@flowerforce/flowerbase 1.0.1-beta.3

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 (292) hide show
  1. package/CHANGELOG.md +0 -0
  2. package/LICENSE +3 -0
  3. package/README.md +18 -0
  4. package/dist/auth/controller.d.ts +8 -0
  5. package/dist/auth/controller.d.ts.map +1 -0
  6. package/dist/auth/controller.js +76 -0
  7. package/dist/auth/dtos.d.ts +6 -0
  8. package/dist/auth/dtos.d.ts.map +1 -0
  9. package/dist/auth/dtos.js +2 -0
  10. package/dist/auth/plugins/jwt.d.ts +14 -0
  11. package/dist/auth/plugins/jwt.d.ts.map +1 -0
  12. package/dist/auth/plugins/jwt.js +68 -0
  13. package/dist/auth/providers/local-userpass/controller.d.ts +8 -0
  14. package/dist/auth/providers/local-userpass/controller.d.ts.map +1 -0
  15. package/dist/auth/providers/local-userpass/controller.js +184 -0
  16. package/dist/auth/providers/local-userpass/dtos.d.ts +35 -0
  17. package/dist/auth/providers/local-userpass/dtos.d.ts.map +1 -0
  18. package/dist/auth/providers/local-userpass/dtos.js +2 -0
  19. package/dist/auth/utils.d.ts +126 -0
  20. package/dist/auth/utils.d.ts.map +1 -0
  21. package/dist/auth/utils.js +122 -0
  22. package/dist/constants.d.ts +18 -0
  23. package/dist/constants.d.ts.map +1 -0
  24. package/dist/constants.js +34 -0
  25. package/dist/features/endpoints/index.d.ts +10 -0
  26. package/dist/features/endpoints/index.d.ts.map +1 -0
  27. package/dist/features/endpoints/index.js +31 -0
  28. package/dist/features/endpoints/interface.d.ts +27 -0
  29. package/dist/features/endpoints/interface.d.ts.map +1 -0
  30. package/dist/features/endpoints/interface.js +2 -0
  31. package/dist/features/endpoints/utils.d.ts +31 -0
  32. package/dist/features/endpoints/utils.d.ts.map +1 -0
  33. package/dist/features/endpoints/utils.js +85 -0
  34. package/dist/features/functions/controller.d.ts +9 -0
  35. package/dist/features/functions/controller.d.ts.map +1 -0
  36. package/dist/features/functions/controller.js +88 -0
  37. package/dist/features/functions/dtos.d.ts +34 -0
  38. package/dist/features/functions/dtos.d.ts.map +1 -0
  39. package/dist/features/functions/dtos.js +2 -0
  40. package/dist/features/functions/index.d.ts +9 -0
  41. package/dist/features/functions/index.d.ts.map +1 -0
  42. package/dist/features/functions/index.js +28 -0
  43. package/dist/features/functions/interface.d.ts +32 -0
  44. package/dist/features/functions/interface.d.ts.map +1 -0
  45. package/dist/features/functions/interface.js +2 -0
  46. package/dist/features/functions/utils.d.ts +23 -0
  47. package/dist/features/functions/utils.d.ts.map +1 -0
  48. package/dist/features/functions/utils.js +75 -0
  49. package/dist/features/rules/index.d.ts +1 -0
  50. package/dist/features/rules/index.d.ts.map +1 -0
  51. package/dist/features/rules/index.js +1 -0
  52. package/dist/features/rules/interface.d.ts +22 -0
  53. package/dist/features/rules/interface.d.ts.map +1 -0
  54. package/dist/features/rules/interface.js +2 -0
  55. package/dist/features/rules/utils.d.ts +3 -0
  56. package/dist/features/rules/utils.d.ts.map +1 -0
  57. package/dist/features/rules/utils.js +31 -0
  58. package/dist/features/triggers/dtos.d.ts +9 -0
  59. package/dist/features/triggers/dtos.d.ts.map +1 -0
  60. package/dist/features/triggers/dtos.js +2 -0
  61. package/dist/features/triggers/index.d.ts +10 -0
  62. package/dist/features/triggers/index.d.ts.map +1 -0
  63. package/dist/features/triggers/index.js +57 -0
  64. package/dist/features/triggers/interface.d.ts +44 -0
  65. package/dist/features/triggers/interface.d.ts.map +1 -0
  66. package/dist/features/triggers/interface.js +2 -0
  67. package/dist/features/triggers/utils.d.ts +16 -0
  68. package/dist/features/triggers/utils.d.ts.map +1 -0
  69. package/dist/features/triggers/utils.js +153 -0
  70. package/dist/index.d.ts +19 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +84 -0
  73. package/dist/model.d.ts +2 -0
  74. package/dist/model.d.ts.map +1 -0
  75. package/dist/model.js +2 -0
  76. package/dist/services/api/index.d.ts +36 -0
  77. package/dist/services/api/index.d.ts.map +1 -0
  78. package/dist/services/api/index.js +36 -0
  79. package/dist/services/api/model.d.ts +33 -0
  80. package/dist/services/api/model.d.ts.map +1 -0
  81. package/dist/services/api/model.js +2 -0
  82. package/dist/services/api/utils.d.ts +16 -0
  83. package/dist/services/api/utils.d.ts.map +1 -0
  84. package/dist/services/api/utils.js +45 -0
  85. package/dist/services/aws/index.d.ts +13 -0
  86. package/dist/services/aws/index.d.ts.map +1 -0
  87. package/dist/services/aws/index.js +50 -0
  88. package/dist/services/index.d.ts +41 -0
  89. package/dist/services/index.d.ts.map +1 -0
  90. package/dist/services/index.js +14 -0
  91. package/dist/services/interface.d.ts +3 -0
  92. package/dist/services/interface.d.ts.map +1 -0
  93. package/dist/services/interface.js +2 -0
  94. package/dist/services/mongodb-atlas/index.d.ts +4 -0
  95. package/dist/services/mongodb-atlas/index.d.ts.map +1 -0
  96. package/dist/services/mongodb-atlas/index.js +483 -0
  97. package/dist/services/mongodb-atlas/model.d.ts +39 -0
  98. package/dist/services/mongodb-atlas/model.d.ts.map +1 -0
  99. package/dist/services/mongodb-atlas/model.js +2 -0
  100. package/dist/services/mongodb-atlas/utils.d.ts +8 -0
  101. package/dist/services/mongodb-atlas/utils.d.ts.map +1 -0
  102. package/dist/services/mongodb-atlas/utils.js +33 -0
  103. package/dist/state.d.ts +6 -0
  104. package/dist/state.d.ts.map +1 -0
  105. package/dist/state.js +18 -0
  106. package/dist/utils/context/helpers.d.ts +74 -0
  107. package/dist/utils/context/helpers.d.ts.map +1 -0
  108. package/dist/utils/context/helpers.js +60 -0
  109. package/dist/utils/context/index.d.ts +14 -0
  110. package/dist/utils/context/index.d.ts.map +1 -0
  111. package/dist/utils/context/index.js +50 -0
  112. package/dist/utils/context/interface.d.ts +18 -0
  113. package/dist/utils/context/interface.d.ts.map +1 -0
  114. package/dist/utils/context/interface.js +2 -0
  115. package/dist/utils/crypto/index.d.ts +19 -0
  116. package/dist/utils/crypto/index.d.ts.map +1 -0
  117. package/dist/utils/crypto/index.js +50 -0
  118. package/dist/utils/helpers/someAsync.d.ts +12 -0
  119. package/dist/utils/helpers/someAsync.d.ts.map +1 -0
  120. package/dist/utils/helpers/someAsync.js +56 -0
  121. package/dist/utils/index.d.ts +3 -0
  122. package/dist/utils/index.d.ts.map +1 -0
  123. package/dist/utils/index.js +11 -0
  124. package/dist/utils/initializer/exposeRoutes.d.ts +8 -0
  125. package/dist/utils/initializer/exposeRoutes.d.ts.map +1 -0
  126. package/dist/utils/initializer/exposeRoutes.js +41 -0
  127. package/dist/utils/initializer/registerPlugins.d.ts +19 -0
  128. package/dist/utils/initializer/registerPlugins.d.ts.map +1 -0
  129. package/dist/utils/initializer/registerPlugins.js +84 -0
  130. package/dist/utils/roles/helpers.d.ts +4 -0
  131. package/dist/utils/roles/helpers.d.ts.map +1 -0
  132. package/dist/utils/roles/helpers.js +47 -0
  133. package/dist/utils/roles/interface.d.ts +33 -0
  134. package/dist/utils/roles/interface.d.ts.map +1 -0
  135. package/dist/utils/roles/interface.js +2 -0
  136. package/dist/utils/roles/machines/commonValidators.d.ts +6 -0
  137. package/dist/utils/roles/machines/commonValidators.d.ts.map +1 -0
  138. package/dist/utils/roles/machines/commonValidators.js +34 -0
  139. package/dist/utils/roles/machines/index.d.ts +14 -0
  140. package/dist/utils/roles/machines/index.d.ts.map +1 -0
  141. package/dist/utils/roles/machines/index.js +27 -0
  142. package/dist/utils/roles/machines/interface.d.ts +46 -0
  143. package/dist/utils/roles/machines/interface.d.ts.map +1 -0
  144. package/dist/utils/roles/machines/interface.js +2 -0
  145. package/dist/utils/roles/machines/machine.d.ts +15 -0
  146. package/dist/utils/roles/machines/machine.d.ts.map +1 -0
  147. package/dist/utils/roles/machines/machine.js +97 -0
  148. package/dist/utils/roles/machines/read/A/index.d.ts +3 -0
  149. package/dist/utils/roles/machines/read/A/index.d.ts.map +1 -0
  150. package/dist/utils/roles/machines/read/A/index.js +27 -0
  151. package/dist/utils/roles/machines/read/B/index.d.ts +3 -0
  152. package/dist/utils/roles/machines/read/B/index.d.ts.map +1 -0
  153. package/dist/utils/roles/machines/read/B/index.js +36 -0
  154. package/dist/utils/roles/machines/read/C/index.d.ts +3 -0
  155. package/dist/utils/roles/machines/read/C/index.d.ts.map +1 -0
  156. package/dist/utils/roles/machines/read/C/index.js +38 -0
  157. package/dist/utils/roles/machines/read/D/index.d.ts +3 -0
  158. package/dist/utils/roles/machines/read/D/index.d.ts.map +1 -0
  159. package/dist/utils/roles/machines/read/D/index.js +26 -0
  160. package/dist/utils/roles/machines/read/D/validators.d.ts +4 -0
  161. package/dist/utils/roles/machines/read/D/validators.d.ts.map +1 -0
  162. package/dist/utils/roles/machines/read/D/validators.js +24 -0
  163. package/dist/utils/roles/machines/read/index.d.ts +2 -0
  164. package/dist/utils/roles/machines/read/index.d.ts.map +1 -0
  165. package/dist/utils/roles/machines/read/index.js +8 -0
  166. package/dist/utils/roles/machines/utils.d.ts +37 -0
  167. package/dist/utils/roles/machines/utils.d.ts.map +1 -0
  168. package/dist/utils/roles/machines/utils.js +54 -0
  169. package/dist/utils/roles/machines/write/A/index.d.ts +3 -0
  170. package/dist/utils/roles/machines/write/A/index.d.ts.map +1 -0
  171. package/dist/utils/roles/machines/write/A/index.js +29 -0
  172. package/dist/utils/roles/machines/write/B/index.d.ts +3 -0
  173. package/dist/utils/roles/machines/write/B/index.d.ts.map +1 -0
  174. package/dist/utils/roles/machines/write/B/index.js +47 -0
  175. package/dist/utils/roles/machines/write/C/index.d.ts +3 -0
  176. package/dist/utils/roles/machines/write/C/index.d.ts.map +1 -0
  177. package/dist/utils/roles/machines/write/C/index.js +26 -0
  178. package/dist/utils/roles/machines/write/C/validators.d.ts +4 -0
  179. package/dist/utils/roles/machines/write/C/validators.d.ts.map +1 -0
  180. package/dist/utils/roles/machines/write/C/validators.js +24 -0
  181. package/dist/utils/roles/machines/write/index.d.ts +2 -0
  182. package/dist/utils/roles/machines/write/index.d.ts.map +1 -0
  183. package/dist/utils/roles/machines/write/index.js +7 -0
  184. package/dist/utils/rules-matcher/interface.d.ts +338 -0
  185. package/dist/utils/rules-matcher/interface.d.ts.map +1 -0
  186. package/dist/utils/rules-matcher/interface.js +26 -0
  187. package/dist/utils/rules-matcher/utils.d.ts +11 -0
  188. package/dist/utils/rules-matcher/utils.d.ts.map +1 -0
  189. package/dist/utils/rules-matcher/utils.js +214 -0
  190. package/dist/utils/rules.d.ts +2 -0
  191. package/dist/utils/rules.d.ts.map +1 -0
  192. package/dist/utils/rules.js +22 -0
  193. package/jest.config.ts +24 -0
  194. package/package.json +63 -0
  195. package/project.json +10 -0
  196. package/rollup.config.js +17 -0
  197. package/src/auth/controller.ts +78 -0
  198. package/src/auth/dtos.ts +6 -0
  199. package/src/auth/plugins/jwt.ts +68 -0
  200. package/src/auth/providers/local-userpass/controller.ts +226 -0
  201. package/src/auth/providers/local-userpass/dtos.ts +40 -0
  202. package/src/auth/utils.ts +165 -0
  203. package/src/babel.config.json +3 -0
  204. package/src/constants.ts +22 -0
  205. package/src/fastify.d.ts +28 -0
  206. package/src/features/endpoints/index.ts +27 -0
  207. package/src/features/endpoints/interface.ts +29 -0
  208. package/src/features/endpoints/utils.ts +72 -0
  209. package/src/features/functions/controller.ts +102 -0
  210. package/src/features/functions/dtos.ts +41 -0
  211. package/src/features/functions/index.ts +21 -0
  212. package/src/features/functions/interface.ts +38 -0
  213. package/src/features/functions/utils.ts +82 -0
  214. package/src/features/rules/index.tsx +0 -0
  215. package/src/features/rules/interface.ts +24 -0
  216. package/src/features/rules/utils.ts +20 -0
  217. package/src/features/triggers/dtos.ts +9 -0
  218. package/src/features/triggers/index.ts +34 -0
  219. package/src/features/triggers/interface.ts +44 -0
  220. package/src/features/triggers/utils.ts +157 -0
  221. package/src/global.d.ts +0 -0
  222. package/src/index.ts +75 -0
  223. package/src/model.ts +1 -0
  224. package/src/services/api/index.ts +50 -0
  225. package/src/services/api/model.ts +38 -0
  226. package/src/services/api/utils.ts +39 -0
  227. package/src/services/aws/index.ts +48 -0
  228. package/src/services/index.ts +9 -0
  229. package/src/services/interface.ts +3 -0
  230. package/src/services/mongodb-atlas/index.ts +569 -0
  231. package/src/services/mongodb-atlas/model.ts +67 -0
  232. package/src/services/mongodb-atlas/utils.ts +44 -0
  233. package/src/state.ts +24 -0
  234. package/src/utils/__tests__/STEP_A_STATES.test.ts +54 -0
  235. package/src/utils/__tests__/STEP_B_STATES.test.ts +113 -0
  236. package/src/utils/__tests__/STEP_C_STATES.test.ts +87 -0
  237. package/src/utils/__tests__/STEP_D_STATES.test.ts +93 -0
  238. package/src/utils/__tests__/checkAdditionalFieldsFn.test.ts +45 -0
  239. package/src/utils/__tests__/checkApplyWhen.test.ts +49 -0
  240. package/src/utils/__tests__/checkFieldsPropertyExists.test.ts +47 -0
  241. package/src/utils/__tests__/checkIsValidFieldNameFn.test.ts +190 -0
  242. package/src/utils/__tests__/comparePassword.test.ts +38 -0
  243. package/src/utils/__tests__/evaluateDocumentsFiltersReadFn.test.ts +57 -0
  244. package/src/utils/__tests__/evaluateDocumentsFiltersWriteFn.test.ts +57 -0
  245. package/src/utils/__tests__/evaluateTopLevelReadFn.test.ts +58 -0
  246. package/src/utils/__tests__/evaluateTopLevelWriteFn.test.ts +66 -0
  247. package/src/utils/__tests__/exposeRoutes.test.ts +65 -0
  248. package/src/utils/__tests__/generateContextData.test.ts +75 -0
  249. package/src/utils/__tests__/getDefaultRule.test.ts +29 -0
  250. package/src/utils/__tests__/getKey.test.ts +12 -0
  251. package/src/utils/__tests__/getKeys.test.ts +11 -0
  252. package/src/utils/__tests__/getWinningRole.test.ts +66 -0
  253. package/src/utils/__tests__/hashPassword.test.ts +28 -0
  254. package/src/utils/__tests__/isEmpty.test.ts +17 -0
  255. package/src/utils/__tests__/logMachineInfo.test.ts +15 -0
  256. package/src/utils/__tests__/operators.test.ts +99 -0
  257. package/src/utils/__tests__/readFileContent.test.ts +35 -0
  258. package/src/utils/__tests__/registerPlugins.test.ts +59 -0
  259. package/src/utils/__tests__/rule.test.ts +51 -0
  260. package/src/utils/__tests__/rulesMatcherInterfaces.test.ts +57 -0
  261. package/src/utils/__tests__/rulesMatcherUtils.test.ts +56 -0
  262. package/src/utils/__tests__/someAsync.test.ts +55 -0
  263. package/src/utils/context/helpers.ts +71 -0
  264. package/src/utils/context/index.ts +52 -0
  265. package/src/utils/context/interface.ts +19 -0
  266. package/src/utils/crypto/index.ts +36 -0
  267. package/src/utils/helpers/someAsync.ts +24 -0
  268. package/src/utils/index.ts +5 -0
  269. package/src/utils/initializer/exposeRoutes.ts +26 -0
  270. package/src/utils/initializer/registerPlugins.ts +97 -0
  271. package/src/utils/roles/helpers.ts +47 -0
  272. package/src/utils/roles/interface.ts +42 -0
  273. package/src/utils/roles/machines/commonValidators.ts +24 -0
  274. package/src/utils/roles/machines/index.ts +20 -0
  275. package/src/utils/roles/machines/interface.ts +46 -0
  276. package/src/utils/roles/machines/machine.ts +85 -0
  277. package/src/utils/roles/machines/read/A/index.ts +19 -0
  278. package/src/utils/roles/machines/read/B/index.ts +31 -0
  279. package/src/utils/roles/machines/read/C/index.ts +30 -0
  280. package/src/utils/roles/machines/read/D/index.ts +20 -0
  281. package/src/utils/roles/machines/read/D/validators.ts +24 -0
  282. package/src/utils/roles/machines/read/index.ts +6 -0
  283. package/src/utils/roles/machines/utils.ts +54 -0
  284. package/src/utils/roles/machines/write/A/index.ts +25 -0
  285. package/src/utils/roles/machines/write/B/index.ts +43 -0
  286. package/src/utils/roles/machines/write/C/index.ts +20 -0
  287. package/src/utils/roles/machines/write/C/validators.ts +24 -0
  288. package/src/utils/roles/machines/write/index.ts +5 -0
  289. package/src/utils/rules-matcher/interface.ts +365 -0
  290. package/src/utils/rules-matcher/utils.ts +281 -0
  291. package/src/utils/rules.ts +19 -0
  292. package/tsconfig.json +28 -0
@@ -0,0 +1,25 @@
1
+ import { evaluateDocumentFiltersFn } from '../../commonValidators'
2
+ import { States } from '../../interface'
3
+ import { logMachineInfo } from '../../utils'
4
+
5
+ export const STEP_A_STATES: States = {
6
+ checkDocumentsFilters: async ({ context, next, goToNextValidationStage }) => {
7
+ logMachineInfo({ enabled: context.enableLog, machine: "A", step: 1, stepName: "checkDocumentsFilters" })
8
+ const { role } = context
9
+ if (role.document_filters) {
10
+ return next('evaluateDocumentsFiltersWrite')
11
+ }
12
+ return goToNextValidationStage()
13
+ },
14
+ evaluateDocumentsFiltersWrite: async ({
15
+ context,
16
+ endValidation,
17
+ goToNextValidationStage
18
+ }) => {
19
+ logMachineInfo({ enabled: context.enableLog, machine: "B", step: 2, stepName: "evaluateDocumentsFiltersWrite" })
20
+ const check = await evaluateDocumentFiltersFn(context, "write")
21
+ return check ? goToNextValidationStage() : endValidation({ success: false })
22
+ }
23
+ }
24
+
25
+
@@ -0,0 +1,43 @@
1
+ import { checkFieldsPropertyExists, evaluateTopLevelPermissionsFn } from '../../commonValidators'
2
+ import { States } from '../../interface'
3
+ import { logMachineInfo } from '../../utils'
4
+
5
+ export const STEP_B_STATES: States = {
6
+ checkDeleteRequest: async ({ context, next }) => {
7
+ logMachineInfo({ enabled: context.enableLog, machine: "B", step: 1, stepName: "checkDeleteRequest" })
8
+ if (context.params.type === 'delete') {
9
+ return next('evaluateTopLevelDelete')
10
+ }
11
+ return next('evaluateTopLevelWrite')
12
+ },
13
+ evaluateTopLevelDelete: async ({
14
+ context,
15
+ endValidation,
16
+ }) => {
17
+ logMachineInfo({ enabled: context.enableLog, machine: "B", step: 2, stepName: "evaluateTopLevelDelete" })
18
+ const check = await evaluateTopLevelPermissionsFn(context, "delete")
19
+ return endValidation({ success: !!check })
20
+ },
21
+ evaluateTopLevelWrite: async ({ context, next, endValidation }) => {
22
+ logMachineInfo({ enabled: context.enableLog, machine: "B", step: 3, stepName: "evaluateTopLevelWrite" })
23
+ const check = await evaluateTopLevelPermissionsFn(context, "write")
24
+ if (check) return context.params.type === "insert" ? next('evaluateTopLevelInsert') : endValidation({ success: true })
25
+ return check === false
26
+ ? endValidation({ success: false })
27
+ : next('checkFieldsProperty')
28
+ },
29
+ checkFieldsProperty: async ({ context, goToNextValidationStage }) => {
30
+ logMachineInfo({ enabled: context.enableLog, machine: "B", step: 4, stepName: "checkFieldsProperty" })
31
+ const check = checkFieldsPropertyExists(context)
32
+ return goToNextValidationStage(
33
+ check ? 'checkIsValidFieldName' : 'checkAdditionalFields'
34
+ )
35
+ },
36
+ evaluateTopLevelInsert: async ({ context, endValidation }) => {
37
+ logMachineInfo({ enabled: context.enableLog, machine: "B", step: 5, stepName: "evaluateTopLevelInsert" })
38
+ const check = await evaluateTopLevelPermissionsFn(context, "insert")
39
+ return endValidation({ success: !!check })
40
+ }
41
+ }
42
+
43
+
@@ -0,0 +1,20 @@
1
+ import { States } from '../../interface'
2
+ import { logMachineInfo } from '../../utils'
3
+ import {
4
+ checkAdditionalFieldsFn,
5
+ checkIsValidFieldNameFn,
6
+ } from './validators'
7
+
8
+ export const STEP_C_STATES: States = {
9
+ checkAdditionalFields: async ({ context, next, endValidation }) => {
10
+ logMachineInfo({ enabled: context.enableLog, machine: "C", step: 1, stepName: "checkAdditionalFields" })
11
+ const check = checkAdditionalFieldsFn(context)
12
+ return check ? next('checkIsValidFieldName') : endValidation({ success: false })
13
+ },
14
+ checkIsValidFieldName: async ({ context, endValidation }) => {
15
+ logMachineInfo({ enabled: context.enableLog, machine: "D", step: 2, stepName: "checkIsValidFieldName" })
16
+ const document = checkIsValidFieldNameFn(context)
17
+ return endValidation({ success: !!Object.keys(document).length, document })
18
+ },
19
+ }
20
+
@@ -0,0 +1,24 @@
1
+ import { MachineContext } from "../../interface"
2
+
3
+
4
+ export const checkAdditionalFieldsFn = ({ role }: MachineContext) => {
5
+ return !!Object.keys(role.additional_fields || {}).length
6
+ }
7
+
8
+ export const checkIsValidFieldNameFn = ({ role, params }: MachineContext) => {
9
+ const { cursor } = params
10
+
11
+ const { fields = {}, additional_fields = {} } = role
12
+ const rulesOnId = !!(fields["_id"] || additional_fields["_id"])
13
+ const filteredDocument = Object.entries(cursor).reduce((filteredDocument, [key, value]) => {
14
+ if (fields![key]) {
15
+ return role.fields![key].write ? { ...filteredDocument, [key]: value } : filteredDocument
16
+ }
17
+ if (additional_fields[key]) {
18
+ return additional_fields[key]?.write ? { ...filteredDocument, [key]: value } : filteredDocument
19
+ }
20
+ return { ...filteredDocument, [key]: value }
21
+ }, {})
22
+
23
+ return (rulesOnId || cursor._id === undefined) ? filteredDocument : { ...filteredDocument, "_id": cursor._id }
24
+ }
@@ -0,0 +1,5 @@
1
+ import { STEP_A_STATES } from "./A";
2
+ import { STEP_B_STATES } from "./B";
3
+ import { STEP_C_STATES } from "./C";
4
+
5
+ export const WRITE_MACHINE = [STEP_A_STATES, STEP_B_STATES, STEP_C_STATES]
@@ -0,0 +1,365 @@
1
+ export type CheckTypeOf = (v: any) => boolean
2
+
3
+ export type CheckOperationObj = {
4
+ op: keyof Operators
5
+ value: any
6
+ opt?: any
7
+ }
8
+
9
+ export interface RulesMatcherUtils {
10
+ /**
11
+ * @param el
12
+ *
13
+ * Determines if a given value is a number.
14
+ * It checks if the value matches a numeric pattern using a regular expression.
15
+ *
16
+ * @returns
17
+ */
18
+ isNumber: <T>(el: T) => boolean
19
+ /**
20
+ * @param val
21
+ * @param data
22
+ * @param options
23
+ *
24
+ * Processes a single rule against provided data to check its validity.
25
+ * Returns a boolean indicating whether the rule is valid and a name for the rule.
26
+ *
27
+ * @returns
28
+ */
29
+ rule: (
30
+ block: Record<string, any>,
31
+ keys: Record<string, any>,
32
+ options?: Record<string, any>
33
+ ) => {
34
+ valid: boolean
35
+ name: string
36
+ }
37
+ /**
38
+ * @param block
39
+ * @param keys
40
+ * @param options
41
+ *
42
+ * Extracts keys from a rule object.
43
+ * It recursively traverses through the rule object and extracts keys while handling $and and $or logical operators.
44
+ *
45
+ * @returns
46
+ */
47
+ getKey: (
48
+ block: RulesObject<any>,
49
+ keys: Record<string, any>,
50
+ options: Record<string, any>
51
+ ) => Record<string, any>
52
+ /**
53
+ * @param v
54
+ *
55
+ * Checks if a given value is a Date object.
56
+ *
57
+ * @returns
58
+ */
59
+ isDate: CheckTypeOf
60
+ /**
61
+ * @param v
62
+ *
63
+ * Checks if a given value is defined (neither null nor undefined).
64
+ *
65
+ * @returns
66
+ */
67
+ isDefined: CheckTypeOf
68
+ /**
69
+ * @param v
70
+ *
71
+ * Checks if a given value is an object (it will return true if pass an Array).
72
+ *
73
+ * @returns
74
+ */
75
+ isObject: CheckTypeOf
76
+ /**
77
+ * @param v
78
+ *
79
+ * Checks if a given value is a function.
80
+ *
81
+ * @returns
82
+ */
83
+ isFunction: CheckTypeOf
84
+ /**
85
+ * @param v
86
+ *
87
+ * Checks if a given value is a string.
88
+ *
89
+ * @returns
90
+ */
91
+ isString: CheckTypeOf
92
+ /**
93
+ * @param value
94
+ *
95
+ * Returns the default comparison operation for a string value.
96
+ *
97
+ * @returns
98
+ */
99
+ getDefaultStringValue: (value: '$required' | '$exists' | string) => CheckOperationObj
100
+ /**
101
+ * @param value
102
+ *
103
+ * Determines the type of a given value.
104
+ *
105
+ * @returns
106
+ */
107
+ getTypeOf: (value: any) => string | null
108
+ /**
109
+ * @param value
110
+ *
111
+ * Returns the default rule configuration based on the type of the value.
112
+ *
113
+ * @returns
114
+ */
115
+ getDefaultRule: (value: any) => CheckOperationObj
116
+ /**
117
+ * @param value
118
+ *
119
+ * Checks if a value is empty.
120
+ * Handles various data types including null, undefined, functions, strings, arrays, objects, and dates.
121
+ *
122
+ * @returns
123
+ */
124
+ isEmpty: (value: any) => boolean
125
+ /**
126
+ * @param a
127
+ *
128
+ * Converts a value into an array if it is not already.
129
+ *
130
+ * @returns
131
+ */
132
+ forceArray: <T>(value: T) => Array<T>
133
+ /**
134
+ * @param path
135
+ * @param prefix
136
+ *
137
+ * Constructs a path with a prefix if provided.
138
+ * Handles special characters such as '^' and '$'.
139
+ *
140
+ * @returns
141
+ */
142
+ getPath: (path: string, prefix?: string) => string
143
+ /**
144
+ * @param el
145
+ *
146
+ * Converts a value into a number.
147
+ * Handles cases where the value might be a string representation of a number or an array.
148
+ *
149
+ * @returns
150
+ */
151
+ forceNumber: <T>(value: T) => number
152
+ /**
153
+ * @param block
154
+ * @param data
155
+ * @param options
156
+ *
157
+ * Checks if a given rule is valid against the provided data.
158
+ *
159
+ * @returns
160
+ */
161
+ checkRule: <T extends Record<string, any>>(
162
+ block: RulesObject<T>,
163
+ data: T,
164
+ options?: Record<string, any>
165
+ ) => boolean
166
+ /**
167
+ * @param rules
168
+ * @param options
169
+ *
170
+ * Extracts keys from a set of rules.
171
+ *
172
+ * @returns
173
+ */
174
+ getKeys: <T extends Record<string, any>>(
175
+ rules?: T,
176
+ options?: Record<string, any>
177
+ ) => string[] | null
178
+ }
179
+
180
+ export type OperatorsFunction = (a: any, b: any, opt?: any, data?: any) => boolean
181
+
182
+ export type Operators = {
183
+ /**
184
+ * @param a
185
+ * @param b
186
+ *
187
+ * Checks if a value exists or not.
188
+ * If the user input is not empty, it returns true if the rule value is true, otherwise false.
189
+ *
190
+ * @returns
191
+ */
192
+ $exists: OperatorsFunction
193
+ /**
194
+ * @param a
195
+ * @param b
196
+ *
197
+ * Checks if two values are equal.
198
+ *
199
+ * @returns
200
+ */
201
+ $eq: OperatorsFunction
202
+ /**
203
+ * @param a
204
+ * @param b
205
+ *
206
+ * Checks if two values are not equal.
207
+ *
208
+ * @returns
209
+ */
210
+ $ne: OperatorsFunction
211
+ /**
212
+ * @param a
213
+ * @param b
214
+ *
215
+ * Checks if the user input value is greater than the rule value after converting them both to numbers.
216
+ *
217
+ * @returns
218
+ */
219
+ $gt: OperatorsFunction
220
+ /**
221
+ * @param a
222
+ * @param b
223
+ *
224
+ * Checks if the user input value is greater than or equal to the rule value.
225
+ *
226
+ * @returns
227
+ */
228
+ $gte: OperatorsFunction
229
+ /**
230
+ * @param a
231
+ * @param b
232
+ *
233
+ * Checks if the user input value is less than the rule value.
234
+ *
235
+ * @returns
236
+ */
237
+ $lt: OperatorsFunction
238
+ /**
239
+ * @param a
240
+ * @param b
241
+ *
242
+ * Checks if the user input value is less than or equal to the rule value.
243
+ *
244
+ * @returns
245
+ */
246
+ $lte: OperatorsFunction
247
+ /**
248
+ * @param a
249
+ * @param b
250
+ *
251
+ * Compares the lengths of two strings and checks if the length of the user input string is greater than the rule value.
252
+ *
253
+ * @returns
254
+ */
255
+ $strGt: OperatorsFunction
256
+ /**
257
+ * @param a
258
+ * @param b
259
+ *
260
+ * Compares the lengths of two strings and checks if the length of the user input string is greater than or equal to the rule value.
261
+ *
262
+ * @returns
263
+ */
264
+ $strGte: OperatorsFunction
265
+ /**
266
+ * @param a
267
+ * @param b
268
+ *
269
+ * Compares the lengths of two strings and checks if the length of the user input string is less than the rule value.
270
+ *
271
+ * @returns
272
+ */
273
+ $strLt: OperatorsFunction
274
+ /**
275
+ * @param a
276
+ * @param b
277
+ *
278
+ * Compares the lengths of two strings and checks if the length of the user input string is less than or equal to the rule value.
279
+ *
280
+ * @returns
281
+ */
282
+ $strLte: OperatorsFunction
283
+
284
+ /**
285
+ * @param a
286
+ * @param b
287
+ *
288
+ * Checks if the user input value is in the array of rule values.
289
+ * It checks for intersection between the user input array and each rule value array.
290
+ *
291
+ * @returns
292
+ */
293
+ $in: OperatorsFunction
294
+ /**
295
+ * @param a
296
+ * @param b
297
+ *
298
+ * Checks if the user input value is not in the array of rule values.
299
+ * It checks for the absence of intersection between the user input array and each rule value array.
300
+ *
301
+ * @returns
302
+ */
303
+ $nin: OperatorsFunction
304
+ /**
305
+ * @param a
306
+ * @param b
307
+ *
308
+ * Checks if all elements in the user input array are present in the array of rule values.
309
+ * It checks for intersection between each element of the user input array and each rule value array.
310
+ *
311
+ * @returns
312
+ */
313
+ $all: OperatorsFunction
314
+ /**
315
+ * @param a
316
+ * @param b
317
+ * @param opt
318
+ *
319
+ * Performs a regular expression match on the user input value with the rule value(s).
320
+ * It supports either a single regular expression or an array of regular expressions.
321
+ *
322
+ * @returns
323
+ */
324
+ $regex: OperatorsFunction
325
+ }
326
+
327
+ export enum RulesOperators {
328
+ $exists = '$exists',
329
+ $eq = '$eq',
330
+ $ne = '$ne',
331
+ $gt = '$gt',
332
+ $gte = '$gte',
333
+ $lt = '$lt',
334
+ $lte = '$lte',
335
+ $strGt = '$strGt',
336
+ $strGte = '$strGte',
337
+ $strLt = '$strLt',
338
+ $strLte = '$strLte',
339
+ $in = '$in',
340
+ $nin = '$nin',
341
+ $all = '$all',
342
+ $regex = '$regex'
343
+ }
344
+
345
+ export type RulesOperatorsInArray<T> = Partial<{
346
+ [KEY in keyof T]: Partial<{
347
+ [K in keyof typeof RulesOperators]: T[KEY]
348
+ }>
349
+ }>
350
+
351
+ export type RulesValuesType<T> = { '$form.isValid'?: boolean } & T
352
+
353
+ export enum RulesModes {
354
+ $and = '$and',
355
+ $or = '$or'
356
+ }
357
+
358
+ export type RulesObject<T> =
359
+ | RulesValuesType<T>
360
+ | {
361
+ [K in keyof typeof RulesModes]:
362
+ | Array<RulesOperatorsInArray<RulesValuesType<T>>>
363
+ | Array<RulesObject<RulesValuesType<T>>>
364
+ }
365
+ | Array<Exclude<RulesOperatorsInArray<RulesValuesType<T>>, undefined>>