@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/README.md
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
# Quatrain Core
|
|
2
|
-
|
|
3
|
-
## Why
|
|
4
|
-
|
|
5
|
-
Quatrain Core is an abstraction layer designed to accelerate and simplify the development
|
|
6
|
-
of applications using many models and various data stores, being database or APIs.
|
|
7
|
-
|
|
8
|
-
With Quatrain Core and peer packages, one may develop robust applications based on
|
|
9
|
-
Oriented Object Programming with a clear separation of concerns between logic, data
|
|
10
|
-
and storage.
|
|
11
|
-
|
|
12
|
-
## How to install
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
yarn install @quatrain/core
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
Quatrain Core comes with a built-in Mock backend adapter. Other adapters are available in
|
|
19
|
-
different packages. For example, a Google Firestore adapter is available:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
yarn install @quatrain/backend-firestore
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## How to use
|
|
26
|
-
|
|
27
|
-
### Setup
|
|
28
|
-
|
|
29
|
-
```ts
|
|
30
|
-
import { Core } from '@quatrain/core'
|
|
31
|
-
|
|
32
|
-
Core.addBackend(myAdapter, 'myDB', true)
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### Create a model
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
import { BaseObjectCore } from '@quatrain/core'
|
|
39
|
-
|
|
40
|
-
export type Cat = {
|
|
41
|
-
name: string
|
|
42
|
-
color: `#${string}`
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export class CatCore extends BaseObjectCore {
|
|
46
|
-
static COLLECTION = 'cats'
|
|
47
|
-
|
|
48
|
-
static PROPERTIES = [
|
|
49
|
-
{
|
|
50
|
-
name: 'name',
|
|
51
|
-
type: Property.STRING,
|
|
52
|
-
minLength: 1,
|
|
53
|
-
maxLength: 32,
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: 'color',
|
|
57
|
-
type: Property.STRING,
|
|
58
|
-
minLength: 4,
|
|
59
|
-
maxLength: 7,
|
|
60
|
-
},
|
|
61
|
-
]
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Instantiate a model
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
const catData: Cat = {
|
|
69
|
-
name: 'Garfield',
|
|
70
|
-
color: '#ffa502',
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const garfield = CatCore.fromObject(catData)
|
|
74
|
-
|
|
75
|
-
console.log(garfield.name)
|
|
76
|
-
// > "Garfield"
|
|
77
|
-
console.log(garfield.color)
|
|
78
|
-
// > "#ffa502"
|
|
79
|
-
console.log(garfield.core)
|
|
80
|
-
// > CatCore { ... }
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Interact with backend
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
// Let's save Garfield in our database
|
|
87
|
-
garfield.core.save()
|
|
88
|
-
|
|
89
|
-
// Now, let's retrieve Garfield in the database
|
|
90
|
-
const persistedGarfield = await CatCore.fromBackend('garfield')
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### Using repositories
|
|
94
|
-
|
|
95
|
-
You can use repositories as an alternative way to persist and retrieve models in your backend.
|
|
96
|
-
|
|
97
|
-
This module provides a BaseRepository class that you can extend and override to apply your business logic when doing backend operations.
|
|
98
|
-
|
|
99
|
-
Let's create a repository for our Cat model, that prevents us from deleting a cat.
|
|
100
|
-
|
|
101
|
-
```ts
|
|
102
|
-
import { Core, BackendInterface, BaseRepository } from '@quatrain/core'
|
|
103
|
-
|
|
104
|
-
export default class CatRepository extends BaseRepository<Cat> {
|
|
105
|
-
constructor(backendAdapter: BackendInterface = Core.getBackend()) {
|
|
106
|
-
super(CatCore, backendAdapter)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async delete(uid: string) {
|
|
110
|
-
throw Error("Don't delete the cats!")
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
Now, let's use our new CatRepository.
|
|
116
|
-
|
|
117
|
-
```ts
|
|
118
|
-
const repository = new CatRepository()
|
|
119
|
-
|
|
120
|
-
repository.create(garfield)
|
|
121
|
-
repository.read('garfield')
|
|
122
|
-
repository.update(persistedGarfield)
|
|
123
|
-
repository.delete('garfield') // Will throw "Don't delete the cats!"
|
|
124
|
-
```
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { UserClass } from './types/UserClass';
|
|
2
|
-
import { ObjectUri } from './ObjectUri';
|
|
3
|
-
export interface BaseObjectType {
|
|
4
|
-
name: string;
|
|
5
|
-
status: string;
|
|
6
|
-
createdBy?: UserClass | ObjectUri;
|
|
7
|
-
createdAt?: number;
|
|
8
|
-
updatedBy?: UserClass | ObjectUri;
|
|
9
|
-
updatedAt?: number;
|
|
10
|
-
deletedBy?: UserClass | ObjectUri;
|
|
11
|
-
deletedAt?: number;
|
|
12
|
-
}
|
|
13
|
-
export declare const BaseObjectProperties: any;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.BaseObjectProperties = void 0;
|
|
27
|
-
const statuses = __importStar(require("../statuses"));
|
|
28
|
-
const StringProperty_1 = require("../properties/StringProperty");
|
|
29
|
-
const ObjectProperty_1 = require("../properties/ObjectProperty");
|
|
30
|
-
const EnumProperty_1 = require("../properties/EnumProperty");
|
|
31
|
-
const DateTimeProperty_1 = require("../properties/DateTimeProperty");
|
|
32
|
-
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
33
|
-
exports.BaseObjectProperties = [
|
|
34
|
-
{
|
|
35
|
-
name: 'name',
|
|
36
|
-
mandatory: true,
|
|
37
|
-
type: StringProperty_1.StringProperty.TYPE,
|
|
38
|
-
minLength: 1,
|
|
39
|
-
maxLength: 100,
|
|
40
|
-
htmlType: htmlType.NAME,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: 'status',
|
|
44
|
-
mandatory: true,
|
|
45
|
-
type: EnumProperty_1.EnumProperty.TYPE,
|
|
46
|
-
values: [
|
|
47
|
-
statuses.CREATED,
|
|
48
|
-
statuses.PENDING,
|
|
49
|
-
statuses.ACTIVE,
|
|
50
|
-
statuses.DELETED,
|
|
51
|
-
],
|
|
52
|
-
defaultValue: statuses.CREATED,
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: 'createdBy',
|
|
56
|
-
type: ObjectProperty_1.ObjectProperty.TYPE,
|
|
57
|
-
instanceOf: 'User',
|
|
58
|
-
mandatory: true,
|
|
59
|
-
protected: true,
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: 'createdAt',
|
|
63
|
-
type: DateTimeProperty_1.DateTimeProperty.TYPE,
|
|
64
|
-
mandatory: true,
|
|
65
|
-
protected: true,
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
name: 'updatedBy',
|
|
69
|
-
type: ObjectProperty_1.ObjectProperty.TYPE,
|
|
70
|
-
instanceOf: 'User',
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
name: 'updatedAt',
|
|
74
|
-
type: DateTimeProperty_1.DateTimeProperty.TYPE,
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
name: 'deletedBy',
|
|
78
|
-
type: ObjectProperty_1.ObjectProperty.TYPE,
|
|
79
|
-
instanceOf: 'User',
|
|
80
|
-
protected: true,
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
name: 'deletedAt',
|
|
84
|
-
type: DateTimeProperty_1.DateTimeProperty.TYPE,
|
|
85
|
-
protected: true,
|
|
86
|
-
},
|
|
87
|
-
];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const EntityProperties: any;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.EntityProperties = void 0;
|
|
27
|
-
const CollectionProperty_1 = require("../properties/CollectionProperty");
|
|
28
|
-
const StringProperty_1 = require("../properties/StringProperty");
|
|
29
|
-
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
30
|
-
const User_1 = require("./User");
|
|
31
|
-
exports.EntityProperties = [
|
|
32
|
-
{
|
|
33
|
-
// surcharge property minLength and htmlType
|
|
34
|
-
name: 'name',
|
|
35
|
-
type: StringProperty_1.StringProperty.TYPE,
|
|
36
|
-
mandatory: true,
|
|
37
|
-
minLength: 1,
|
|
38
|
-
htmlType: htmlType.ORG,
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: 'bogus',
|
|
42
|
-
type: StringProperty_1.StringProperty.TYPE,
|
|
43
|
-
mandatory: true,
|
|
44
|
-
minLength: 1,
|
|
45
|
-
htmlType: htmlType.ORG,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: 'users',
|
|
49
|
-
mandatory: true,
|
|
50
|
-
type: CollectionProperty_1.CollectionProperty.TYPE,
|
|
51
|
-
instanceOf: User_1.User,
|
|
52
|
-
parentKey: 'entity',
|
|
53
|
-
},
|
|
54
|
-
];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const UserProperties: any;
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.UserProperties = void 0;
|
|
27
|
-
const properties_1 = require("../properties");
|
|
28
|
-
const HashProperty_1 = require("../properties/HashProperty");
|
|
29
|
-
const StringProperty_1 = require("../properties/StringProperty");
|
|
30
|
-
const Entity_1 = require("./Entity");
|
|
31
|
-
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
32
|
-
/**
|
|
33
|
-
* Callback function to populate the 'name' property
|
|
34
|
-
* @param dao DataObject
|
|
35
|
-
* @returns
|
|
36
|
-
*/
|
|
37
|
-
const onChange = (dao) => dao.set('name', `${dao.val('firstname')} ${dao.val('lastname')}`);
|
|
38
|
-
exports.UserProperties = [
|
|
39
|
-
{
|
|
40
|
-
// change name property minLength
|
|
41
|
-
name: 'name',
|
|
42
|
-
type: StringProperty_1.StringProperty.TYPE,
|
|
43
|
-
minLength: 0,
|
|
44
|
-
fullSearch: true,
|
|
45
|
-
htmlType: htmlType.NAME,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: 'firstname',
|
|
49
|
-
mandatory: true,
|
|
50
|
-
type: StringProperty_1.StringProperty.TYPE,
|
|
51
|
-
minLength: 1,
|
|
52
|
-
maxLength: 100,
|
|
53
|
-
htmlType: htmlType.GIVEN_NAME,
|
|
54
|
-
onChange,
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
name: 'lastname',
|
|
58
|
-
mandatory: true,
|
|
59
|
-
type: StringProperty_1.StringProperty.TYPE,
|
|
60
|
-
minLength: 1,
|
|
61
|
-
maxLength: 100,
|
|
62
|
-
htmlType: htmlType.FAMILY_NAME,
|
|
63
|
-
onChange,
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
name: 'gender',
|
|
67
|
-
mandatory: false,
|
|
68
|
-
type: properties_1.EnumProperty.TYPE,
|
|
69
|
-
values: ['male', 'female', 'nonbinary'],
|
|
70
|
-
htmlType: htmlType.GENDER,
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
name: 'birthday',
|
|
74
|
-
mandatory: false,
|
|
75
|
-
type: properties_1.DateTimeProperty.TYPE,
|
|
76
|
-
htmlType: htmlType.BIRTHDAY,
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
name: 'email',
|
|
80
|
-
mandatory: true,
|
|
81
|
-
type: StringProperty_1.StringProperty.TYPE,
|
|
82
|
-
minLength: 1,
|
|
83
|
-
maxLength: 100,
|
|
84
|
-
fullSearch: true,
|
|
85
|
-
htmlType: htmlType.EMAIL,
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
name: 'password',
|
|
89
|
-
mandatory: true,
|
|
90
|
-
type: HashProperty_1.HashProperty.TYPE,
|
|
91
|
-
algorithm: HashProperty_1.HashProperty.ALGORITHM_SHA256,
|
|
92
|
-
salt: '',
|
|
93
|
-
minLength: 5,
|
|
94
|
-
maxLength: 20,
|
|
95
|
-
htmlType: htmlType.PASSWORD,
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
name: 'entity',
|
|
99
|
-
mandatory: false,
|
|
100
|
-
type: properties_1.ObjectProperty.TYPE,
|
|
101
|
-
instanceof: Entity_1.Entity,
|
|
102
|
-
},
|
|
103
|
-
];
|
|
File without changes
|