@ug.software/opposer 3.0.10 → 3.0.11

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 (227) hide show
  1. package/lib/bin/commands/build.js +15 -28
  2. package/lib/bin/commands/init.js +27 -30
  3. package/lib/esm/server/security/jwt/index.d.ts +1 -1
  4. package/lib/esm/server/security/jwt/index.js +21 -29
  5. package/lib/esm/system/index.d.ts +1 -1
  6. package/lib/esm/system/index.js +42 -55
  7. package/package.json +3 -3
  8. package/lib/cjs/examples/full-app/index.d.ts +0 -1
  9. package/lib/cjs/examples/full-app/index.js +0 -102
  10. package/lib/cjs/examples/full-app/models/author.d.ts +0 -7
  11. package/lib/cjs/examples/full-app/models/author.js +0 -42
  12. package/lib/cjs/examples/full-app/models/book.d.ts +0 -9
  13. package/lib/cjs/examples/full-app/models/book.js +0 -51
  14. package/lib/cjs/examples/full-app/models/category.d.ts +0 -4
  15. package/lib/cjs/examples/full-app/models/category.js +0 -26
  16. package/lib/cjs/examples/full-app/schedules/catalog-refresh.d.ts +0 -28
  17. package/lib/cjs/examples/full-app/schedules/catalog-refresh.js +0 -149
  18. package/lib/cjs/examples/full-app/schedules/inventory-sync.d.ts +0 -12
  19. package/lib/cjs/examples/full-app/schedules/inventory-sync.js +0 -61
  20. package/lib/cjs/examples/full-app/schedules/library-alerts.d.ts +0 -11
  21. package/lib/cjs/examples/full-app/schedules/library-alerts.js +0 -55
  22. package/lib/cjs/examples/minimal/src/handlers/book.d.ts +0 -11
  23. package/lib/cjs/examples/minimal/src/handlers/book.js +0 -51
  24. package/lib/cjs/examples/minimal/src/index.d.ts +0 -1
  25. package/lib/cjs/examples/minimal/src/index.js +0 -14
  26. package/lib/cjs/examples/minimal/src/models/books.d.ts +0 -4
  27. package/lib/cjs/examples/minimal/src/models/books.js +0 -26
  28. package/lib/cjs/examples/orm/models/permission.d.ts +0 -6
  29. package/lib/cjs/examples/orm/models/permission.js +0 -38
  30. package/lib/cjs/examples/orm/models/profile.d.ts +0 -7
  31. package/lib/cjs/examples/orm/models/profile.js +0 -42
  32. package/lib/cjs/examples/orm/models/user.d.ts +0 -11
  33. package/lib/cjs/examples/orm/models/user.js +0 -70
  34. package/lib/cjs/examples/orm/mysql/index.d.ts +0 -1
  35. package/lib/cjs/examples/orm/mysql/index.js +0 -44
  36. package/lib/cjs/examples/orm/postgres/index.d.ts +0 -1
  37. package/lib/cjs/examples/orm/postgres/index.js +0 -40
  38. package/lib/cjs/examples/orm/sqlite/index.d.ts +0 -1
  39. package/lib/cjs/examples/orm/sqlite/index.js +0 -41
  40. package/lib/cjs/index.d.ts +0 -2
  41. package/lib/cjs/index.js +0 -23
  42. package/lib/cjs/interfaces/controller.d.ts +0 -109
  43. package/lib/cjs/interfaces/controller.js +0 -2
  44. package/lib/cjs/interfaces/field.d.ts +0 -23
  45. package/lib/cjs/interfaces/field.js +0 -2
  46. package/lib/cjs/interfaces/handler.d.ts +0 -18
  47. package/lib/cjs/interfaces/handler.js +0 -2
  48. package/lib/cjs/interfaces/jwt.d.ts +0 -21
  49. package/lib/cjs/interfaces/jwt.js +0 -2
  50. package/lib/cjs/interfaces/model.d.ts +0 -9
  51. package/lib/cjs/interfaces/model.js +0 -2
  52. package/lib/cjs/interfaces/request.d.ts +0 -13
  53. package/lib/cjs/interfaces/request.js +0 -2
  54. package/lib/cjs/interfaces/schema.d.ts +0 -9
  55. package/lib/cjs/interfaces/schema.js +0 -2
  56. package/lib/cjs/interfaces/security.d.ts +0 -32
  57. package/lib/cjs/interfaces/security.js +0 -2
  58. package/lib/cjs/interfaces/server.d.ts +0 -37
  59. package/lib/cjs/interfaces/server.js +0 -2
  60. package/lib/cjs/interfaces/system.d.ts +0 -41
  61. package/lib/cjs/interfaces/system.js +0 -2
  62. package/lib/cjs/orm/decorators/index.d.ts +0 -33
  63. package/lib/cjs/orm/decorators/index.js +0 -131
  64. package/lib/cjs/orm/driver/mysql.d.ts +0 -14
  65. package/lib/cjs/orm/driver/mysql.js +0 -103
  66. package/lib/cjs/orm/driver/postgres.d.ts +0 -14
  67. package/lib/cjs/orm/driver/postgres.js +0 -105
  68. package/lib/cjs/orm/driver/sqlite.d.ts +0 -14
  69. package/lib/cjs/orm/driver/sqlite.js +0 -143
  70. package/lib/cjs/orm/index.d.ts +0 -8
  71. package/lib/cjs/orm/index.js +0 -28
  72. package/lib/cjs/orm/metadata.d.ts +0 -47
  73. package/lib/cjs/orm/metadata.js +0 -47
  74. package/lib/cjs/orm/opposer.d.ts +0 -30
  75. package/lib/cjs/orm/opposer.js +0 -33
  76. package/lib/cjs/orm/query-builder.d.ts +0 -32
  77. package/lib/cjs/orm/query-builder.js +0 -278
  78. package/lib/cjs/orm/repository.d.ts +0 -54
  79. package/lib/cjs/orm/repository.js +0 -325
  80. package/lib/cjs/orm/validation.d.ts +0 -44
  81. package/lib/cjs/orm/validation.js +0 -128
  82. package/lib/cjs/package.json +0 -3
  83. package/lib/cjs/persistent/cache/core-context.d.ts +0 -17
  84. package/lib/cjs/persistent/cache/core-context.js +0 -39
  85. package/lib/cjs/persistent/cache/global.d.ts +0 -18
  86. package/lib/cjs/persistent/cache/global.js +0 -22
  87. package/lib/cjs/persistent/cache/index.d.ts +0 -3
  88. package/lib/cjs/persistent/cache/index.js +0 -12
  89. package/lib/cjs/persistent/cache/session.d.ts +0 -19
  90. package/lib/cjs/persistent/cache/session.js +0 -39
  91. package/lib/cjs/persistent/cache/storage.d.ts +0 -14
  92. package/lib/cjs/persistent/cache/storage.js +0 -88
  93. package/lib/cjs/persistent/cache/store.d.ts +0 -16
  94. package/lib/cjs/persistent/cache/store.js +0 -112
  95. package/lib/cjs/persistent/context/index.d.ts +0 -3
  96. package/lib/cjs/persistent/context/index.js +0 -5
  97. package/lib/cjs/persistent/decorators/global.d.ts +0 -1
  98. package/lib/cjs/persistent/decorators/global.js +0 -25
  99. package/lib/cjs/persistent/decorators/session.d.ts +0 -1
  100. package/lib/cjs/persistent/decorators/session.js +0 -27
  101. package/lib/cjs/persistent/index.d.ts +0 -6
  102. package/lib/cjs/persistent/index.js +0 -18
  103. package/lib/cjs/persistent/interfaces/context.d.ts +0 -5
  104. package/lib/cjs/persistent/interfaces/context.js +0 -2
  105. package/lib/cjs/persistent/interfaces/system.d.ts +0 -47
  106. package/lib/cjs/persistent/interfaces/system.js +0 -29
  107. package/lib/cjs/persistent/system/index.d.ts +0 -7
  108. package/lib/cjs/persistent/system/index.js +0 -44
  109. package/lib/cjs/persistent/utils/memory.d.ts +0 -8
  110. package/lib/cjs/persistent/utils/memory.js +0 -44
  111. package/lib/cjs/persistent/utils/timer.d.ts +0 -14
  112. package/lib/cjs/persistent/utils/timer.js +0 -21
  113. package/lib/cjs/playground/build/client/assets/AddRounded-ByHfnsiW.js +0 -4
  114. package/lib/cjs/playground/build/client/assets/Button-DLrxHRm7.js +0 -1
  115. package/lib/cjs/playground/build/client/assets/Container-CgITmmbk.js +0 -1
  116. package/lib/cjs/playground/build/client/assets/Divider-B_Wx9srO.js +0 -1
  117. package/lib/cjs/playground/build/client/assets/List-juBjUmfP.js +0 -1
  118. package/lib/cjs/playground/build/client/assets/ListItemText-DgWZmgzc.js +0 -1
  119. package/lib/cjs/playground/build/client/assets/MenuItem-D_5SuVKQ.js +0 -1
  120. package/lib/cjs/playground/build/client/assets/Modal-BwXR_5Bh.js +0 -1
  121. package/lib/cjs/playground/build/client/assets/TableRow-B9hAmlnV.js +0 -2
  122. package/lib/cjs/playground/build/client/assets/TextField-UybdTIGB.js +0 -3
  123. package/lib/cjs/playground/build/client/assets/Tooltip-BGcUWUcF.js +0 -1
  124. package/lib/cjs/playground/build/client/assets/auth-CD1rXHzz.js +0 -1
  125. package/lib/cjs/playground/build/client/assets/auth-GyTIVKy5.js +0 -1
  126. package/lib/cjs/playground/build/client/assets/confirm-Dr0pbiV6.js +0 -1
  127. package/lib/cjs/playground/build/client/assets/dividerClasses-CIiqeEPO.js +0 -1
  128. package/lib/cjs/playground/build/client/assets/entry.client-D6FYz1yh.js +0 -13
  129. package/lib/cjs/playground/build/client/assets/index-CJ0wdt6Z.js +0 -1
  130. package/lib/cjs/playground/build/client/assets/index-CQc11yq_.js +0 -1153
  131. package/lib/cjs/playground/build/client/assets/index-Cr4I-4J2.js +0 -1
  132. package/lib/cjs/playground/build/client/assets/index-CtPqstFl.js +0 -26
  133. package/lib/cjs/playground/build/client/assets/index-Ct_NE85o.js +0 -1
  134. package/lib/cjs/playground/build/client/assets/index-D0I6xwmb.js +0 -1
  135. package/lib/cjs/playground/build/client/assets/index-DmDCpKb3.js +0 -1
  136. package/lib/cjs/playground/build/client/assets/index-DsSkAwyn.js +0 -1
  137. package/lib/cjs/playground/build/client/assets/index-_DMgWZ3Y.js +0 -1
  138. package/lib/cjs/playground/build/client/assets/listItemIconClasses-39Itzgzt.js +0 -1
  139. package/lib/cjs/playground/build/client/assets/listItemTextClasses-EQFLPLzt.js +0 -1
  140. package/lib/cjs/playground/build/client/assets/manifest-c06e9a7f.js +0 -1
  141. package/lib/cjs/playground/build/client/assets/mergeSlotProps-DptgQgAT.js +0 -1
  142. package/lib/cjs/playground/build/client/assets/playground-Hl52p9f5.js +0 -108
  143. package/lib/cjs/playground/build/client/assets/root-CQTBmuv8.js +0 -1
  144. package/lib/cjs/playground/build/client/assets/toast-CsAH5FIf.js +0 -1
  145. package/lib/cjs/playground/build/client/assets/use-request-BZNkzlTr.js +0 -1
  146. package/lib/cjs/playground/build/client/favicon.ico +0 -0
  147. package/lib/cjs/playground/build/client/index.html +0 -6
  148. package/lib/cjs/playground/index.d.ts +0 -2
  149. package/lib/cjs/playground/index.js +0 -135
  150. package/lib/cjs/scheduler/controllers/index.d.ts +0 -19
  151. package/lib/cjs/scheduler/controllers/index.js +0 -62
  152. package/lib/cjs/scheduler/decorators/index.d.ts +0 -9
  153. package/lib/cjs/scheduler/decorators/index.js +0 -21
  154. package/lib/cjs/scheduler/handlers/index.d.ts +0 -19
  155. package/lib/cjs/scheduler/handlers/index.js +0 -62
  156. package/lib/cjs/scheduler/index.d.ts +0 -24
  157. package/lib/cjs/scheduler/index.js +0 -110
  158. package/lib/cjs/scheduler/models/history.d.ts +0 -10
  159. package/lib/cjs/scheduler/models/history.js +0 -50
  160. package/lib/cjs/server/constants/index.d.ts +0 -78
  161. package/lib/cjs/server/constants/index.js +0 -372
  162. package/lib/cjs/server/context/index.d.ts +0 -17
  163. package/lib/cjs/server/context/index.js +0 -33
  164. package/lib/cjs/server/controller/index.d.ts +0 -3
  165. package/lib/cjs/server/controller/index.js +0 -217
  166. package/lib/cjs/server/controllers/index.d.ts +0 -5
  167. package/lib/cjs/server/controllers/index.js +0 -72
  168. package/lib/cjs/server/core/index.d.ts +0 -16
  169. package/lib/cjs/server/core/index.js +0 -110
  170. package/lib/cjs/server/core/middleware/body-parser.d.ts +0 -2
  171. package/lib/cjs/server/core/middleware/body-parser.js +0 -27
  172. package/lib/cjs/server/core/middleware/cors.d.ts +0 -4
  173. package/lib/cjs/server/core/middleware/cors.js +0 -32
  174. package/lib/cjs/server/core/middleware/logger.d.ts +0 -2
  175. package/lib/cjs/server/core/middleware/logger.js +0 -15
  176. package/lib/cjs/server/decorators/controller.d.ts +0 -3
  177. package/lib/cjs/server/decorators/controller.js +0 -14
  178. package/lib/cjs/server/decorators/field.d.ts +0 -2
  179. package/lib/cjs/server/decorators/field.js +0 -36
  180. package/lib/cjs/server/decorators/handler.d.ts +0 -3
  181. package/lib/cjs/server/decorators/handler.js +0 -14
  182. package/lib/cjs/server/decorators/index.d.ts +0 -7
  183. package/lib/cjs/server/decorators/index.js +0 -26
  184. package/lib/cjs/server/decorators/is-public-method.d.ts +0 -3
  185. package/lib/cjs/server/decorators/is-public-method.js +0 -16
  186. package/lib/cjs/server/decorators/is-public.d.ts +0 -3
  187. package/lib/cjs/server/decorators/is-public.js +0 -14
  188. package/lib/cjs/server/decorators/method.d.ts +0 -3
  189. package/lib/cjs/server/decorators/method.js +0 -16
  190. package/lib/cjs/server/decorators/payload.d.ts +0 -3
  191. package/lib/cjs/server/decorators/payload.js +0 -15
  192. package/lib/cjs/server/handlers/index.d.ts +0 -5
  193. package/lib/cjs/server/handlers/index.js +0 -72
  194. package/lib/cjs/server/helpers/index.d.ts +0 -17
  195. package/lib/cjs/server/helpers/index.js +0 -39
  196. package/lib/cjs/server/index.d.ts +0 -12
  197. package/lib/cjs/server/index.js +0 -176
  198. package/lib/cjs/server/security/controller/auth.d.ts +0 -76
  199. package/lib/cjs/server/security/controller/auth.js +0 -346
  200. package/lib/cjs/server/security/index.d.ts +0 -2
  201. package/lib/cjs/server/security/index.js +0 -10
  202. package/lib/cjs/server/security/jwt/index.d.ts +0 -23
  203. package/lib/cjs/server/security/jwt/index.js +0 -108
  204. package/lib/cjs/server/security/middleware/autorization.d.ts +0 -3
  205. package/lib/cjs/server/security/middleware/autorization.js +0 -46
  206. package/lib/cjs/server/security/middleware/permission.d.ts +0 -3
  207. package/lib/cjs/server/security/middleware/permission.js +0 -138
  208. package/lib/cjs/server/security/models/crp.d.ts +0 -8
  209. package/lib/cjs/server/security/models/crp.js +0 -42
  210. package/lib/cjs/server/security/models/ke.d.ts +0 -7
  211. package/lib/cjs/server/security/models/ke.js +0 -38
  212. package/lib/cjs/server/security/models/rl.d.ts +0 -9
  213. package/lib/cjs/server/security/models/rl.js +0 -50
  214. package/lib/cjs/server/security/models/se.d.ts +0 -11
  215. package/lib/cjs/server/security/models/se.js +0 -54
  216. package/lib/cjs/server/security/models/usr.d.ts +0 -14
  217. package/lib/cjs/server/security/models/usr.js +0 -82
  218. package/lib/cjs/server/services/delete.d.ts +0 -13
  219. package/lib/cjs/server/services/delete.js +0 -49
  220. package/lib/cjs/server/services/get.d.ts +0 -4
  221. package/lib/cjs/server/services/get.js +0 -145
  222. package/lib/cjs/server/services/insert.d.ts +0 -13
  223. package/lib/cjs/server/services/insert.js +0 -74
  224. package/lib/cjs/server/services/update.d.ts +0 -13
  225. package/lib/cjs/server/services/update.js +0 -60
  226. package/lib/cjs/system/index.d.ts +0 -13
  227. package/lib/cjs/system/index.js +0 -237
@@ -1,49 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const index_js_1 = require("../constants/index.js");
7
- const index_js_2 = require("../helpers/index.js");
8
- const index_js_3 = __importDefault(require("../../system/index.js"));
9
- const index_js_4 = require("../index.js");
10
- exports.default = async (props) => {
11
- const customModels = index_js_4.Context.get('models');
12
- const allModels = await index_js_3.default.getAllModels(customModels);
13
- const model = allModels.find((x) => x.name === props.model);
14
- const db = index_js_4.Context.get('db');
15
- if (!db) {
16
- return (0, index_js_2.Exception)({
17
- name: index_js_1.HttpStatus[500].name,
18
- code: index_js_1.HttpStatus[500].code,
19
- message: 'Database not connected.',
20
- });
21
- }
22
- if (model) {
23
- const repository = db.getRepository(model.entity);
24
- if (!props.filter || Object.keys(props.filter).length === 0) {
25
- return (0, index_js_2.Exception)({
26
- ...index_js_1.HttpStatus[400],
27
- message: 'Necessary to set query params for delete items.',
28
- });
29
- }
30
- try {
31
- await repository.delete(props.filter);
32
- return (0, index_js_2.Success)({
33
- message: 'Success removing item',
34
- });
35
- }
36
- catch (err) {
37
- return (0, index_js_2.Exception)({
38
- name: index_js_1.HttpStatus[500].name,
39
- code: index_js_1.HttpStatus[500].code,
40
- message: err.message,
41
- });
42
- }
43
- }
44
- return (0, index_js_2.Exception)({
45
- name: index_js_1.HttpStatus[400].name,
46
- code: index_js_1.HttpStatus[400].code,
47
- message: 'Unable to identify Model.',
48
- });
49
- };
@@ -1,4 +0,0 @@
1
- import { HandleGetProps } from '../../interfaces/controller.js';
2
- import { HandleRequestResult } from '../../interfaces/request.js';
3
- declare const _default: (props: HandleGetProps) => Promise<HandleRequestResult<unknown>>;
4
- export default _default;
@@ -1,145 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const index_js_1 = require("../helpers/index.js");
7
- const index_js_2 = require("../constants/index.js");
8
- const index_js_3 = __importDefault(require("../../system/index.js"));
9
- const index_js_4 = require("../index.js");
10
- exports.default = async (props) => {
11
- const customModels = index_js_4.Context.get('models');
12
- const allModels = await index_js_3.default.getAllModels(customModels);
13
- const model = allModels.find((x) => {
14
- return x.name.toLowerCase() === props.model.toLowerCase();
15
- });
16
- if (!model) {
17
- return (0, index_js_1.Exception)({
18
- name: index_js_2.HttpStatus[400].name,
19
- code: index_js_2.HttpStatus[400].code,
20
- message: 'Unable to identify Model.',
21
- });
22
- }
23
- const db = index_js_4.Context.get('db');
24
- if (!db) {
25
- return (0, index_js_1.Exception)({
26
- name: index_js_2.HttpStatus[500].name,
27
- code: index_js_2.HttpStatus[500].code,
28
- message: 'Database not connected.',
29
- });
30
- }
31
- if (!props.query) {
32
- return (0, index_js_1.Exception)({
33
- name: index_js_2.HttpStatus[400].name,
34
- code: index_js_2.HttpStatus[400].code,
35
- message: 'Search parameters missing.',
36
- });
37
- }
38
- const repository = db.getRepository(model.entity);
39
- const queryKeys = ['filter', 'find', 'count', 'exists', 'aggregate', 'distinct', 'group'];
40
- const presentKeys = queryKeys.filter((k) => {
41
- return k in props.query;
42
- });
43
- if (presentKeys.length > 1) {
44
- return (0, index_js_1.Exception)({
45
- name: index_js_2.HttpStatus[400].name,
46
- code: index_js_2.HttpStatus[400].code,
47
- message: `Conflicting search parameters: multiple types provided (${presentKeys.join(', ')}).`,
48
- });
49
- }
50
- let type = props.query.type;
51
- if (presentKeys.length === 1) {
52
- type = presentKeys[0];
53
- }
54
- if (!type) {
55
- return (0, index_js_1.Exception)({
56
- name: index_js_2.HttpStatus[400].name,
57
- code: index_js_2.HttpStatus[400].code,
58
- message: 'Search type not identified. Please provide one of: ' + queryKeys.join(', '),
59
- });
60
- }
61
- try {
62
- switch (type) {
63
- case 'filter': {
64
- const filter = props.query.filter || {};
65
- const select = props.query.select || [];
66
- const relation = props.query.relation || [];
67
- const pagination = props.pagination;
68
- const items = await repository.find({
69
- where: filter,
70
- select,
71
- relation,
72
- pagination,
73
- });
74
- if (props.pagination) {
75
- const totalItems = await repository.count(filter);
76
- const totalPages = Math.ceil(totalItems / (props.pagination.take || 10));
77
- return (0, index_js_1.Success)({
78
- items,
79
- totalItems,
80
- totalPages: totalPages > 0 ? totalPages : 0,
81
- });
82
- }
83
- return (0, index_js_1.Success)(items);
84
- }
85
- case 'find': {
86
- const find = props.query.find || {};
87
- const select = props.query.select || [];
88
- const relation = props.query.relation || [];
89
- const result = await repository.findOne({
90
- where: find,
91
- select,
92
- relation,
93
- });
94
- return (0, index_js_1.Success)(result);
95
- }
96
- case 'count': {
97
- const count = props.query.count || {};
98
- const result = await repository.count(count);
99
- return (0, index_js_1.Success)({ count: result });
100
- }
101
- case 'exists': {
102
- const exists = props.query.exists || {};
103
- const result = await repository.exists(exists);
104
- return (0, index_js_1.Success)({ exists: result });
105
- }
106
- case 'aggregate': {
107
- const aggregate = props.query.aggregate;
108
- if (!aggregate) {
109
- throw new Error('Aggregate configuration missing.');
110
- }
111
- const result = await repository.aggregate(aggregate);
112
- return (0, index_js_1.Success)(result);
113
- }
114
- case 'distinct': {
115
- const distinct = props.query.distinct;
116
- if (!distinct) {
117
- throw new Error('Distinct configuration missing.');
118
- }
119
- const result = await repository.distinct(distinct);
120
- return (0, index_js_1.Success)(result);
121
- }
122
- case 'group': {
123
- const group = props.query.group;
124
- if (!group) {
125
- throw new Error('Group configuration missing.');
126
- }
127
- const result = await repository.group(group);
128
- return (0, index_js_1.Success)(result);
129
- }
130
- default:
131
- return (0, index_js_1.Exception)({
132
- name: index_js_2.HttpStatus[400].name,
133
- code: index_js_2.HttpStatus[400].code,
134
- message: `Search type '${type}' not understood.`,
135
- });
136
- }
137
- }
138
- catch (err) {
139
- return (0, index_js_1.Exception)({
140
- name: index_js_2.HttpStatus[400].name,
141
- code: index_js_2.HttpStatus[400].code,
142
- message: err.message,
143
- });
144
- }
145
- };
@@ -1,13 +0,0 @@
1
- import { HandleInsertProps } from '../../interfaces/controller.js';
2
- declare const _default: (props: HandleInsertProps) => Promise<{
3
- readonly success: true;
4
- readonly data: any;
5
- } | {
6
- readonly success: false;
7
- readonly error: {
8
- name: string;
9
- code: number;
10
- message: any;
11
- };
12
- }>;
13
- export default _default;
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const index_js_1 = require("../helpers/index.js");
7
- const index_js_2 = require("../constants/index.js");
8
- const index_js_3 = __importDefault(require("../../system/index.js"));
9
- const index_js_4 = require("../index.js");
10
- exports.default = async (props) => {
11
- try {
12
- const customModels = index_js_4.Context.get('models');
13
- const allModels = await index_js_3.default.getAllModels(customModels);
14
- const model = allModels.find((x) => x.name === props.model);
15
- if (!model) {
16
- return (0, index_js_1.Exception)({
17
- name: index_js_2.HttpStatus[400].name,
18
- code: index_js_2.HttpStatus[400].code,
19
- message: 'Unable to identify Model',
20
- });
21
- }
22
- const db = index_js_4.Context.get('db');
23
- if (!db) {
24
- return (0, index_js_1.Exception)({
25
- name: index_js_2.HttpStatus[500].name,
26
- code: index_js_2.HttpStatus[500].code,
27
- message: 'Database not connected.',
28
- });
29
- }
30
- const repository = db.getRepository(model.entity);
31
- if (typeof props.data !== 'object') {
32
- return (0, index_js_1.Exception)({
33
- name: index_js_2.HttpStatus[400].name,
34
- code: index_js_2.HttpStatus[400].code,
35
- message: "'Data' is not of type 'object'.",
36
- });
37
- }
38
- const repositoryFields = repository.Fields.map((f) => f.name);
39
- const checkDataProperties = (data) => {
40
- return Object.keys(data).every((key) => repositoryFields.includes(key) || key === 'id');
41
- };
42
- if (Array.isArray(props.data)) {
43
- for (const item of props.data) {
44
- if (!checkDataProperties(item)) {
45
- return (0, index_js_1.Exception)({
46
- name: index_js_2.HttpStatus[400].name,
47
- code: index_js_2.HttpStatus[400].code,
48
- message: 'Some data properties are outside the expected range.',
49
- });
50
- }
51
- }
52
- const results = await Promise.all(props.data.map((item) => repository.insert(item)));
53
- return (0, index_js_1.Success)(results);
54
- }
55
- else {
56
- if (!checkDataProperties(props.data)) {
57
- return (0, index_js_1.Exception)({
58
- name: index_js_2.HttpStatus[400].name,
59
- code: index_js_2.HttpStatus[400].code,
60
- message: "'Data' outside of expected range.",
61
- });
62
- }
63
- const result = await repository.insert(props.data);
64
- return (0, index_js_1.Success)(result);
65
- }
66
- }
67
- catch (err) {
68
- return (0, index_js_1.Exception)({
69
- name: index_js_2.HttpStatus[500].name,
70
- code: index_js_2.HttpStatus[500].code,
71
- message: err.message,
72
- });
73
- }
74
- };
@@ -1,13 +0,0 @@
1
- import { HandleUpdateProps } from '../../interfaces/controller.js';
2
- declare const _default: (props: HandleUpdateProps) => Promise<{
3
- readonly success: true;
4
- readonly data: any;
5
- } | {
6
- readonly success: false;
7
- readonly error: {
8
- name: string;
9
- code: number;
10
- message: any;
11
- };
12
- }>;
13
- export default _default;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const index_js_1 = require("../helpers/index.js");
7
- const index_js_2 = require("../constants/index.js");
8
- const index_js_3 = __importDefault(require("../../system/index.js"));
9
- const index_js_4 = require("../index.js");
10
- exports.default = async (props) => {
11
- const customModels = index_js_4.Context.get('models');
12
- const allModels = await index_js_3.default.getAllModels(customModels);
13
- const model = allModels.find((x) => x.name === props.model);
14
- if (!model) {
15
- return (0, index_js_1.Exception)({
16
- name: index_js_2.HttpStatus[400].name,
17
- code: index_js_2.HttpStatus[400].code,
18
- message: 'Unable to identify Model',
19
- });
20
- }
21
- const db = index_js_4.Context.get('db');
22
- if (!db) {
23
- return (0, index_js_1.Exception)({
24
- name: index_js_2.HttpStatus[500].name,
25
- code: index_js_2.HttpStatus[500].code,
26
- message: 'Database not connected.',
27
- });
28
- }
29
- const repository = db.getRepository(model.entity);
30
- const repositoryFields = repository.Fields.map((f) => f.name);
31
- const thereIsPropertyOutsideTheRule = Object.keys(props.data).some((key) => {
32
- return !repositoryFields.includes(key) && key !== 'id';
33
- });
34
- if (thereIsPropertyOutsideTheRule) {
35
- return (0, index_js_1.Exception)({
36
- name: index_js_2.HttpStatus[400].name,
37
- code: index_js_2.HttpStatus[400].code,
38
- message: "'Data' out of expected range, check your data and try again",
39
- });
40
- }
41
- if (!props.filter || Object.keys(props.filter).length === 0) {
42
- return (0, index_js_1.Exception)({
43
- ...index_js_2.HttpStatus[400],
44
- message: 'Necessary to set query params for update items.',
45
- });
46
- }
47
- try {
48
- await repository.update(props.filter, props.data);
49
- return (0, index_js_1.Success)({
50
- message: 'Success updating item',
51
- });
52
- }
53
- catch (err) {
54
- return (0, index_js_1.Exception)({
55
- name: index_js_2.HttpStatus[500].name,
56
- code: index_js_2.HttpStatus[500].code,
57
- message: err.message,
58
- });
59
- }
60
- };
@@ -1,13 +0,0 @@
1
- import { OpposerSystemConfigOptions, ClassType, ModelDefinition } from "../interfaces/system.js";
2
- export declare class OpposerSystem {
3
- getFileName(filePath: string, withExtension?: boolean): string;
4
- getAllModels(customModels?: string | ClassType<unknown>[]): Promise<ModelDefinition[]>;
5
- private getAuthModels;
6
- getAllControllers(customControllers?: string | ClassType<unknown>[]): Promise<ClassType<unknown>[]>;
7
- getAllSchedules(customSchedules?: string | ClassType<unknown>[]): Promise<ClassType<unknown>[]>;
8
- getSettingsFile(): OpposerSystemConfigOptions;
9
- getAllFiles(dir: string): string[];
10
- saveSettingsFile(settings: OpposerSystemConfigOptions): void;
11
- }
12
- declare const system: OpposerSystem;
13
- export default system;
@@ -1,237 +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 () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.OpposerSystem = void 0;
40
- const url_1 = require("url");
41
- const path_1 = __importDefault(require("path"));
42
- const fs_1 = __importDefault(require("fs"));
43
- const crp_js_1 = __importDefault(require("../server/security/models/crp.js"));
44
- const ke_js_1 = __importDefault(require("../server/security/models/ke.js"));
45
- const rl_js_1 = __importDefault(require("../server/security/models/rl.js"));
46
- const se_js_1 = __importDefault(require("../server/security/models/se.js"));
47
- const usr_js_1 = __importDefault(require("../server/security/models/usr.js"));
48
- const history_js_1 = __importDefault(require("../scheduler/models/history.js"));
49
- const metadata_js_1 = require("../orm/metadata.js");
50
- class OpposerSystem {
51
- getFileName(filePath, withExtension = true) {
52
- if (withExtension) {
53
- return path_1.default.basename(filePath);
54
- }
55
- else {
56
- return path_1.default.basename(filePath, path_1.default.extname(filePath));
57
- }
58
- }
59
- async getAllModels(customModels) {
60
- const settings = this.getSettingsFile();
61
- const root = process.cwd();
62
- if (typeof customModels === "string") {
63
- const modelsPath = path_1.default.resolve(root, customModels);
64
- if (fs_1.default.existsSync(modelsPath)) {
65
- const modelsFiles = this.getAllFiles(modelsPath);
66
- await Promise.all(modelsFiles.map(async (filePath) => {
67
- const fileUrl = (0, url_1.pathToFileURL)(filePath).href;
68
- return await Promise.resolve(`${fileUrl}`).then(s => __importStar(require(s)));
69
- }));
70
- }
71
- }
72
- else if (Array.isArray(customModels)) {
73
- // If models are passed as an array, they are already imported/defined.
74
- // We don't need to do anything here as they should have registered themselves
75
- // via decorators if they are in the array.
76
- }
77
- const allEntities = metadata_js_1.MetadataStore.getAllEntities();
78
- const authModels = this.getAuthModels(settings);
79
- const models = allEntities.map((meta) => ({
80
- name: meta.name,
81
- entity: meta.target,
82
- }));
83
- // Combine with auth models if they aren't already there
84
- authModels.forEach((auth) => {
85
- if (!models.find((m) => m.name === auth.name)) {
86
- models.push(auth);
87
- }
88
- });
89
- return models;
90
- }
91
- getAuthModels(settings) {
92
- const models = [];
93
- if (settings.auth) {
94
- models.push({ name: "crp", entity: crp_js_1.default }, { name: "ke", entity: ke_js_1.default }, { name: "rl", entity: rl_js_1.default }, { name: "se", entity: se_js_1.default }, { name: "usr", entity: usr_js_1.default });
95
- }
96
- // Always include ScheduleHistory as it's a core feature
97
- models.push({ name: "sh", entity: history_js_1.default });
98
- return models;
99
- }
100
- async getAllControllers(customControllers) {
101
- const settings = this.getSettingsFile();
102
- const root = process.cwd();
103
- // Dynamic import to avoid circular dependency
104
- const SchedulerController = (await Promise.resolve().then(() => __importStar(require("../scheduler/controllers/index.js")))).default;
105
- const internalControllers = [SchedulerController];
106
- if (Array.isArray(customControllers)) {
107
- return [...internalControllers, ...customControllers];
108
- }
109
- let controllersPath = customControllers || path_1.default.resolve(root, "src", "controllers");
110
- if (!customControllers && settings.controllers) {
111
- controllersPath = path_1.default.resolve(root, settings.controllers, "controllers");
112
- }
113
- if (!fs_1.default.existsSync(controllersPath)) {
114
- return internalControllers;
115
- }
116
- const controllersFiles = this.getAllFiles(controllersPath);
117
- const userControllers = await Promise.all(controllersFiles.map(async (filePath) => {
118
- const fileUrl = (0, url_1.pathToFileURL)(filePath).href;
119
- //@ts-ignore
120
- return (await Promise.resolve(`${fileUrl}`).then(s => __importStar(require(s)))).default;
121
- }));
122
- return [...internalControllers, ...userControllers.filter((h) => h)];
123
- }
124
- async getAllSchedules(customSchedules) {
125
- const settings = this.getSettingsFile();
126
- const root = process.cwd();
127
- if (Array.isArray(customSchedules)) {
128
- return customSchedules;
129
- }
130
- let schedulesPath = customSchedules || path_1.default.resolve(root, "src", "schedules");
131
- if (!customSchedules && settings.schedules) {
132
- schedulesPath = path_1.default.resolve(root, settings.schedules, "schedules");
133
- }
134
- if (!fs_1.default.existsSync(schedulesPath)) {
135
- return [];
136
- }
137
- const schedulesFiles = this.getAllFiles(schedulesPath);
138
- const userSchedules = await Promise.all(schedulesFiles.map(async (filePath) => {
139
- const fileUrl = (0, url_1.pathToFileURL)(filePath).href;
140
- //@ts-ignore
141
- return (await Promise.resolve(`${fileUrl}`).then(s => __importStar(require(s)))).default;
142
- }));
143
- return userSchedules.filter((s) => s);
144
- }
145
- getSettingsFile() {
146
- let config = {};
147
- try {
148
- const root = process.cwd();
149
- const configPath = path_1.default.resolve(root, "opposer-settings.json");
150
- if (fs_1.default.existsSync(configPath)) {
151
- const fileContent = fs_1.default.readFileSync(configPath, "utf8");
152
- config = JSON.parse(fileContent);
153
- }
154
- }
155
- catch (error) {
156
- // Normal if file doesn't exist
157
- }
158
- // Override with Environment Variables
159
- config.port = process.env.OPPOSER_PORT
160
- ? parseInt(process.env.OPPOSER_PORT)
161
- : config.port || 3000;
162
- config.url = process.env.OPPOSER_URL || config.url;
163
- if (process.env.OPPOSER_DATABASE_TYPE || config.database) {
164
- config.database = {
165
- ...config.database,
166
- type: process.env.OPPOSER_DATABASE_TYPE ||
167
- config.database?.type,
168
- host: process.env.OPPOSER_DATABASE_HOST || config.database?.host,
169
- port: process.env.OPPOSER_DATABASE_PORT
170
- ? parseInt(process.env.OPPOSER_DATABASE_PORT)
171
- : config.database?.port,
172
- username: process.env.OPPOSER_DATABASE_USER ||
173
- config.database?.username,
174
- password: process.env.OPPOSER_DATABASE_PASSWORD ||
175
- config.database?.password,
176
- database: process.env.OPPOSER_DATABASE_NAME || config.database?.database,
177
- logging: process.env.OPPOSER_DATABASE_LOGGING === "true" || config.database?.logging,
178
- };
179
- }
180
- if (process.env.OPPOSER_JWT_ACCESS || config.jwt) {
181
- config.jwt = {
182
- ...(config.jwt || { access: "", refresh: "", recover: "" }),
183
- access: process.env.OPPOSER_JWT_ACCESS || config.jwt?.access || "",
184
- refresh: process.env.OPPOSER_JWT_REFRESH || config.jwt?.refresh || "",
185
- recover: process.env.OPPOSER_JWT_RECOVER || config.jwt?.recover || "",
186
- };
187
- }
188
- if (process.env.OPPOSER_MANAGER_LOGIN || config.manager) {
189
- config.manager = {
190
- ...(config.manager || {
191
- login: "",
192
- password: "",
193
- firstName: "",
194
- lastName: "",
195
- }),
196
- login: process.env.OPPOSER_MANAGER_LOGIN || config.manager?.login || "",
197
- password: process.env.OPPOSER_MANAGER_PASSWORD ||
198
- config.manager?.password ||
199
- "",
200
- firstName: process.env.OPPOSER_MANAGER_FIRST_NAME ||
201
- config.manager?.firstName ||
202
- "",
203
- lastName: process.env.OPPOSER_MANAGER_LAST_NAME ||
204
- config.manager?.lastName ||
205
- "",
206
- };
207
- }
208
- return config;
209
- }
210
- getAllFiles(dir) {
211
- let results = [];
212
- if (!fs_1.default.existsSync(dir))
213
- return [];
214
- const list = fs_1.default.readdirSync(dir, { withFileTypes: true });
215
- list.forEach((file) => {
216
- const filePath = path_1.default.resolve(dir, file.name);
217
- if (file.isDirectory()) {
218
- results = results.concat(this.getAllFiles(filePath));
219
- }
220
- else if (file.isFile() &&
221
- (file.name.endsWith(".js") || file.name.endsWith(".ts"))) {
222
- results.push(filePath);
223
- }
224
- });
225
- return results;
226
- }
227
- saveSettingsFile(settings) {
228
- const root = process.cwd();
229
- const configPath = path_1.default.resolve(root, "opposer-settings.json");
230
- return fs_1.default.writeFileSync(configPath, JSON.stringify(settings, null, 2), {
231
- encoding: "utf8",
232
- });
233
- }
234
- }
235
- exports.OpposerSystem = OpposerSystem;
236
- const system = new OpposerSystem();
237
- exports.default = system;