@quatrain/core 1.0.0-beta1 → 1.0.0-beta3
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 +28 -0
- package/lib/Core.d.ts +6 -8
- package/lib/Core.js +6 -5
- package/lib/authentication/AbstractAuthAdapter.d.ts +21 -0
- package/lib/authentication/AbstractAuthAdapter.js +28 -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/Middleware.d.ts +5 -0
- package/lib/authentication/types/AuthInterface.d.ts +9 -0
- package/lib/authentication/types/AuthInterface.js +2 -0
- package/lib/backends/AbstractAdapter.d.ts +11 -41
- package/lib/backends/AbstractAdapter.js +18 -5
- 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.d.ts +3 -3
- 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/AbstractObject.d.ts +1 -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 +12 -6
- package/lib/components/Entity.d.ts +5 -19
- package/lib/components/Entity.js +9 -7
- package/lib/components/EntityRepository.d.ts +3 -3
- package/lib/components/EntityRepository.js +1 -1
- package/lib/components/ObjectUri.js +1 -2
- package/lib/components/User.d.ts +4 -5
- package/lib/components/User.js +19 -10
- package/lib/components/UserRepository.d.ts +4 -4
- 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 +2 -0
- package/lib/components/types/RepositoryClass.d.ts +1 -1
- package/lib/index.d.ts +7 -3
- package/lib/index.js +14 -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 +2 -2
- package/README.md +0 -124
- 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/{components/types/UserClass.js → authentication/middlewares/Middleware.js} +0 -0
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';
|
|
@@ -1,5 +1,5 @@
|
|
|
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;
|
|
@@ -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') || '' });
|
|
@@ -237,6 +242,7 @@ class DataObject {
|
|
|
237
242
|
break;
|
|
238
243
|
case 'ObjectProperty':
|
|
239
244
|
const value = prop.val();
|
|
245
|
+
console.log(value, typeof value);
|
|
240
246
|
Reflect.set(data, key, value
|
|
241
247
|
? objectsAsReferences && !(value instanceof ObjectUri_1.ObjectUri)
|
|
242
248
|
? value.asReference()
|
|
@@ -1,26 +1,12 @@
|
|
|
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
|
-
export interface
|
|
7
|
-
users
|
|
6
|
+
export interface EntityType extends BaseObject {
|
|
7
|
+
users?: User[];
|
|
8
8
|
}
|
|
9
|
-
export declare class
|
|
9
|
+
export declare class Entity 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
|
@@ -23,8 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.Entity = 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");
|
|
@@ -46,24 +47,25 @@ exports.EntityProperties = [
|
|
|
46
47
|
parentKey: 'entity',
|
|
47
48
|
},
|
|
48
49
|
];
|
|
49
|
-
class
|
|
50
|
+
class Entity extends BaseObjectCore_1.BaseObjectCore {
|
|
50
51
|
}
|
|
51
|
-
exports.
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
exports.Entity = Entity;
|
|
53
|
+
Entity.COLLECTION = 'entities';
|
|
54
|
+
Entity.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',
|
|
64
66
|
mandatory: true,
|
|
65
67
|
type: CollectionProperty_1.CollectionProperty.TYPE,
|
|
66
|
-
instanceOf: User_1.
|
|
68
|
+
instanceOf: User_1.User,
|
|
67
69
|
parentKey: 'entity',
|
|
68
70
|
},
|
|
69
71
|
];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BackendInterface } from '../backends';
|
|
1
|
+
import { BackendInterface } from '../backends/types/BackendInterface';
|
|
2
2
|
import BaseRepository from './BaseRepository';
|
|
3
|
-
import {
|
|
4
|
-
export default class EntityRepository extends BaseRepository<
|
|
3
|
+
import { EntityType } from './Entity';
|
|
4
|
+
export default class EntityRepository extends BaseRepository<EntityType> {
|
|
5
5
|
constructor(backendAdapter?: BackendInterface);
|
|
6
6
|
}
|
|
@@ -8,7 +8,7 @@ const BaseRepository_1 = __importDefault(require("./BaseRepository"));
|
|
|
8
8
|
const Entity_1 = require("./Entity");
|
|
9
9
|
class EntityRepository extends BaseRepository_1.default {
|
|
10
10
|
constructor(backendAdapter = Core_1.Core.getBackend()) {
|
|
11
|
-
super(Entity_1.
|
|
11
|
+
super(Entity_1.Entity, backendAdapter);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.default = EntityRepository;
|
|
@@ -52,10 +52,9 @@ class ObjectUri {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
set class(objClass) {
|
|
55
|
-
var _a;
|
|
56
55
|
this._objClass = objClass;
|
|
57
56
|
if (objClass) {
|
|
58
|
-
this._collection = objClass.COLLECTION ||
|
|
57
|
+
this._collection = objClass.COLLECTION || objClass.name && objClass.name.toLowerCase();
|
|
59
58
|
}
|
|
60
59
|
else {
|
|
61
60
|
this._collection = undefined;
|
package/lib/components/User.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { BaseObjectCore } from './BaseObjectCore';
|
|
2
2
|
import { BaseObject } from './BaseObject';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export interface User extends BaseObject {
|
|
3
|
+
export interface UserType extends BaseObject {
|
|
4
|
+
name: string;
|
|
6
5
|
firstname: string;
|
|
7
6
|
lastname: string;
|
|
8
7
|
gender?: 'male' | 'female' | 'nonbinary';
|
|
@@ -11,8 +10,8 @@ export interface User extends BaseObject {
|
|
|
11
10
|
email: string;
|
|
12
11
|
}
|
|
13
12
|
export declare const UserProperties: any;
|
|
14
|
-
export declare class
|
|
13
|
+
export declare class User 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<User>;
|
|
18
17
|
}
|
package/lib/components/User.js
CHANGED
|
@@ -32,13 +32,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.
|
|
35
|
+
exports.User = exports.UserProperties = void 0;
|
|
36
36
|
const BaseObjectCore_1 = require("./BaseObjectCore");
|
|
37
37
|
const properties_1 = require("../properties");
|
|
38
38
|
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
|
},
|
|
@@ -95,33 +97,40 @@ exports.UserProperties = [
|
|
|
95
97
|
fullSearch: true,
|
|
96
98
|
htmlType: htmlType.EMAIL,
|
|
97
99
|
},
|
|
100
|
+
{
|
|
101
|
+
name: 'phone',
|
|
102
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
103
|
+
minLength: 1,
|
|
104
|
+
maxLength: 100,
|
|
105
|
+
htmlType: htmlType.OFF,
|
|
106
|
+
},
|
|
98
107
|
{
|
|
99
108
|
name: 'password',
|
|
100
109
|
mandatory: true,
|
|
101
110
|
type: HashProperty_1.HashProperty.TYPE,
|
|
102
111
|
algorithm: HashProperty_1.HashProperty.ALGORITHM_SHA256,
|
|
103
|
-
salt: '',
|
|
112
|
+
salt: '', // you should override it in your code
|
|
104
113
|
minLength: 5,
|
|
105
|
-
maxLength: 20,
|
|
114
|
+
maxLength: 20, // this is for the clear password
|
|
106
115
|
htmlType: htmlType.PASSWORD,
|
|
107
116
|
},
|
|
108
117
|
{
|
|
109
118
|
name: 'entity',
|
|
110
119
|
mandatory: false,
|
|
111
120
|
type: properties_1.ObjectProperty.TYPE,
|
|
112
|
-
instanceOf:
|
|
121
|
+
instanceOf: Entity_1.Entity,
|
|
113
122
|
},
|
|
114
123
|
];
|
|
115
|
-
class
|
|
124
|
+
class User extends BaseObjectCore_1.BaseObjectCore {
|
|
116
125
|
static factory(src = undefined) {
|
|
117
126
|
const _super = Object.create(null, {
|
|
118
127
|
factory: { get: () => super.factory }
|
|
119
128
|
});
|
|
120
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
return _super.factory.call(this, src,
|
|
130
|
+
return _super.factory.call(this, src, User);
|
|
122
131
|
});
|
|
123
132
|
}
|
|
124
133
|
}
|
|
125
|
-
exports.
|
|
126
|
-
|
|
127
|
-
|
|
134
|
+
exports.User = User;
|
|
135
|
+
User.PROPS_DEFINITION = exports.UserProperties;
|
|
136
|
+
User.COLLECTION = 'user';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BackendInterface } from '../backends';
|
|
1
|
+
import { BackendInterface } from '../backends/types/BackendInterface';
|
|
2
2
|
import BaseRepository from './BaseRepository';
|
|
3
|
-
import {
|
|
4
|
-
export default class UserRepository extends BaseRepository<
|
|
3
|
+
import { UserType } from './User';
|
|
4
|
+
export default class UserRepository extends BaseRepository<UserType> {
|
|
5
5
|
constructor(backendAdapter?: BackendInterface);
|
|
6
|
-
getFromEmail(email: string): Promise<
|
|
6
|
+
getFromEmail(email: string): Promise<UserType>;
|
|
7
7
|
}
|
|
@@ -19,11 +19,11 @@ const User_1 = require("./User");
|
|
|
19
19
|
const UNAUTHORIZED_ERROR = `Wrong password or email`;
|
|
20
20
|
class UserRepository extends BaseRepository_1.default {
|
|
21
21
|
constructor(backendAdapter) {
|
|
22
|
-
super(User_1.
|
|
22
|
+
super(User_1.User, backendAdapter);
|
|
23
23
|
}
|
|
24
24
|
getFromEmail(email) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const query = new backends_1.Query(User_1.
|
|
26
|
+
const query = new backends_1.Query(User_1.User);
|
|
27
27
|
query.where('email', email).batch(1);
|
|
28
28
|
const { items } = yield this.query(query);
|
|
29
29
|
if (items.length == 0) {
|
|
@@ -5,6 +5,6 @@ import { AbstractObject } from './AbstractObject';
|
|
|
5
5
|
import { BaseObjectCore } from './BaseObjectCore';
|
|
6
6
|
import { BaseObjectProperties } from './BaseObject';
|
|
7
7
|
import BaseRepository from './BaseRepository';
|
|
8
|
-
import {
|
|
8
|
+
import { User, UserProperties } from './User';
|
|
9
9
|
import { Entity } from './Entity';
|
|
10
|
-
export { DataObject, DataObjectParams, DataObjectClass, ObjectUri, AbstractObject, BaseObjectCore, BaseRepository,
|
|
10
|
+
export { DataObject, DataObjectParams, DataObjectClass, ObjectUri, AbstractObject, BaseObjectCore, BaseRepository, User, Entity, BaseObjectProperties, UserProperties, };
|
package/lib/components/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.UserProperties = exports.BaseObjectProperties = exports.
|
|
6
|
+
exports.UserProperties = exports.BaseObjectProperties = exports.Entity = exports.User = exports.BaseRepository = exports.BaseObjectCore = exports.AbstractObject = exports.ObjectUri = exports.DataObject = void 0;
|
|
7
7
|
const DataObject_1 = require("./DataObject");
|
|
8
8
|
Object.defineProperty(exports, "DataObject", { enumerable: true, get: function () { return DataObject_1.DataObject; } });
|
|
9
9
|
const ObjectUri_1 = require("./ObjectUri");
|
|
@@ -17,5 +17,7 @@ Object.defineProperty(exports, "BaseObjectProperties", { enumerable: true, get:
|
|
|
17
17
|
const BaseRepository_1 = __importDefault(require("./BaseRepository"));
|
|
18
18
|
exports.BaseRepository = BaseRepository_1.default;
|
|
19
19
|
const User_1 = require("./User");
|
|
20
|
-
Object.defineProperty(exports, "
|
|
20
|
+
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return User_1.User; } });
|
|
21
21
|
Object.defineProperty(exports, "UserProperties", { enumerable: true, get: function () { return User_1.UserProperties; } });
|
|
22
|
+
const Entity_1 = require("./Entity");
|
|
23
|
+
Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return Entity_1.Entity; } });
|
|
@@ -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,17 @@ 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
|
-
import { User } from './components/User';
|
|
25
|
+
import { UserType, 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 {
|
|
29
|
+
import { AuthAction, AuthParameters, AuthParametersKeys } from './Auth';
|
|
30
|
+
import { AuthInterface, AbstractAuthAdapter, AuthenticationError } from './authentication';
|
|
31
|
+
import { AbstractAdapter, MockAdapter, BackendError, Query, QueryMetaType, QueryResultType, Filter, Filters, Limits, Sorting, SortAndLimit } from './backends';
|
|
28
32
|
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, };
|
|
33
|
+
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, AuthAction, AuthParameters, AuthParametersKeys, AuthInterface, AbstractAuthAdapter, AuthenticationError, BackendParameters, BackendParametersKeys, BackendRecordType, BackendAction, BaseRepository, BackendError, Query, QueryMetaType, QueryResultType, Filter, Filters, Limits, Sorting, SortAndLimit, Middleware, InjectMetaMiddleware, InjectKeywordsMiddleware, User, UserType, 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.Entity = exports.UserRepository = exports.User = exports.InjectKeywordsMiddleware = exports.InjectMetaMiddleware = exports.SortAndLimit = exports.Sorting = exports.Limits = exports.Filters = exports.Filter = exports.Query = exports.BackendError = exports.BaseRepository = exports.BackendAction = exports.AuthenticationError = exports.AbstractAuthAdapter = exports.AuthAction = 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,12 +61,25 @@ 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; } });
|
|
70
|
+
const User_1 = require("./components/User");
|
|
71
|
+
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return User_1.User; } });
|
|
66
72
|
const UserRepository_1 = __importDefault(require("./components/UserRepository"));
|
|
67
73
|
exports.UserRepository = UserRepository_1.default;
|
|
74
|
+
const Entity_1 = require("./components/Entity");
|
|
75
|
+
Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return Entity_1.Entity; } });
|
|
68
76
|
const EntityRepository_1 = __importDefault(require("./components/EntityRepository"));
|
|
69
77
|
exports.EntityRepository = EntityRepository_1.default;
|
|
78
|
+
const Auth_1 = require("./Auth");
|
|
79
|
+
Object.defineProperty(exports, "AuthAction", { enumerable: true, get: function () { return Auth_1.AuthAction; } });
|
|
80
|
+
const authentication_1 = require("./authentication");
|
|
81
|
+
Object.defineProperty(exports, "AbstractAuthAdapter", { enumerable: true, get: function () { return authentication_1.AbstractAuthAdapter; } });
|
|
82
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return authentication_1.AuthenticationError; } });
|
|
70
83
|
const backends_1 = require("./backends");
|
|
71
84
|
Object.defineProperty(exports, "AbstractAdapter", { enumerable: true, get: function () { return backends_1.AbstractAdapter; } });
|
|
72
85
|
Object.defineProperty(exports, "MockAdapter", { enumerable: true, get: function () { return backends_1.MockAdapter; } });
|
|
@@ -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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/core",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta3",
|
|
4
4
|
"description": "Core objects for business apps",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -30,4 +30,4 @@
|
|
|
30
30
|
"push": "yarn publish --access public",
|
|
31
31
|
"prepublish": "tsc"
|
|
32
32
|
}
|
|
33
|
-
}
|
|
33
|
+
}
|