@quatrain/core 0.5.6 → 1.0.0-beta10
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 +34 -1
- package/lib/Backend.js +1 -9
- package/lib/Core.d.ts +11 -7
- package/lib/Core.js +13 -3
- package/lib/authentication/AbstractAuthAdapter.d.ts +18 -0
- package/lib/authentication/AbstractAuthAdapter.js +23 -0
- package/lib/authentication/AuthenticationError.d.ts +2 -0
- package/lib/authentication/AuthenticationError.js +6 -0
- package/lib/authentication/index.d.ts +4 -0
- package/lib/authentication/index.js +7 -0
- package/lib/authentication/middlewares/AbstractAuthMiddleware.d.ts +0 -0
- package/lib/authentication/middlewares/AbstractAuthMiddleware.js +1 -0
- package/lib/authentication/middlewares/AuthMiddleware.d.ts +5 -0
- package/lib/authentication/middlewares/AuthMiddleware.js +2 -0
- package/lib/authentication/middlewares/Middleware.d.ts +5 -0
- package/lib/authentication/middlewares/Middleware.js +2 -0
- package/lib/authentication/types/AuthInterface.d.ts +9 -0
- package/lib/authentication/types/AuthInterface.js +2 -0
- package/lib/backends/AbstractAdapter.d.ts +20 -45
- package/lib/backends/AbstractAdapter.js +27 -9
- package/lib/backends/Filters.d.ts +2 -1
- package/lib/backends/MockAdapter.d.ts +6 -4
- package/lib/backends/MockAdapter.js +15 -6
- package/lib/backends/Query.d.ts +29 -13
- package/lib/backends/Query.js +22 -9
- package/lib/backends/index.d.ts +5 -3
- package/lib/backends/index.js +26 -1
- package/lib/backends/middlewares/InjectKeywordsMiddleware.d.ts +9 -0
- package/lib/backends/middlewares/InjectKeywordsMiddleware.js +47 -0
- package/lib/backends/middlewares/InjectMetaMiddleware.d.ts +6 -6
- package/lib/backends/middlewares/InjectMetaMiddleware.js +10 -7
- package/lib/backends/middlewares/Middleware.d.ts +2 -2
- package/lib/backends/middlewares/types/MiddlewareParams.d.ts +3 -0
- package/lib/backends/middlewares/types/MiddlewareParams.js +2 -0
- package/lib/backends/types/BackendInterface.d.ts +13 -0
- package/lib/backends/types/BackendInterface.js +2 -0
- package/lib/backends/types/CollectionHierarchy.d.ts +3 -0
- package/lib/backends/types/CollectionHierarchy.js +6 -0
- package/lib/common/statuses.d.ts +3 -0
- package/lib/common/statuses.js +4 -1
- package/lib/components/AbstractObject.d.ts +9 -1
- package/lib/components/AbstractObject.js +9 -0
- package/lib/components/BaseObject.d.ts +3 -3
- package/lib/components/BaseObject.js +3 -0
- package/lib/components/BaseObjectCore.d.ts +16 -3
- package/lib/components/BaseObjectCore.js +21 -5
- package/lib/components/BaseRepository.d.ts +14 -13
- package/lib/components/BaseRepository.js +37 -21
- package/lib/components/DataObject.d.ts +20 -3
- package/lib/components/DataObject.js +73 -13
- package/lib/components/Entity.d.ts +4 -21
- package/lib/components/Entity.js +34 -32
- package/lib/components/EntityRepository.d.ts +3 -3
- package/lib/components/EntityRepository.js +1 -1
- package/lib/components/ObjectUri.js +2 -3
- 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 +3 -2
- package/lib/components/index.js +9 -2
- package/lib/components/types/DataObjectClass.d.ts +7 -1
- package/lib/components/types/RepositoryClass.d.ts +2 -2
- package/lib/components/types/toJSONParams.d.ts +8 -0
- package/lib/components/types/toJSONParams.js +2 -0
- package/lib/index.d.ts +10 -5
- package/lib/index.js +17 -2
- package/lib/properties/ArrayProperty.d.ts +1 -1
- package/lib/properties/ArrayProperty.js +2 -2
- package/lib/properties/BaseProperty.d.ts +4 -1
- package/lib/properties/BaseProperty.js +15 -3
- package/lib/properties/BooleanProperty.d.ts +1 -1
- package/lib/properties/BooleanProperty.js +2 -2
- package/lib/properties/CollectionProperty.d.ts +3 -3
- package/lib/properties/CollectionProperty.js +4 -3
- package/lib/properties/DateTimeProperty.d.ts +1 -1
- package/lib/properties/DateTimeProperty.js +2 -2
- package/lib/properties/EnumProperty.d.ts +1 -1
- package/lib/properties/EnumProperty.js +2 -2
- package/lib/properties/HashProperty.d.ts +7 -1
- package/lib/properties/HashProperty.js +10 -2
- package/lib/properties/MapProperty.d.ts +1 -1
- package/lib/properties/MapProperty.js +2 -2
- package/lib/properties/NumberProperty.d.ts +1 -1
- package/lib/properties/NumberProperty.js +2 -2
- package/lib/properties/ObjectProperty.d.ts +6 -6
- package/lib/properties/ObjectProperty.js +57 -5
- package/lib/properties/Property.d.ts +9 -2
- package/lib/properties/StringProperty.d.ts +2 -2
- package/lib/properties/StringProperty.js +2 -2
- package/lib/properties/types/AbstractPropertyType.d.ts +1 -0
- package/lib/properties/types/PropertyClassType.d.ts +4 -1
- package/lib/utils/DataGenerator.d.ts +2 -3
- package/lib/utils/DataGenerator.js +2 -1
- package/lib/wrappers/cloud/AbstractCloudWrapper.d.ts +4 -0
- package/lib/wrappers/cloud/AbstractCloudWrapper.js +9 -0
- package/package.json +3 -2
- package/README.md +0 -124
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
|
-
```
|