@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.
Files changed (100) hide show
  1. package/lib/Auth.d.ts +25 -0
  2. package/lib/Auth.js +9 -0
  3. package/lib/Backend.d.ts +34 -1
  4. package/lib/Backend.js +1 -9
  5. package/lib/Core.d.ts +11 -7
  6. package/lib/Core.js +13 -3
  7. package/lib/authentication/AbstractAuthAdapter.d.ts +18 -0
  8. package/lib/authentication/AbstractAuthAdapter.js +23 -0
  9. package/lib/authentication/AuthenticationError.d.ts +2 -0
  10. package/lib/authentication/AuthenticationError.js +6 -0
  11. package/lib/authentication/index.d.ts +4 -0
  12. package/lib/authentication/index.js +7 -0
  13. package/lib/authentication/middlewares/AbstractAuthMiddleware.d.ts +0 -0
  14. package/lib/authentication/middlewares/AbstractAuthMiddleware.js +1 -0
  15. package/lib/authentication/middlewares/AuthMiddleware.d.ts +5 -0
  16. package/lib/authentication/middlewares/AuthMiddleware.js +2 -0
  17. package/lib/authentication/middlewares/Middleware.d.ts +5 -0
  18. package/lib/authentication/middlewares/Middleware.js +2 -0
  19. package/lib/authentication/types/AuthInterface.d.ts +9 -0
  20. package/lib/authentication/types/AuthInterface.js +2 -0
  21. package/lib/backends/AbstractAdapter.d.ts +20 -45
  22. package/lib/backends/AbstractAdapter.js +27 -9
  23. package/lib/backends/Filters.d.ts +2 -1
  24. package/lib/backends/MockAdapter.d.ts +6 -4
  25. package/lib/backends/MockAdapter.js +15 -6
  26. package/lib/backends/Query.d.ts +29 -13
  27. package/lib/backends/Query.js +22 -9
  28. package/lib/backends/index.d.ts +5 -3
  29. package/lib/backends/index.js +26 -1
  30. package/lib/backends/middlewares/InjectKeywordsMiddleware.d.ts +9 -0
  31. package/lib/backends/middlewares/InjectKeywordsMiddleware.js +47 -0
  32. package/lib/backends/middlewares/InjectMetaMiddleware.d.ts +6 -6
  33. package/lib/backends/middlewares/InjectMetaMiddleware.js +10 -7
  34. package/lib/backends/middlewares/Middleware.d.ts +2 -2
  35. package/lib/backends/middlewares/types/MiddlewareParams.d.ts +3 -0
  36. package/lib/backends/middlewares/types/MiddlewareParams.js +2 -0
  37. package/lib/backends/types/BackendInterface.d.ts +13 -0
  38. package/lib/backends/types/BackendInterface.js +2 -0
  39. package/lib/backends/types/CollectionHierarchy.d.ts +3 -0
  40. package/lib/backends/types/CollectionHierarchy.js +6 -0
  41. package/lib/common/statuses.d.ts +3 -0
  42. package/lib/common/statuses.js +4 -1
  43. package/lib/components/AbstractObject.d.ts +9 -1
  44. package/lib/components/AbstractObject.js +9 -0
  45. package/lib/components/BaseObject.d.ts +3 -3
  46. package/lib/components/BaseObject.js +3 -0
  47. package/lib/components/BaseObjectCore.d.ts +16 -3
  48. package/lib/components/BaseObjectCore.js +21 -5
  49. package/lib/components/BaseRepository.d.ts +14 -13
  50. package/lib/components/BaseRepository.js +37 -21
  51. package/lib/components/DataObject.d.ts +20 -3
  52. package/lib/components/DataObject.js +73 -13
  53. package/lib/components/Entity.d.ts +4 -21
  54. package/lib/components/Entity.js +34 -32
  55. package/lib/components/EntityRepository.d.ts +3 -3
  56. package/lib/components/EntityRepository.js +1 -1
  57. package/lib/components/ObjectUri.js +2 -3
  58. package/lib/components/User.d.ts +4 -5
  59. package/lib/components/User.js +19 -10
  60. package/lib/components/UserRepository.d.ts +4 -4
  61. package/lib/components/UserRepository.js +2 -2
  62. package/lib/components/index.d.ts +3 -2
  63. package/lib/components/index.js +9 -2
  64. package/lib/components/types/DataObjectClass.d.ts +7 -1
  65. package/lib/components/types/RepositoryClass.d.ts +2 -2
  66. package/lib/components/types/toJSONParams.d.ts +8 -0
  67. package/lib/components/types/toJSONParams.js +2 -0
  68. package/lib/index.d.ts +10 -5
  69. package/lib/index.js +17 -2
  70. package/lib/properties/ArrayProperty.d.ts +1 -1
  71. package/lib/properties/ArrayProperty.js +2 -2
  72. package/lib/properties/BaseProperty.d.ts +4 -1
  73. package/lib/properties/BaseProperty.js +15 -3
  74. package/lib/properties/BooleanProperty.d.ts +1 -1
  75. package/lib/properties/BooleanProperty.js +2 -2
  76. package/lib/properties/CollectionProperty.d.ts +3 -3
  77. package/lib/properties/CollectionProperty.js +4 -3
  78. package/lib/properties/DateTimeProperty.d.ts +1 -1
  79. package/lib/properties/DateTimeProperty.js +2 -2
  80. package/lib/properties/EnumProperty.d.ts +1 -1
  81. package/lib/properties/EnumProperty.js +2 -2
  82. package/lib/properties/HashProperty.d.ts +7 -1
  83. package/lib/properties/HashProperty.js +10 -2
  84. package/lib/properties/MapProperty.d.ts +1 -1
  85. package/lib/properties/MapProperty.js +2 -2
  86. package/lib/properties/NumberProperty.d.ts +1 -1
  87. package/lib/properties/NumberProperty.js +2 -2
  88. package/lib/properties/ObjectProperty.d.ts +6 -6
  89. package/lib/properties/ObjectProperty.js +57 -5
  90. package/lib/properties/Property.d.ts +9 -2
  91. package/lib/properties/StringProperty.d.ts +2 -2
  92. package/lib/properties/StringProperty.js +2 -2
  93. package/lib/properties/types/AbstractPropertyType.d.ts +1 -0
  94. package/lib/properties/types/PropertyClassType.d.ts +4 -1
  95. package/lib/utils/DataGenerator.d.ts +2 -3
  96. package/lib/utils/DataGenerator.js +2 -1
  97. package/lib/wrappers/cloud/AbstractCloudWrapper.d.ts +4 -0
  98. package/lib/wrappers/cloud/AbstractCloudWrapper.js +9 -0
  99. package/package.json +3 -2
  100. 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
- ```