@quatrain/core 1.0.0-beta1 → 1.0.0-beta2
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 +28 -0
- package/lib/Core.d.ts +5 -9
- package/lib/Core.js +6 -5
- package/lib/backends/AbstractAdapter.d.ts +5 -41
- package/lib/backends/AbstractAdapter.js +0 -5
- package/lib/backends/BackendInterface.d.ts +13 -0
- package/lib/backends/BackendInterface.js +2 -0
- package/lib/backends/MockAdapter.d.ts +6 -4
- package/lib/backends/MockAdapter.js +15 -6
- package/lib/backends/Query.d.ts +18 -7
- package/lib/backends/Query.js +8 -6
- package/lib/backends/index.d.ts +4 -3
- package/lib/backends/middlewares/InjectKeywordsMiddleware.d.ts +9 -0
- package/lib/backends/middlewares/InjectKeywordsMiddleware.js +47 -0
- package/lib/backends/middlewares/InjectMetaMiddleware copy.d.ts +12 -0
- package/lib/backends/middlewares/InjectMetaMiddleware copy.js +30 -0
- package/lib/backends/types/BackendInterface.d.ts +13 -0
- package/lib/backends/types/BackendInterface.js +2 -0
- package/lib/common/statuses.d.ts +2 -0
- package/lib/common/statuses.js +3 -1
- package/lib/components/BaseObject.d.ts +3 -3
- package/lib/components/BaseObjectCore.js +1 -2
- package/lib/components/BaseRepository.d.ts +9 -8
- package/lib/components/BaseRepository.js +7 -10
- package/lib/components/DataObject.d.ts +1 -0
- package/lib/components/DataObject.js +11 -6
- package/lib/components/Entity.d.ts +2 -16
- package/lib/components/Entity.js +4 -2
- package/lib/components/EntityRepository.d.ts +1 -1
- package/lib/components/User.d.ts +2 -3
- package/lib/components/User.js +4 -2
- package/lib/components/UserRepository.d.ts +2 -2
- package/lib/components/types/DataObjectClass.d.ts +2 -0
- package/lib/components/types/RepositoryClass.d.ts +1 -1
- package/lib/index.d.ts +4 -2
- package/lib/index.js +5 -1
- package/lib/properties/CollectionProperty.d.ts +2 -2
- package/lib/properties/HashProperty.d.ts +6 -0
- package/lib/properties/HashProperty.js +8 -0
- package/lib/properties/types/PropertyClassType.d.ts +1 -0
- package/package.json +1 -1
package/lib/Backend.d.ts
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
|
+
import Middleware from "./backends/middlewares/Middleware";
|
|
1
2
|
export declare enum BackendAction {
|
|
2
3
|
CREATE = "create",
|
|
3
4
|
READ = "read",
|
|
4
5
|
UPDATE = "update",
|
|
5
6
|
DELETE = "delete"
|
|
6
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Default interface for a backend record
|
|
10
|
+
*/
|
|
11
|
+
export interface BackendRecordType {
|
|
12
|
+
uid: string | undefined;
|
|
13
|
+
path: string | undefined;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Backend Parameters acceptable keys
|
|
18
|
+
*/
|
|
19
|
+
export type BackendParametersKeys = 'host' | 'alias' | 'mapping' | 'middlewares' | 'config' | 'fixtures' | 'softDelete' | 'debug';
|
|
20
|
+
/**
|
|
21
|
+
* Backend parameters interface
|
|
22
|
+
*/
|
|
23
|
+
export interface BackendParameters {
|
|
24
|
+
host?: string;
|
|
25
|
+
alias?: string;
|
|
26
|
+
mapping?: {
|
|
27
|
+
[x: string]: any;
|
|
28
|
+
};
|
|
29
|
+
middlewares?: Middleware[];
|
|
30
|
+
config?: any;
|
|
31
|
+
fixtures?: any;
|
|
32
|
+
softDelete?: boolean;
|
|
33
|
+
debug?: boolean;
|
|
34
|
+
}
|
package/lib/Core.d.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { AbstractAdapter } from './backends/AbstractAdapter';
|
|
2
|
-
import {
|
|
2
|
+
import { UserCore } from './components/User';
|
|
3
3
|
import { DataObjectClass } from './components/types/DataObjectClass';
|
|
4
4
|
export type BackendRegistry<T extends AbstractAdapter> = {
|
|
5
5
|
[x: string]: T;
|
|
6
6
|
};
|
|
7
7
|
export declare class Core {
|
|
8
8
|
static defaultBackend: string;
|
|
9
|
-
static
|
|
9
|
+
static userClass: typeof UserCore;
|
|
10
10
|
static classRegistry: {
|
|
11
11
|
[key: string]: any;
|
|
12
12
|
};
|
|
13
|
-
static logger:
|
|
14
|
-
(...data: any[]): void;
|
|
15
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
16
|
-
};
|
|
13
|
+
static logger: Console;
|
|
17
14
|
static timestamp: () => string;
|
|
18
15
|
protected static _backends: BackendRegistry<any>;
|
|
19
16
|
static definition(key: string): {
|
|
@@ -35,9 +32,8 @@ export declare class Core {
|
|
|
35
32
|
/**
|
|
36
33
|
* Log message using defined logger
|
|
37
34
|
* This is currently just a stub that will be implemented from config in the future
|
|
38
|
-
* @param message string
|
|
35
|
+
* @param message string | object
|
|
39
36
|
* @param level string
|
|
40
37
|
*/
|
|
41
|
-
static log(message:
|
|
42
|
-
static getObject(): void;
|
|
38
|
+
static log(message: any, src?: string, level?: string): void;
|
|
43
39
|
}
|
package/lib/Core.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Core = void 0;
|
|
4
4
|
const DataObject_1 = require("./components/DataObject");
|
|
5
|
+
const User_1 = require("./components/User");
|
|
5
6
|
class Core {
|
|
6
7
|
static definition(key) {
|
|
7
8
|
return {
|
|
@@ -42,18 +43,18 @@ class Core {
|
|
|
42
43
|
/**
|
|
43
44
|
* Log message using defined logger
|
|
44
45
|
* This is currently just a stub that will be implemented from config in the future
|
|
45
|
-
* @param message string
|
|
46
|
+
* @param message string | object
|
|
46
47
|
* @param level string
|
|
47
48
|
*/
|
|
48
49
|
static log(message, src = 'Core', level = 'NOTICE') {
|
|
49
|
-
Core.logger(`${Date.now()} - [${src}] ${message}`);
|
|
50
|
+
Core.logger.log(`${Date.now()} - [${src}] ${typeof message === 'string' ? message : JSON.stringify(message)}`);
|
|
50
51
|
}
|
|
51
|
-
static getObject() { }
|
|
52
52
|
}
|
|
53
53
|
exports.Core = Core;
|
|
54
54
|
Core.defaultBackend = '@default';
|
|
55
|
+
Core.userClass = User_1.UserCore;
|
|
55
56
|
Core.classRegistry = {};
|
|
56
|
-
Core.logger = console
|
|
57
|
+
Core.logger = console;
|
|
57
58
|
// How timestamp are formatted
|
|
58
|
-
Core.timestamp = () =>
|
|
59
|
+
Core.timestamp = () => new Date().toISOString();
|
|
59
60
|
Core._backends = {};
|
|
@@ -1,46 +1,11 @@
|
|
|
1
|
-
import { BackendAction } from '../Backend';
|
|
1
|
+
import { BackendAction, BackendParameters, BackendParametersKeys } from '../Backend';
|
|
2
2
|
import { DataObjectClass } from '../components/types/DataObjectClass';
|
|
3
|
+
import { BackendInterface } from './types/BackendInterface';
|
|
3
4
|
import { Filter } from './Filter';
|
|
4
5
|
import { Filters } from './Filters';
|
|
5
|
-
import { Query } from './Query';
|
|
6
|
+
import { Query, QueryResultType } from './Query';
|
|
6
7
|
import { SortAndLimit } from './SortAndLimit';
|
|
7
8
|
import Middleware from './middlewares/Middleware';
|
|
8
|
-
/**
|
|
9
|
-
* Default interface for a backend record
|
|
10
|
-
*/
|
|
11
|
-
export interface BackendRecordType {
|
|
12
|
-
uid: string | undefined;
|
|
13
|
-
path: string | undefined;
|
|
14
|
-
[key: string]: any;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Backend Parameters acceptable keys
|
|
18
|
-
*/
|
|
19
|
-
export type BackendParametersKeys = 'host' | 'alias' | 'mapping' | 'middlewares' | 'config' | 'fixtures' | 'softDelete' | 'debug';
|
|
20
|
-
/**
|
|
21
|
-
* Backend parameters interface
|
|
22
|
-
*/
|
|
23
|
-
export interface BackendParameters {
|
|
24
|
-
host?: string;
|
|
25
|
-
alias?: string;
|
|
26
|
-
mapping?: {
|
|
27
|
-
[x: string]: any;
|
|
28
|
-
};
|
|
29
|
-
middlewares?: Middleware[];
|
|
30
|
-
config?: any;
|
|
31
|
-
fixtures?: any;
|
|
32
|
-
softDelete?: boolean;
|
|
33
|
-
debug?: boolean;
|
|
34
|
-
}
|
|
35
|
-
export interface BackendInterface {
|
|
36
|
-
create(dataObject: DataObjectClass<any>, desiredUid: string | undefined): Promise<DataObjectClass<any>>;
|
|
37
|
-
read(param: string | DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
38
|
-
update(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
39
|
-
delete(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
40
|
-
query(query: Query<any>): Promise<DataObjectClass<any>[]>;
|
|
41
|
-
find(dataObject: DataObjectClass<any>, filters: Filters | Filter[] | undefined, pagination: SortAndLimit | undefined): Promise<DataObjectClass<any>[]>;
|
|
42
|
-
count(query: Query<any>): Promise<number>;
|
|
43
|
-
}
|
|
44
9
|
export declare abstract class AbstractAdapter implements BackendInterface {
|
|
45
10
|
protected _alias: string;
|
|
46
11
|
protected _params: BackendParameters;
|
|
@@ -62,9 +27,8 @@ export declare abstract class AbstractAdapter implements BackendInterface {
|
|
|
62
27
|
* @param query
|
|
63
28
|
* @returns Array
|
|
64
29
|
*/
|
|
65
|
-
query(query: Query<any>): Promise<DataObjectClass<any
|
|
66
|
-
|
|
67
|
-
abstract find(dataObject: DataObjectClass<any>, filters: Filters | Filter[] | undefined, pagination: SortAndLimit | undefined): Promise<DataObjectClass<any>[]>;
|
|
30
|
+
query(query: Query<any>): Promise<QueryResultType<DataObjectClass<any>>>;
|
|
31
|
+
abstract find(dataObject: DataObjectClass<any>, filters: Filters | Filter[] | undefined, pagination: SortAndLimit | undefined): Promise<QueryResultType<any>>;
|
|
68
32
|
log(message: string): void;
|
|
69
33
|
executeMiddlewares(dataObject: DataObjectClass<any>, action: BackendAction): Promise<DataObjectClass<any>>;
|
|
70
34
|
}
|
|
@@ -46,11 +46,6 @@ class AbstractAdapter {
|
|
|
46
46
|
return yield this.find(yield query.obj.daoFactory(), query.filters, query.sortAndLimit);
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
count(query) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
return (yield this.find(yield query.obj.daoFactory(), query.filters, undefined)).length;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
49
|
log(message) {
|
|
55
50
|
if (this._params['debug'] === true) {
|
|
56
51
|
console.log(message);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DataObjectClass } from '../components';
|
|
2
|
+
import { Filter } from './Filter';
|
|
3
|
+
import { Filters } from './Filters';
|
|
4
|
+
import { Query, QueryResultType } from './Query';
|
|
5
|
+
import { SortAndLimit } from './SortAndLimit';
|
|
6
|
+
export interface BackendInterface {
|
|
7
|
+
create(dataObject: DataObjectClass<any>, desiredUid: string | undefined): Promise<DataObjectClass<any>>;
|
|
8
|
+
read(param: string | DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
9
|
+
update(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
10
|
+
delete(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
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>>>;
|
|
13
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { DataObjectClass } from '../components/types/DataObjectClass';
|
|
2
|
+
import { QueryResultType } from './Query';
|
|
3
3
|
import { Filter } from './Filter';
|
|
4
4
|
import { Filters } from './Filters';
|
|
5
5
|
import { SortAndLimit } from './SortAndLimit';
|
|
6
|
-
import {
|
|
6
|
+
import { AbstractAdapter } from './AbstractAdapter';
|
|
7
|
+
import { BackendInterface } from './types/BackendInterface';
|
|
8
|
+
import { BackendRecordType } from '../Backend';
|
|
7
9
|
export declare class MockAdapter extends AbstractAdapter implements BackendInterface {
|
|
8
10
|
protected static _fixtures: any;
|
|
9
11
|
/**
|
|
@@ -19,5 +21,5 @@ export declare class MockAdapter extends AbstractAdapter implements BackendInter
|
|
|
19
21
|
update(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
20
22
|
delete(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
21
23
|
deleteCollection(collection: string, batchSize?: number | undefined): Promise<void>;
|
|
22
|
-
find(dataObject: DataObjectClass<any>, filters?: Filters | Filter[] | undefined, pagination?: SortAndLimit | undefined): Promise<DataObjectClass<any
|
|
24
|
+
find(dataObject: DataObjectClass<any>, filters?: Filters | Filter[] | undefined, pagination?: SortAndLimit | undefined): Promise<QueryResultType<DataObjectClass<any>>>;
|
|
23
25
|
}
|
|
@@ -10,11 +10,12 @@ 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
|
|
13
|
+
const Core_1 = require("../Core");
|
|
14
14
|
const ObjectUri_1 = require("../components/ObjectUri");
|
|
15
15
|
const faker_1 = require("@faker-js/faker");
|
|
16
16
|
const BackendError_1 = require("./BackendError");
|
|
17
17
|
const ResourcesErrors_1 = require("../common/ResourcesErrors");
|
|
18
|
+
const AbstractAdapter_1 = require("./AbstractAdapter");
|
|
18
19
|
class MockAdapter extends AbstractAdapter_1.AbstractAdapter {
|
|
19
20
|
/**
|
|
20
21
|
* Inject fixtures data to backend adapter
|
|
@@ -116,12 +117,12 @@ class MockAdapter extends AbstractAdapter_1.AbstractAdapter {
|
|
|
116
117
|
find(dataObject, filters = undefined, pagination = undefined) {
|
|
117
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
119
|
const limit = (pagination === null || pagination === void 0 ? void 0 : pagination.limits.batch) || 1e10;
|
|
119
|
-
let
|
|
120
|
+
let items = [];
|
|
120
121
|
const collection = this.getCollection(dataObject);
|
|
121
122
|
// TODO filter only records matchinf collection
|
|
122
123
|
for (let key in MockAdapter.getFixtures()) {
|
|
123
124
|
let keep = true;
|
|
124
|
-
if (key.startsWith(`${collection}/`) &&
|
|
125
|
+
if (key.startsWith(`${collection}/`) && items.length <= limit) {
|
|
125
126
|
const dao = yield dataObject.clone(MockAdapter.getFixture(key));
|
|
126
127
|
if (filters) {
|
|
127
128
|
if (Array.isArray(filters)) {
|
|
@@ -164,15 +165,23 @@ class MockAdapter extends AbstractAdapter_1.AbstractAdapter {
|
|
|
164
165
|
}
|
|
165
166
|
if (keep) {
|
|
166
167
|
dao.uri = new ObjectUri_1.ObjectUri(key);
|
|
167
|
-
|
|
168
|
+
items.push(dao);
|
|
168
169
|
}
|
|
169
170
|
}
|
|
170
171
|
}
|
|
171
172
|
if (pagination && pagination.sortings.length > 0) {
|
|
172
|
-
|
|
173
|
+
items = items.sort((a, b) => Number(a.val(pagination.sortings[0].prop) >
|
|
173
174
|
b.val(pagination.sortings[0].prop)));
|
|
174
175
|
}
|
|
175
|
-
return
|
|
176
|
+
return {
|
|
177
|
+
items,
|
|
178
|
+
meta: {
|
|
179
|
+
count: 100,
|
|
180
|
+
offset: (pagination === null || pagination === void 0 ? void 0 : pagination.limits.offset) || 0,
|
|
181
|
+
batch: (pagination === null || pagination === void 0 ? void 0 : pagination.limits.batch) || 10,
|
|
182
|
+
executionTime: Core_1.Core.timestamp(),
|
|
183
|
+
},
|
|
184
|
+
};
|
|
176
185
|
});
|
|
177
186
|
}
|
|
178
187
|
}
|
package/lib/backends/Query.d.ts
CHANGED
|
@@ -2,14 +2,24 @@ import { Filter } from './Filter';
|
|
|
2
2
|
import { Limits } from './Limits';
|
|
3
3
|
import { Sorting } from './Sorting';
|
|
4
4
|
import { SortAndLimit } from './SortAndLimit';
|
|
5
|
-
import { BackendInterface } from './
|
|
5
|
+
import { BackendInterface } from './types/BackendInterface';
|
|
6
6
|
import { DataObjectClass, ObjectUri } from '../components';
|
|
7
|
-
import { Persisted } from '../components/types/Persisted';
|
|
8
|
-
import { BaseObject } from '../components/BaseObject';
|
|
9
7
|
import { BaseObjectCore } from '../components/BaseObjectCore';
|
|
10
8
|
export declare const AS_OBJECTURIS = "objectUris";
|
|
11
9
|
export declare const AS_DATAOBJECTS = "dataObjects";
|
|
12
10
|
export declare const AS_INSTANCES = "classInstances";
|
|
11
|
+
export type QueryMetaType = {
|
|
12
|
+
count: number;
|
|
13
|
+
offset: number;
|
|
14
|
+
batch: number;
|
|
15
|
+
executionTime: string | number;
|
|
16
|
+
sortField?: string;
|
|
17
|
+
sortOrder?: 'asc' | 'desc';
|
|
18
|
+
};
|
|
19
|
+
export type QueryResultType<T> = {
|
|
20
|
+
items: Array<T>;
|
|
21
|
+
meta: QueryMetaType;
|
|
22
|
+
};
|
|
13
23
|
export declare enum returnAs {
|
|
14
24
|
AS_OBJECTURIS = "objectUris",
|
|
15
25
|
AS_DATAOBJECTS = "dataObjects",
|
|
@@ -22,6 +32,7 @@ export declare class Query<T extends typeof BaseObjectCore> {
|
|
|
22
32
|
filters: Filter[];
|
|
23
33
|
sortings: Sorting[];
|
|
24
34
|
limits: Limits;
|
|
35
|
+
meta: any;
|
|
25
36
|
constructor(obj: T, params?: {
|
|
26
37
|
[x: string]: any;
|
|
27
38
|
});
|
|
@@ -32,8 +43,8 @@ export declare class Query<T extends typeof BaseObjectCore> {
|
|
|
32
43
|
offset(offset?: number): this;
|
|
33
44
|
batch(batch?: number): this;
|
|
34
45
|
get sortAndLimit(): SortAndLimit;
|
|
35
|
-
fetch(backend?: BackendInterface): Promise<DataObjectClass<any
|
|
36
|
-
fetchAsUri(backend?: BackendInterface): Promise<ObjectUri
|
|
37
|
-
fetchAsInstances(backend?: BackendInterface): Promise<
|
|
38
|
-
execute(as?: returnAs, backend?: BackendInterface): Promise<any
|
|
46
|
+
fetch(backend?: BackendInterface): Promise<QueryResultType<DataObjectClass<any>>>;
|
|
47
|
+
fetchAsUri(backend?: BackendInterface): Promise<QueryResultType<ObjectUri>>;
|
|
48
|
+
fetchAsInstances(backend?: BackendInterface): Promise<QueryResultType<T>>;
|
|
49
|
+
execute(as?: returnAs, backend?: BackendInterface): Promise<QueryResultType<any>>;
|
|
39
50
|
}
|
package/lib/backends/Query.js
CHANGED
|
@@ -32,18 +32,20 @@ class Query {
|
|
|
32
32
|
this.filters = [];
|
|
33
33
|
this.sortings = [];
|
|
34
34
|
this.limits = new Limits_1.Limits();
|
|
35
|
+
this.meta = {};
|
|
35
36
|
}
|
|
36
37
|
get obj() {
|
|
37
38
|
return this._obj;
|
|
38
39
|
}
|
|
39
40
|
where(param, value = null, operator = 'equals') {
|
|
41
|
+
console.log(`received value`, value);
|
|
40
42
|
if (typeof param == 'object') {
|
|
41
43
|
this.filters.push(param);
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
44
46
|
if (operator === 'equals' && Array.isArray(value)) {
|
|
45
47
|
// auto-convert operator if value is an array
|
|
46
|
-
operator = '
|
|
48
|
+
operator = 'contains'; // Any'
|
|
47
49
|
}
|
|
48
50
|
this.filters.push(new Filter_1.Filter(param, value, operator));
|
|
49
51
|
}
|
|
@@ -80,18 +82,18 @@ class Query {
|
|
|
80
82
|
}
|
|
81
83
|
fetchAsUri(backend = Core_1.Core.getBackend()) {
|
|
82
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
const
|
|
84
|
-
return yield Promise.all(
|
|
85
|
+
const { items, meta } = yield this.fetch(backend);
|
|
86
|
+
return { items: yield Promise.all(items.map((dao) => dao.uri)), meta };
|
|
85
87
|
});
|
|
86
88
|
}
|
|
87
89
|
fetchAsInstances(backend = Core_1.Core.getBackend()) {
|
|
88
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
-
const
|
|
91
|
+
const { items, meta } = yield this.fetch(backend);
|
|
90
92
|
const instances = [];
|
|
91
|
-
for (const item of
|
|
93
|
+
for (const item of items) {
|
|
92
94
|
instances.push(this._obj.fromDataObject(item));
|
|
93
95
|
}
|
|
94
|
-
return instances;
|
|
96
|
+
return { items: instances, meta };
|
|
95
97
|
});
|
|
96
98
|
}
|
|
97
99
|
execute(as = returnAs.AS_DATAOBJECTS, backend = Core_1.Core.getBackend()) {
|
package/lib/backends/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { AbstractAdapter
|
|
1
|
+
import { AbstractAdapter } from './AbstractAdapter';
|
|
2
2
|
import { MockAdapter } from './MockAdapter';
|
|
3
3
|
import { BackendError } from './BackendError';
|
|
4
|
-
import {
|
|
4
|
+
import { BackendInterface } from './types/BackendInterface';
|
|
5
|
+
import { Query, QueryResultType, QueryMetaType } from './Query';
|
|
5
6
|
import { Filter } from './Filter';
|
|
6
7
|
import { Filters } from './Filters';
|
|
7
8
|
import { Sorting } from './Sorting';
|
|
8
9
|
import { Limits } from './Limits';
|
|
9
10
|
import { SortAndLimit } from './SortAndLimit';
|
|
10
|
-
export {
|
|
11
|
+
export { BackendInterface, AbstractAdapter, BackendError, MockAdapter, Query, QueryResultType, QueryMetaType, Filter, Filters, Sorting, Limits, SortAndLimit, };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DataObjectClass } from '../../components';
|
|
2
|
+
import { BackendAction } from '../../Backend';
|
|
3
|
+
import Middleware from './Middleware';
|
|
4
|
+
export interface InjectKeywordsMiddlewareParams {
|
|
5
|
+
}
|
|
6
|
+
export declare class InjectKeywordsMiddleware implements Middleware {
|
|
7
|
+
execute(dataObject: DataObjectClass<any>, action: BackendAction): void;
|
|
8
|
+
protected _createKeywords(dataObject: DataObjectClass<any>): string[];
|
|
9
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectKeywordsMiddleware = void 0;
|
|
4
|
+
const Backend_1 = require("../../Backend");
|
|
5
|
+
const properties_1 = require("../../properties");
|
|
6
|
+
class InjectKeywordsMiddleware {
|
|
7
|
+
execute(dataObject, action) {
|
|
8
|
+
if (!dataObject.has('keywords')) {
|
|
9
|
+
dataObject.addProperty(new properties_1.ArrayProperty({ name: 'keywords' }));
|
|
10
|
+
}
|
|
11
|
+
switch (action) {
|
|
12
|
+
case Backend_1.BackendAction.CREATE:
|
|
13
|
+
case Backend_1.BackendAction.UPDATE:
|
|
14
|
+
dataObject.set('keywords', this._createKeywords(dataObject));
|
|
15
|
+
break;
|
|
16
|
+
default:
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
_createKeywords(dataObject) {
|
|
22
|
+
const keywords = [];
|
|
23
|
+
Object.keys(dataObject.properties)
|
|
24
|
+
.filter((key) => dataObject.get(key).fullSearch === true)
|
|
25
|
+
.forEach((key) => {
|
|
26
|
+
const val = dataObject.val(key);
|
|
27
|
+
if (val) {
|
|
28
|
+
val.toLowerCase()
|
|
29
|
+
.split(' ')
|
|
30
|
+
.forEach((word) => {
|
|
31
|
+
let seq = '';
|
|
32
|
+
word
|
|
33
|
+
.split('')
|
|
34
|
+
.splice(0, 15)
|
|
35
|
+
.forEach((letter) => {
|
|
36
|
+
seq += letter;
|
|
37
|
+
if (seq.length > 1) {
|
|
38
|
+
keywords.push(seq);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return [...new Set(keywords)];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.InjectKeywordsMiddleware = InjectKeywordsMiddleware;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DataObjectClass } from '../../components';
|
|
2
|
+
import { BackendAction } from '../../Backend';
|
|
3
|
+
import { UserCore } from '../../components/User';
|
|
4
|
+
import Middleware from './Middleware';
|
|
5
|
+
export interface InjectMetaMiddlewareParams {
|
|
6
|
+
user: UserCore;
|
|
7
|
+
}
|
|
8
|
+
export declare class InjectMetaMiddleware implements Middleware {
|
|
9
|
+
protected _user: UserCore;
|
|
10
|
+
constructor(params: InjectMetaMiddlewareParams);
|
|
11
|
+
execute(dataObject: DataObjectClass<any>, action: BackendAction): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectMetaMiddleware = void 0;
|
|
4
|
+
const Backend_1 = require("../../Backend");
|
|
5
|
+
class InjectMetaMiddleware {
|
|
6
|
+
constructor(params) {
|
|
7
|
+
this._user = params.user;
|
|
8
|
+
}
|
|
9
|
+
execute(dataObject, action) {
|
|
10
|
+
switch (action) {
|
|
11
|
+
// add properties existence validation
|
|
12
|
+
case Backend_1.BackendAction.CREATE:
|
|
13
|
+
dataObject.set('createdBy', this._user);
|
|
14
|
+
dataObject.set('createdAt', Date.now());
|
|
15
|
+
break;
|
|
16
|
+
case Backend_1.BackendAction.UPDATE:
|
|
17
|
+
dataObject.set('updatedBy', this._user);
|
|
18
|
+
dataObject.set('updatedAt', Date.now());
|
|
19
|
+
break;
|
|
20
|
+
case Backend_1.BackendAction.DELETE:
|
|
21
|
+
dataObject.set('deletedBy', this._user);
|
|
22
|
+
dataObject.set('deletedAt', Date.now());
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.InjectMetaMiddleware = InjectMetaMiddleware;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DataObjectClass } from '../../components';
|
|
2
|
+
import { Filter } from '../Filter';
|
|
3
|
+
import { Filters } from '../Filters';
|
|
4
|
+
import { Query, QueryResultType } from '../Query';
|
|
5
|
+
import { SortAndLimit } from '../SortAndLimit';
|
|
6
|
+
export interface BackendInterface {
|
|
7
|
+
create(dataObject: DataObjectClass<any>, desiredUid: string | undefined): Promise<DataObjectClass<any>>;
|
|
8
|
+
read(param: string | DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
9
|
+
update(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
10
|
+
delete(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
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>>>;
|
|
13
|
+
}
|
package/lib/common/statuses.d.ts
CHANGED
|
@@ -2,11 +2,13 @@ export declare const CREATED = "created";
|
|
|
2
2
|
export declare const PENDING = "pending";
|
|
3
3
|
export declare const QUEUED = "queued";
|
|
4
4
|
export declare const ACTIVE = "active";
|
|
5
|
+
export declare const COMPLETED = "completed";
|
|
5
6
|
export declare const ERROR = "error";
|
|
6
7
|
export declare const TEST = "test";
|
|
7
8
|
export declare const SUSPENDED = "suspended";
|
|
8
9
|
export declare const DELETABLE = "deletable";
|
|
9
10
|
export declare const DELETED = "deleted";
|
|
11
|
+
export declare const DISABLED = "disabled";
|
|
10
12
|
export declare const DONE = "done";
|
|
11
13
|
export declare const MAINTENANCE = "maintenance";
|
|
12
14
|
export declare const UNKNOWN = "unknown";
|
package/lib/common/statuses.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UNKNOWN = exports.MAINTENANCE = exports.DONE = exports.DELETED = exports.DELETABLE = exports.SUSPENDED = exports.TEST = exports.ERROR = exports.ACTIVE = exports.QUEUED = exports.PENDING = exports.CREATED = void 0;
|
|
3
|
+
exports.UNKNOWN = exports.MAINTENANCE = exports.DONE = exports.DISABLED = exports.DELETED = exports.DELETABLE = exports.SUSPENDED = exports.TEST = exports.ERROR = exports.COMPLETED = exports.ACTIVE = exports.QUEUED = exports.PENDING = exports.CREATED = void 0;
|
|
4
4
|
exports.CREATED = 'created';
|
|
5
5
|
exports.PENDING = 'pending';
|
|
6
6
|
exports.QUEUED = 'queued';
|
|
7
7
|
exports.ACTIVE = 'active';
|
|
8
|
+
exports.COMPLETED = 'completed';
|
|
8
9
|
exports.ERROR = 'error';
|
|
9
10
|
exports.TEST = 'test';
|
|
10
11
|
exports.SUSPENDED = 'suspended';
|
|
11
12
|
exports.DELETABLE = 'deletable';
|
|
12
13
|
exports.DELETED = 'deleted';
|
|
14
|
+
exports.DISABLED = 'disabled';
|
|
13
15
|
exports.DONE = 'done';
|
|
14
16
|
exports.MAINTENANCE = 'maintenance';
|
|
15
17
|
exports.UNKNOWN = 'unknown';
|
|
@@ -4,10 +4,10 @@ export interface BaseObject {
|
|
|
4
4
|
name: string;
|
|
5
5
|
status: string;
|
|
6
6
|
createdBy?: User | ObjectUri;
|
|
7
|
-
createdAt?: number;
|
|
7
|
+
createdAt?: number | string;
|
|
8
8
|
updatedBy?: User | ObjectUri;
|
|
9
|
-
updatedAt?: number;
|
|
9
|
+
updatedAt?: number | string;
|
|
10
10
|
deletedBy?: User | ObjectUri;
|
|
11
|
-
deletedAt?: number;
|
|
11
|
+
deletedAt?: number | string;
|
|
12
12
|
}
|
|
13
13
|
export declare const BaseObjectProperties: any;
|
|
@@ -63,7 +63,7 @@ class BaseObjectCore extends AbstractObject_1.AbstractObject {
|
|
|
63
63
|
dao.uri.class = child;
|
|
64
64
|
dao.populateFromData(src);
|
|
65
65
|
const obj = new this(dao);
|
|
66
|
-
return obj;
|
|
66
|
+
return obj;
|
|
67
67
|
}
|
|
68
68
|
static factory(src = undefined, child = this) {
|
|
69
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -144,7 +144,6 @@ class BaseObjectCore extends AbstractObject_1.AbstractObject {
|
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
asReference() {
|
|
147
|
-
console.log(this._dataObject.toReference());
|
|
148
147
|
return this._dataObject.toReference();
|
|
149
148
|
}
|
|
150
149
|
query() {
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Query } from '../backends/Query';
|
|
1
|
+
import { Query, QueryResultType } from '../backends/Query';
|
|
3
2
|
import { BaseObjectCore } from './BaseObjectCore';
|
|
4
3
|
import { DataObjectClass } from './types/DataObjectClass';
|
|
5
|
-
import Payload from './types/Payload';
|
|
6
4
|
import { BaseObject } from './BaseObject';
|
|
7
|
-
import {
|
|
8
|
-
import { Proxy } from './types/ProxyConstructor';
|
|
5
|
+
import { BackendInterface } from '../backends/types/BackendInterface';
|
|
9
6
|
/**
|
|
10
7
|
* CRUD methods for models/entities inheriting from BaseObject
|
|
11
8
|
* Extend this by passing the typeof of the desired class to the constructor
|
|
@@ -17,7 +14,11 @@ export default class BaseRepository<T extends BaseObject> {
|
|
|
17
14
|
protected getDataObjectFromUid(uid: string): Promise<DataObjectClass<any>>;
|
|
18
15
|
create<B extends BaseObjectCore>(obj: B, uid?: string): Promise<any>;
|
|
19
16
|
read(key: string): Promise<any>;
|
|
20
|
-
update(obj:
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
update(obj: BaseObjectCore): Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* delete object in its backend
|
|
20
|
+
* @param uid string
|
|
21
|
+
*/
|
|
22
|
+
delete(uid: string): Promise<DataObjectClass<any>>;
|
|
23
|
+
query(query: Query<any>): Promise<QueryResultType<T>>;
|
|
23
24
|
}
|
|
@@ -90,27 +90,24 @@ class BaseRepository {
|
|
|
90
90
|
}
|
|
91
91
|
update(obj) {
|
|
92
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const dataObject = obj.
|
|
93
|
+
const dataObject = obj.dataObject;
|
|
94
94
|
const savedObj = yield this.backendAdapter.update(dataObject);
|
|
95
95
|
return this._model.fromDataObject(savedObj);
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* delete object in its backend
|
|
100
|
+
* @param uid string
|
|
101
|
+
*/
|
|
98
102
|
delete(uid) {
|
|
99
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
104
|
const dataObject = yield this.getDataObjectFromUid(uid);
|
|
101
|
-
yield this.backendAdapter.delete(dataObject);
|
|
105
|
+
return yield this.backendAdapter.delete(dataObject);
|
|
102
106
|
});
|
|
103
107
|
}
|
|
104
108
|
query(query) {
|
|
105
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
|
|
107
|
-
const count = yield this.backendAdapter.count(query);
|
|
108
|
-
const meta = {
|
|
109
|
-
count,
|
|
110
|
-
updatedAt: new Date().getTime(),
|
|
111
|
-
};
|
|
112
|
-
const payload = { items, meta };
|
|
113
|
-
return payload;
|
|
110
|
+
return yield query.fetchAsInstances(this.backendAdapter);
|
|
114
111
|
});
|
|
115
112
|
}
|
|
116
113
|
}
|
|
@@ -43,6 +43,7 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
43
43
|
*/
|
|
44
44
|
asProxy(): this;
|
|
45
45
|
setProperties(properties: Properties): void;
|
|
46
|
+
addProperty(property: PropertyClassType): void;
|
|
46
47
|
/**
|
|
47
48
|
* Populate data object from instant data or backend query
|
|
48
49
|
* @param data
|
|
@@ -13,6 +13,7 @@ exports.DataObject = void 0;
|
|
|
13
13
|
const Core_1 = require("../Core");
|
|
14
14
|
const Property_1 = require("../properties/Property");
|
|
15
15
|
const ObjectUri_1 = require("./ObjectUri");
|
|
16
|
+
const ResourcesErrors_1 = require("../common/ResourcesErrors");
|
|
16
17
|
/**
|
|
17
18
|
* Data objects constitute the agnostic glue between objects and backends.
|
|
18
19
|
* They handle data and identifiers in a protected registry
|
|
@@ -74,6 +75,12 @@ class DataObject {
|
|
|
74
75
|
// TODO check if doable
|
|
75
76
|
this._properties = properties;
|
|
76
77
|
}
|
|
78
|
+
addProperty(property) {
|
|
79
|
+
if (Object.keys(this._properties).includes(property.name)) {
|
|
80
|
+
throw new Error(`Property ${name} already exists`);
|
|
81
|
+
}
|
|
82
|
+
this._properties[property.name] = property;
|
|
83
|
+
}
|
|
77
84
|
/**
|
|
78
85
|
* Populate data object from instant data or backend query
|
|
79
86
|
* @param data
|
|
@@ -192,12 +199,10 @@ class DataObject {
|
|
|
192
199
|
* @returns BaseProperty
|
|
193
200
|
*/
|
|
194
201
|
get(key) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
catch (err) {
|
|
199
|
-
throw new Error(err.message);
|
|
202
|
+
if (!Reflect.has(this._properties, key)) {
|
|
203
|
+
throw new ResourcesErrors_1.NotFoundError(`No property matching key ${key}`);
|
|
200
204
|
}
|
|
205
|
+
return Reflect.get(this._properties, key);
|
|
201
206
|
}
|
|
202
207
|
set(key, val) {
|
|
203
208
|
if (!this.has(key)) {
|
|
@@ -222,7 +227,7 @@ class DataObject {
|
|
|
222
227
|
}
|
|
223
228
|
}
|
|
224
229
|
toJSON(objectsAsReferences = false) {
|
|
225
|
-
return Object.assign(Object.assign({}, (this.
|
|
230
|
+
return Object.assign(Object.assign({}, (this.uri && { uid: this.uri.uid, path: this.uri.path })), this._dataToJSON(objectsAsReferences));
|
|
226
231
|
}
|
|
227
232
|
toReference() {
|
|
228
233
|
return Object.assign(Object.assign({}, this._objectUri.toReference()), { label: this.val('name') || '' });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseObjectCore } from './BaseObjectCore';
|
|
2
2
|
import { BaseObject } from './BaseObject';
|
|
3
|
-
import { User
|
|
3
|
+
import { User } from './User';
|
|
4
4
|
import { EntityClass } from './types/EntityClass';
|
|
5
5
|
export declare const EntityProperties: any;
|
|
6
6
|
export interface Entity extends BaseObject {
|
|
@@ -8,19 +8,5 @@ export interface Entity extends BaseObject {
|
|
|
8
8
|
}
|
|
9
9
|
export declare class EntityCore extends BaseObjectCore implements EntityClass {
|
|
10
10
|
static COLLECTION: string;
|
|
11
|
-
static PROPS_DEFINITION:
|
|
12
|
-
name: string;
|
|
13
|
-
type: string;
|
|
14
|
-
mandatory: boolean;
|
|
15
|
-
minLength: number;
|
|
16
|
-
instanceOf?: undefined;
|
|
17
|
-
parentKey?: undefined;
|
|
18
|
-
} | {
|
|
19
|
-
name: string;
|
|
20
|
-
mandatory: boolean;
|
|
21
|
-
type: string;
|
|
22
|
-
instanceOf: typeof UserCore;
|
|
23
|
-
parentKey: string;
|
|
24
|
-
minLength?: undefined;
|
|
25
|
-
})[];
|
|
11
|
+
static PROPS_DEFINITION: any[];
|
|
26
12
|
}
|
package/lib/components/Entity.js
CHANGED
|
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.EntityCore = exports.EntityProperties = void 0;
|
|
27
27
|
const BaseObjectCore_1 = require("./BaseObjectCore");
|
|
28
|
+
const BaseObject_1 = require("./BaseObject");
|
|
28
29
|
const User_1 = require("./User");
|
|
29
30
|
const CollectionProperty_1 = require("../properties/CollectionProperty");
|
|
30
31
|
const StringProperty_1 = require("../properties/StringProperty");
|
|
@@ -49,15 +50,16 @@ exports.EntityProperties = [
|
|
|
49
50
|
class EntityCore extends BaseObjectCore_1.BaseObjectCore {
|
|
50
51
|
}
|
|
51
52
|
exports.EntityCore = EntityCore;
|
|
52
|
-
EntityCore.COLLECTION = '
|
|
53
|
+
EntityCore.COLLECTION = 'entities';
|
|
53
54
|
EntityCore.PROPS_DEFINITION = [
|
|
55
|
+
...BaseObject_1.BaseObjectProperties,
|
|
54
56
|
{
|
|
55
57
|
// surcharge property minLength and htmlType
|
|
56
58
|
name: 'name',
|
|
57
59
|
type: StringProperty_1.StringProperty.TYPE,
|
|
58
60
|
mandatory: true,
|
|
59
61
|
minLength: 1,
|
|
60
|
-
|
|
62
|
+
htmlType: htmlType.ORG,
|
|
61
63
|
},
|
|
62
64
|
{
|
|
63
65
|
name: 'users',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BackendInterface } from '../backends';
|
|
1
|
+
import { BackendInterface } from '../backends/types/BackendInterface';
|
|
2
2
|
import BaseRepository from './BaseRepository';
|
|
3
3
|
import { Entity } from './Entity';
|
|
4
4
|
export default class EntityRepository extends BaseRepository<Entity> {
|
package/lib/components/User.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { BaseObjectCore } from './BaseObjectCore';
|
|
2
2
|
import { BaseObject } from './BaseObject';
|
|
3
|
-
import { Persisted } from './types/Persisted';
|
|
4
|
-
import { Proxy } from './types/ProxyConstructor';
|
|
5
3
|
export interface User extends BaseObject {
|
|
4
|
+
name: string;
|
|
6
5
|
firstname: string;
|
|
7
6
|
lastname: string;
|
|
8
7
|
gender?: 'male' | 'female' | 'nonbinary';
|
|
@@ -14,5 +13,5 @@ export declare const UserProperties: any;
|
|
|
14
13
|
export declare class UserCore extends BaseObjectCore {
|
|
15
14
|
static PROPS_DEFINITION: any;
|
|
16
15
|
static COLLECTION: string;
|
|
17
|
-
static factory(src?: any): Promise<
|
|
16
|
+
static factory(src?: any): Promise<UserCore>;
|
|
18
17
|
}
|
package/lib/components/User.js
CHANGED
|
@@ -39,6 +39,7 @@ const HashProperty_1 = require("../properties/HashProperty");
|
|
|
39
39
|
const StringProperty_1 = require("../properties/StringProperty");
|
|
40
40
|
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
41
41
|
const BaseObject_1 = require("./BaseObject");
|
|
42
|
+
const Entity_1 = require("./Entity");
|
|
42
43
|
/**
|
|
43
44
|
* Callback function to populate the 'name' property
|
|
44
45
|
* @param dao DataObject
|
|
@@ -52,7 +53,6 @@ exports.UserProperties = [
|
|
|
52
53
|
name: 'name',
|
|
53
54
|
type: StringProperty_1.StringProperty.TYPE,
|
|
54
55
|
minLength: 0,
|
|
55
|
-
fullSearch: true,
|
|
56
56
|
htmlType: htmlType.NAME,
|
|
57
57
|
},
|
|
58
58
|
{
|
|
@@ -61,6 +61,7 @@ exports.UserProperties = [
|
|
|
61
61
|
type: StringProperty_1.StringProperty.TYPE,
|
|
62
62
|
minLength: 1,
|
|
63
63
|
maxLength: 100,
|
|
64
|
+
fullSearch: true,
|
|
64
65
|
htmlType: htmlType.GIVEN_NAME,
|
|
65
66
|
onChange,
|
|
66
67
|
},
|
|
@@ -70,6 +71,7 @@ exports.UserProperties = [
|
|
|
70
71
|
type: StringProperty_1.StringProperty.TYPE,
|
|
71
72
|
minLength: 1,
|
|
72
73
|
maxLength: 100,
|
|
74
|
+
fullSearch: true,
|
|
73
75
|
htmlType: htmlType.FAMILY_NAME,
|
|
74
76
|
onChange,
|
|
75
77
|
},
|
|
@@ -109,7 +111,7 @@ exports.UserProperties = [
|
|
|
109
111
|
name: 'entity',
|
|
110
112
|
mandatory: false,
|
|
111
113
|
type: properties_1.ObjectProperty.TYPE,
|
|
112
|
-
instanceOf:
|
|
114
|
+
instanceOf: Entity_1.EntityCore,
|
|
113
115
|
},
|
|
114
116
|
];
|
|
115
117
|
class UserCore extends BaseObjectCore_1.BaseObjectCore {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BackendInterface } from '../backends';
|
|
1
|
+
import { BackendInterface } from '../backends/types/BackendInterface';
|
|
2
2
|
import BaseRepository from './BaseRepository';
|
|
3
3
|
import { User } from './User';
|
|
4
4
|
export default class UserRepository extends BaseRepository<User> {
|
|
5
5
|
constructor(backendAdapter?: BackendInterface);
|
|
6
|
-
getFromEmail(email: string): Promise<
|
|
6
|
+
getFromEmail(email: string): Promise<User>;
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PropertyClassType } from '../../properties/types/PropertyClassType';
|
|
1
2
|
import { ObjectUri } from '../ObjectUri';
|
|
2
3
|
export interface DataObjectClass<T extends DataObjectClass<any>> {
|
|
3
4
|
uri: ObjectUri;
|
|
@@ -7,6 +8,7 @@ export interface DataObjectClass<T extends DataObjectClass<any>> {
|
|
|
7
8
|
class: any;
|
|
8
9
|
properties: any;
|
|
9
10
|
setProperties(properties: any): void;
|
|
11
|
+
addProperty(property: PropertyClassType): void;
|
|
10
12
|
populate(data?: any): Promise<T>;
|
|
11
13
|
isPopulated(): boolean;
|
|
12
14
|
isPersisted(): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BackendInterface } from '../../backends/
|
|
1
|
+
import { BackendInterface } from '../../backends/types/BackendInterface';
|
|
2
2
|
import { Query } from '../../backends/Query';
|
|
3
3
|
import { BaseObjectCore } from '../BaseObjectCore';
|
|
4
4
|
import { BaseObject } from '../BaseObject';
|
package/lib/index.d.ts
CHANGED
|
@@ -17,13 +17,15 @@ import { BaseObjectCore } from './components/BaseObjectCore';
|
|
|
17
17
|
import { BaseObject, BaseObjectProperties } from './components/BaseObject';
|
|
18
18
|
import { Proxy } from './components/types/ProxyConstructor';
|
|
19
19
|
import { InjectMetaMiddleware } from './backends/middlewares/InjectMetaMiddleware';
|
|
20
|
+
import { InjectKeywordsMiddleware } from './backends/middlewares/InjectKeywordsMiddleware';
|
|
20
21
|
import RepositoryClass from './components/types/RepositoryClass';
|
|
21
22
|
import BaseRepository from './components/BaseRepository';
|
|
23
|
+
import { BackendAction, BackendParameters, BackendParametersKeys, BackendRecordType } from './Backend';
|
|
22
24
|
import Middleware from './backends/middlewares/Middleware';
|
|
23
25
|
import { User } from './components/User';
|
|
24
26
|
import UserRepository from './components/UserRepository';
|
|
25
27
|
import { Entity } from './components/Entity';
|
|
26
28
|
import EntityRepository from './components/EntityRepository';
|
|
27
|
-
import { AbstractAdapter, MockAdapter, BackendError,
|
|
29
|
+
import { AbstractAdapter, MockAdapter, BackendError, Query, QueryMetaType, QueryResultType, Filter, Filters, Limits, Sorting, SortAndLimit } from './backends';
|
|
28
30
|
import { BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, GoneError } from './common/ResourcesErrors';
|
|
29
|
-
export { statuses, utils, Core, Property, BaseProperty, BasePropertyType, BooleanProperty, BooleanPropertyType, DateTimeProperty, DateTimePropertyType, EnumProperty, EnumPropertyType, HashProperty, HashPropertyType, ObjectProperty, ObjectPropertyType, StringProperty, StringPropertyType, AbstractAdapter, RepositoryClass, MockAdapter, ObjectUri, DataObjectClass, DataObject, AbstractObject, BaseObject, BaseObjectCore, BaseObjectProperties, BackendParameters, BaseRepository, BackendError, Query, Filter, Filters, Limits, Sorting, SortAndLimit, Middleware, InjectMetaMiddleware, User, Proxy, UserRepository, Entity, EntityRepository, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, GoneError, };
|
|
31
|
+
export { statuses, utils, Core, Property, BaseProperty, BasePropertyType, BooleanProperty, BooleanPropertyType, DateTimeProperty, DateTimePropertyType, EnumProperty, EnumPropertyType, HashProperty, HashPropertyType, ObjectProperty, ObjectPropertyType, StringProperty, StringPropertyType, AbstractAdapter, RepositoryClass, MockAdapter, ObjectUri, DataObjectClass, DataObject, AbstractObject, BaseObject, BaseObjectCore, BaseObjectProperties, BackendParameters, BackendParametersKeys, BackendRecordType, BackendAction, BaseRepository, BackendError, Query, QueryMetaType, QueryResultType, Filter, Filters, Limits, Sorting, SortAndLimit, Middleware, InjectMetaMiddleware, InjectKeywordsMiddleware, User, Proxy, UserRepository, Entity, EntityRepository, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, GoneError, };
|
package/lib/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.GoneError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.EntityRepository = exports.UserRepository = exports.InjectMetaMiddleware = exports.SortAndLimit = exports.Sorting = exports.Limits = exports.Filters = exports.Filter = exports.Query = exports.BackendError = exports.BaseRepository = exports.BaseObjectProperties = exports.BaseObjectCore = exports.AbstractObject = exports.DataObject = exports.ObjectUri = exports.MockAdapter = exports.AbstractAdapter = exports.StringProperty = exports.ObjectProperty = exports.HashProperty = exports.EnumProperty = exports.DateTimeProperty = exports.BooleanProperty = exports.BaseProperty = exports.Property = exports.Core = exports.utils = exports.statuses = void 0;
|
|
29
|
+
exports.GoneError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.EntityRepository = exports.UserRepository = exports.InjectKeywordsMiddleware = exports.InjectMetaMiddleware = exports.SortAndLimit = exports.Sorting = exports.Limits = exports.Filters = exports.Filter = exports.Query = exports.BackendError = exports.BaseRepository = exports.BackendAction = exports.BaseObjectProperties = exports.BaseObjectCore = exports.AbstractObject = exports.DataObject = exports.ObjectUri = exports.MockAdapter = exports.AbstractAdapter = exports.StringProperty = exports.ObjectProperty = exports.HashProperty = exports.EnumProperty = exports.DateTimeProperty = exports.BooleanProperty = exports.BaseProperty = exports.Property = exports.Core = exports.utils = exports.statuses = void 0;
|
|
30
30
|
const Core_1 = require("./Core");
|
|
31
31
|
Object.defineProperty(exports, "Core", { enumerable: true, get: function () { return Core_1.Core; } });
|
|
32
32
|
const statuses = __importStar(require("./common/statuses"));
|
|
@@ -61,8 +61,12 @@ const BaseObject_1 = require("./components/BaseObject");
|
|
|
61
61
|
Object.defineProperty(exports, "BaseObjectProperties", { enumerable: true, get: function () { return BaseObject_1.BaseObjectProperties; } });
|
|
62
62
|
const InjectMetaMiddleware_1 = require("./backends/middlewares/InjectMetaMiddleware");
|
|
63
63
|
Object.defineProperty(exports, "InjectMetaMiddleware", { enumerable: true, get: function () { return InjectMetaMiddleware_1.InjectMetaMiddleware; } });
|
|
64
|
+
const InjectKeywordsMiddleware_1 = require("./backends/middlewares/InjectKeywordsMiddleware");
|
|
65
|
+
Object.defineProperty(exports, "InjectKeywordsMiddleware", { enumerable: true, get: function () { return InjectKeywordsMiddleware_1.InjectKeywordsMiddleware; } });
|
|
64
66
|
const BaseRepository_1 = __importDefault(require("./components/BaseRepository"));
|
|
65
67
|
exports.BaseRepository = BaseRepository_1.default;
|
|
68
|
+
const Backend_1 = require("./Backend");
|
|
69
|
+
Object.defineProperty(exports, "BackendAction", { enumerable: true, get: function () { return Backend_1.BackendAction; } });
|
|
66
70
|
const UserRepository_1 = __importDefault(require("./components/UserRepository"));
|
|
67
71
|
exports.UserRepository = UserRepository_1.default;
|
|
68
72
|
const EntityRepository_1 = __importDefault(require("./components/EntityRepository"));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseProperty, BasePropertyType } from './BaseProperty';
|
|
2
|
-
import { Query } from '../backends/Query';
|
|
2
|
+
import { Query, QueryResultType } from '../backends/Query';
|
|
3
3
|
import { Filter } from '../backends/Filter';
|
|
4
4
|
import { ObjectUri } from '../components/ObjectUri';
|
|
5
5
|
import { returnAs } from '../backends/Query';
|
|
@@ -28,6 +28,6 @@ export declare class CollectionProperty extends BaseProperty {
|
|
|
28
28
|
* @returns
|
|
29
29
|
*/
|
|
30
30
|
get(filters?: Filter[] | undefined): Query<any>;
|
|
31
|
-
val(transform?: returnAs): Promise<
|
|
31
|
+
val(transform?: returnAs): Promise<QueryResultType<any>>;
|
|
32
32
|
toJSON(): any[] | DataObjectClass<any>[] | ObjectUri[] | undefined;
|
|
33
33
|
}
|
|
@@ -16,6 +16,12 @@ export declare class HashProperty extends StringProperty {
|
|
|
16
16
|
protected _prefixed: boolean;
|
|
17
17
|
constructor(config: HashPropertyType);
|
|
18
18
|
_hash(value: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Never return the password which is hashed anyway
|
|
21
|
+
* @param transform
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
get(transform?: string | undefined): string | undefined;
|
|
19
25
|
set(value: string): this;
|
|
20
26
|
compare(value: string): boolean;
|
|
21
27
|
}
|
|
@@ -34,6 +34,14 @@ class HashProperty extends StringProperty_1.StringProperty {
|
|
|
34
34
|
this._rawValue = false; // don't test some constraints after hashing
|
|
35
35
|
return hash;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Never return the password which is hashed anyway
|
|
39
|
+
* @param transform
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
get(transform) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
37
45
|
set(value) {
|
|
38
46
|
return super.set(this._hash(value));
|
|
39
47
|
}
|