@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,135 +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
- exports.default = Playground;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const url_1 = require("url");
10
- const index_js_1 = __importDefault(require("../system/index.js"));
11
- const index_js_2 = require("../server/decorators/index.js");
12
- const index_js_3 = require("../orm/index.js");
13
- const index_js_4 = require("../server/index.js");
14
- // @ts-ignore
15
- const _dirname = typeof __dirname !== 'undefined'
16
- ? __dirname
17
- : // @ts-ignore
18
- path_1.default.dirname((0, url_1.fileURLToPath)(import.meta.url));
19
- async function generateMap(server, models, controllers) {
20
- var map = {
21
- models: {},
22
- controllers: {},
23
- };
24
- var allModels = await index_js_1.default.getAllModels(models);
25
- const internalModels = ['usr', 'rl', 'se', 'ke', 'crp', 'sh', 'User', 'Role', 'Session', 'Key', 'ChangeRequestPassword', 'ScheduleHistory'];
26
- if (Array.isArray(allModels)) {
27
- var modelsMap = allModels
28
- .filter((m) => !internalModels.includes(m.name))
29
- .reduce((__models, m) => {
30
- var fields = (0, index_js_2.getFieldsMetadata)(m.entity);
31
- const meta = index_js_3.MetadataStore.getEntity(m.entity);
32
- if (Array.isArray(fields)) {
33
- var model = fields.reduce((__model, field) => {
34
- __model[field.name] = field.model?.type || 'string';
35
- return __model;
36
- }, {});
37
- __models[m.name] = {
38
- description: meta?.description || 'Database Entity Definition',
39
- model: model,
40
- };
41
- }
42
- return __models;
43
- }, {});
44
- map.models = modelsMap;
45
- }
46
- var allControllers = await index_js_1.default.getAllControllers(controllers);
47
- if (Array.isArray(allControllers)) {
48
- var controllersMap = allControllers.reduce((__controllers, controller) => {
49
- var controllerMetadata = (0, index_js_2.getControllerMetadata)(controller);
50
- var allMethods = (0, index_js_2.getMethodMetadata)(controller);
51
- var allPayloads = (0, index_js_2.getPayloadMetadata)(controller);
52
- if (Array.isArray(allMethods)) {
53
- var methods = allMethods.reduce((__methods, method) => {
54
- var payload = allPayloads.find((x) => x.name === method.name);
55
- if (payload) {
56
- var fields = (0, index_js_2.getFieldsMetadata)(payload.dto);
57
- if (Array.isArray(fields)) {
58
- __methods[method.name] = {
59
- payload: fields.reduce((__fields, field) => {
60
- __fields[field.name] = field.model?.type || 'string';
61
- return __fields;
62
- }, {}),
63
- };
64
- }
65
- }
66
- return __methods;
67
- }, {});
68
- __controllers[controllerMetadata.name] = methods;
69
- }
70
- return __controllers;
71
- }, {});
72
- map.controllers = controllersMap;
73
- const mapPath = path_1.default.resolve(process.cwd(), 'opposer-map.json');
74
- fs_1.default.writeFileSync(mapPath, JSON.stringify(map, null, 2));
75
- return map;
76
- }
77
- return map;
78
- }
79
- const MIME_TYPES = {
80
- '.html': 'text/html',
81
- '.js': 'text/javascript',
82
- '.css': 'text/css',
83
- '.json': 'application/json',
84
- '.png': 'image/png',
85
- '.jpg': 'image/jpeg',
86
- '.gif': 'image/gif',
87
- '.svg': 'image/svg+xml',
88
- '.ico': 'image/x-icon',
89
- };
90
- async function Playground(req, res, next) {
91
- const server = req.server;
92
- const models = index_js_4.Context.get('models');
93
- const controllers = index_js_4.Context.get('controllers');
94
- // Public map endpoint for the Swagger UI
95
- if (req.url === '/opposer-map.json') {
96
- const map = await generateMap(server, models, controllers);
97
- res.status(200).json(map);
98
- return;
99
- }
100
- // Base playground route - Serve static files from build/client
101
- if (req.url.startsWith('/playground')) {
102
- await generateMap(server, models, controllers);
103
- const _buildPath = path_1.default.resolve(_dirname, 'build', 'client');
104
- let relativePath = req.url.replace('/playground', '');
105
- if (relativePath === '' || relativePath === '/') {
106
- relativePath = '/index.html';
107
- }
108
- let filePath = path_1.default.join(_buildPath, relativePath);
109
- // If file doesn't exist, fallback to index.html only if it's a likely page request
110
- if (!fs_1.default.existsSync(filePath) || fs_1.default.statSync(filePath).isDirectory()) {
111
- const isAsset = /\.(js|css|png|jpg|gif|svg|ico|json|map)$/.test(relativePath);
112
- if (!isAsset) {
113
- filePath = path_1.default.join(_buildPath, 'index.html');
114
- }
115
- else {
116
- res.status(404).json({ message: `Asset ${relativePath} not found.` });
117
- return;
118
- }
119
- }
120
- const ext = path_1.default.extname(filePath).toLowerCase();
121
- const contentType = MIME_TYPES[ext] || 'application/octet-stream';
122
- try {
123
- console.log('filePath', filePath);
124
- const content = fs_1.default.readFileSync(filePath);
125
- res.setHeader('Content-Type', contentType);
126
- res.status(200).end(content);
127
- }
128
- catch (error) {
129
- console.log('error', error);
130
- res.status(500).json({ message: 'Error serving playground file.' });
131
- }
132
- return;
133
- }
134
- next();
135
- }
@@ -1,19 +0,0 @@
1
- import { PayloadRequest } from '../../interfaces/controller.js';
2
- export default class SchedulerController {
3
- private get db();
4
- listTasks(): Promise<{
5
- readonly success: true;
6
- readonly data: any;
7
- }>;
8
- getHistory(): Promise<{
9
- readonly success: true;
10
- readonly data: any;
11
- }>;
12
- runTask(payload: PayloadRequest<{
13
- name: string;
14
- data?: any;
15
- }>): Promise<{
16
- readonly success: true;
17
- readonly data: any;
18
- }>;
19
- }
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const index_js_1 = require("../../server/decorators/index.js");
16
- const index_js_2 = require("../../server/helpers/index.js");
17
- const index_js_3 = __importDefault(require("../index.js"));
18
- const history_js_1 = __importDefault(require("../models/history.js"));
19
- const index_js_4 = require("../../server/index.js");
20
- let SchedulerController = class SchedulerController {
21
- get db() {
22
- return index_js_4.Context.get('db');
23
- }
24
- async listTasks() {
25
- return (0, index_js_2.Success)(index_js_3.default.getTasks());
26
- }
27
- async getHistory() {
28
- const historyRepo = this.db.getRepository(history_js_1.default);
29
- const history = await historyRepo.find({
30
- pagination: { page: 0, take: 50 }, // Last 50 runs
31
- });
32
- const sortedHistory = history.sort((a, b) => new Date(b.st).getTime() - new Date(a.st).getTime());
33
- return (0, index_js_2.Success)(sortedHistory);
34
- }
35
- async runTask(payload) {
36
- const { name, data } = payload.data;
37
- const result = await index_js_3.default.runTask(name, data);
38
- return (0, index_js_2.Success)(result);
39
- }
40
- };
41
- __decorate([
42
- (0, index_js_1.Method)(),
43
- __metadata("design:type", Function),
44
- __metadata("design:paramtypes", []),
45
- __metadata("design:returntype", Promise)
46
- ], SchedulerController.prototype, "listTasks", null);
47
- __decorate([
48
- (0, index_js_1.Method)(),
49
- __metadata("design:type", Function),
50
- __metadata("design:paramtypes", []),
51
- __metadata("design:returntype", Promise)
52
- ], SchedulerController.prototype, "getHistory", null);
53
- __decorate([
54
- (0, index_js_1.Method)(),
55
- __metadata("design:type", Function),
56
- __metadata("design:paramtypes", [Object]),
57
- __metadata("design:returntype", Promise)
58
- ], SchedulerController.prototype, "runTask", null);
59
- SchedulerController = __decorate([
60
- (0, index_js_1.Controller)('scheduler')
61
- ], SchedulerController);
62
- exports.default = SchedulerController;
@@ -1,9 +0,0 @@
1
- import "reflect-metadata";
2
- export declare const SCHEDULE_METADATA_KEY: unique symbol;
3
- export interface ScheduleOptions {
4
- name: string;
5
- interval: number;
6
- enabled?: boolean;
7
- }
8
- export declare function Schedule(options: ScheduleOptions): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
9
- export declare function getScheduleMetadata(target: any): any;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SCHEDULE_METADATA_KEY = void 0;
4
- exports.Schedule = Schedule;
5
- exports.getScheduleMetadata = getScheduleMetadata;
6
- require("reflect-metadata");
7
- exports.SCHEDULE_METADATA_KEY = Symbol("opposer:schedule");
8
- function Schedule(options) {
9
- return (target, propertyKey, descriptor) => {
10
- const schedules = Reflect.getMetadata(exports.SCHEDULE_METADATA_KEY, target.constructor) || [];
11
- schedules.push({
12
- ...options,
13
- propertyKey,
14
- enabled: options.enabled !== false,
15
- });
16
- Reflect.defineMetadata(exports.SCHEDULE_METADATA_KEY, schedules, target.constructor);
17
- };
18
- }
19
- function getScheduleMetadata(target) {
20
- return Reflect.getMetadata(exports.SCHEDULE_METADATA_KEY, target) || [];
21
- }
@@ -1,19 +0,0 @@
1
- import { PayloadRequest } from '../../interfaces/controller.js';
2
- export default class SchedulerHandler {
3
- private get db();
4
- listTasks(): Promise<{
5
- readonly success: true;
6
- readonly data: any;
7
- }>;
8
- getHistory(): Promise<{
9
- readonly success: true;
10
- readonly data: any;
11
- }>;
12
- runTask(payload: PayloadRequest<{
13
- name: string;
14
- data?: any;
15
- }>): Promise<{
16
- readonly success: true;
17
- readonly data: any;
18
- }>;
19
- }
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const index_js_1 = require("../../server/decorators/index.js");
16
- const index_js_2 = require("../../server/helpers/index.js");
17
- const index_js_3 = __importDefault(require("../index.js"));
18
- const history_js_1 = __importDefault(require("../models/history.js"));
19
- const index_js_4 = require("../../server/index.js");
20
- let SchedulerHandler = class SchedulerHandler {
21
- get db() {
22
- return index_js_4.Context.get('db');
23
- }
24
- async listTasks() {
25
- return (0, index_js_2.Success)(index_js_3.default.getTasks());
26
- }
27
- async getHistory() {
28
- const historyRepo = this.db.getRepository(history_js_1.default);
29
- const history = await historyRepo.find({
30
- pagination: { page: 0, take: 50 }, // Last 50 runs
31
- });
32
- const sortedHistory = history.sort((a, b) => new Date(b.st).getTime() - new Date(a.st).getTime());
33
- return (0, index_js_2.Success)(sortedHistory);
34
- }
35
- async runTask(payload) {
36
- const { name, data } = payload.data;
37
- const result = await index_js_3.default.runTask(name, data);
38
- return (0, index_js_2.Success)(result);
39
- }
40
- };
41
- __decorate([
42
- (0, index_js_1.Method)(),
43
- __metadata("design:type", Function),
44
- __metadata("design:paramtypes", []),
45
- __metadata("design:returntype", Promise)
46
- ], SchedulerHandler.prototype, "listTasks", null);
47
- __decorate([
48
- (0, index_js_1.Method)(),
49
- __metadata("design:type", Function),
50
- __metadata("design:paramtypes", []),
51
- __metadata("design:returntype", Promise)
52
- ], SchedulerHandler.prototype, "getHistory", null);
53
- __decorate([
54
- (0, index_js_1.Method)(),
55
- __metadata("design:type", Function),
56
- __metadata("design:paramtypes", [Object]),
57
- __metadata("design:returntype", Promise)
58
- ], SchedulerHandler.prototype, "runTask", null);
59
- SchedulerHandler = __decorate([
60
- (0, index_js_1.Controller)('scheduler')
61
- ], SchedulerHandler);
62
- exports.default = SchedulerHandler;
@@ -1,24 +0,0 @@
1
- import { ClassType } from "../interfaces/system.js";
2
- export * from "./decorators/index.js";
3
- export interface RegisteredTask {
4
- name: string;
5
- interval: number;
6
- propertyKey: string;
7
- target: any;
8
- instance: any;
9
- timer?: NodeJS.Timeout;
10
- }
11
- export declare class Scheduler {
12
- private tasks;
13
- private get db();
14
- initialize(customSchedules?: string | ClassType<unknown>[]): Promise<void>;
15
- start(): void;
16
- runTask(name: string, data?: any): Promise<any>;
17
- getTasks(): {
18
- name: string;
19
- interval: number;
20
- enabled: boolean;
21
- }[];
22
- }
23
- declare const _default: Scheduler;
24
- export default _default;
@@ -1,110 +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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.Scheduler = void 0;
21
- const index_js_1 = __importDefault(require("../system/index.js"));
22
- const index_js_2 = require("./decorators/index.js");
23
- const history_js_1 = __importDefault(require("./models/history.js"));
24
- const crypto_1 = require("crypto");
25
- const index_js_3 = __importDefault(require("../server/context/index.js"));
26
- __exportStar(require("./decorators/index.js"), exports);
27
- class Scheduler {
28
- constructor() {
29
- this.tasks = new Map();
30
- }
31
- get db() {
32
- return index_js_3.default.get("db");
33
- }
34
- async initialize(customSchedules) {
35
- const schedules = await index_js_1.default.getAllSchedules(customSchedules);
36
- for (const TargetClass of schedules) {
37
- if (TargetClass && typeof TargetClass === "function") {
38
- const metadata = (0, index_js_2.getScheduleMetadata)(TargetClass);
39
- if (metadata.length > 0) {
40
- const instance = new TargetClass();
41
- for (const taskOptions of metadata) {
42
- if (taskOptions.enabled) {
43
- this.tasks.set(taskOptions.name, {
44
- ...taskOptions,
45
- target: TargetClass,
46
- instance,
47
- });
48
- console.log(`[scheduler] Registered task: ${taskOptions.name} (${taskOptions.interval}ms)`);
49
- }
50
- }
51
- }
52
- }
53
- }
54
- }
55
- start() {
56
- for (const [name, task] of this.tasks.entries()) {
57
- task.timer = setInterval(() => {
58
- this.runTask(name).catch((err) => console.error(`[scheduler] Error in task ${name}:`, err));
59
- }, task.interval);
60
- }
61
- console.log("[scheduler] All tasks started.");
62
- }
63
- async runTask(name, data) {
64
- const task = this.tasks.get(name);
65
- if (!task) {
66
- throw new Error(`Task ${name} not found.`);
67
- }
68
- const historyRepo = this.db.getRepository(history_js_1.default);
69
- const startTime = new Date();
70
- const historyId = (0, crypto_1.randomUUID)();
71
- // Create initial history record
72
- await historyRepo.insert({
73
- id: historyId,
74
- nm: name,
75
- st: startTime,
76
- sc: false,
77
- });
78
- try {
79
- const result = await task.instance[task.propertyKey](data);
80
- const endTime = new Date();
81
- const duration = endTime.getTime() - startTime.getTime();
82
- await historyRepo.update({ id: historyId }, {
83
- ft: endTime,
84
- sc: true,
85
- du: duration,
86
- });
87
- return result;
88
- }
89
- catch (error) {
90
- const endTime = new Date();
91
- const duration = endTime.getTime() - startTime.getTime();
92
- await historyRepo.update({ id: historyId }, {
93
- ft: endTime,
94
- sc: false,
95
- er: error.message || String(error),
96
- du: duration,
97
- });
98
- throw error;
99
- }
100
- }
101
- getTasks() {
102
- return Array.from(this.tasks.values()).map((t) => ({
103
- name: t.name,
104
- interval: t.interval,
105
- enabled: true,
106
- }));
107
- }
108
- }
109
- exports.Scheduler = Scheduler;
110
- exports.default = new Scheduler();
@@ -1,10 +0,0 @@
1
- export default class ScheduleHistory {
2
- id: string;
3
- nm: string;
4
- st: Date;
5
- ft?: Date;
6
- sc: boolean;
7
- er?: string;
8
- du?: number;
9
- ct: Date;
10
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const index_js_1 = require("../../orm/index.js");
13
- let ScheduleHistory = class ScheduleHistory {
14
- };
15
- __decorate([
16
- (0, index_js_1.PrimaryColumn)({ type: "uuid" }),
17
- __metadata("design:type", String)
18
- ], ScheduleHistory.prototype, "id", void 0);
19
- __decorate([
20
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("name is string.").required("name is required.")),
21
- __metadata("design:type", String)
22
- ], ScheduleHistory.prototype, "nm", void 0);
23
- __decorate([
24
- (0, index_js_1.Field)(() => (0, index_js_1.f)().date("started at is date.").required("started at is required.")),
25
- __metadata("design:type", Date)
26
- ], ScheduleHistory.prototype, "st", void 0);
27
- __decorate([
28
- (0, index_js_1.Field)(() => (0, index_js_1.f)().date("finished at is date.")),
29
- __metadata("design:type", Date)
30
- ], ScheduleHistory.prototype, "ft", void 0);
31
- __decorate([
32
- (0, index_js_1.Field)(() => (0, index_js_1.f)().boolean("success is boolean.")),
33
- __metadata("design:type", Boolean)
34
- ], ScheduleHistory.prototype, "sc", void 0);
35
- __decorate([
36
- (0, index_js_1.Field)(() => (0, index_js_1.f)().string("error is string.")),
37
- __metadata("design:type", String)
38
- ], ScheduleHistory.prototype, "er", void 0);
39
- __decorate([
40
- (0, index_js_1.Field)(() => (0, index_js_1.f)().number("duration is number.")),
41
- __metadata("design:type", Number)
42
- ], ScheduleHistory.prototype, "du", void 0);
43
- __decorate([
44
- (0, index_js_1.CreateDateColumn)(),
45
- __metadata("design:type", Date)
46
- ], ScheduleHistory.prototype, "ct", void 0);
47
- ScheduleHistory = __decorate([
48
- (0, index_js_1.Entity)("sh")
49
- ], ScheduleHistory);
50
- exports.default = ScheduleHistory;
@@ -1,78 +0,0 @@
1
- export declare enum HttpStatusCode {
2
- Continue = 100,
3
- SwitchingProtocols = 101,
4
- Processing = 102,
5
- EarlyHints = 103,
6
- OK = 200,
7
- Created = 201,
8
- Accepted = 202,
9
- NonAuthoritativeInformation = 203,
10
- NoContent = 204,
11
- ResetContent = 205,
12
- PartialContent = 206,
13
- MultiStatus = 207,
14
- AlreadyReported = 208,
15
- IMUsed = 226,
16
- MultipleChoices = 300,
17
- MovedPermanently = 301,
18
- Found = 302,
19
- SeeOther = 303,
20
- NotModified = 304,
21
- UseProxy = 305,
22
- TemporaryRedirect = 307,
23
- PermanentRedirect = 308,
24
- BadRequest = 400,
25
- Unauthorized = 401,
26
- PaymentRequired = 402,
27
- Forbidden = 403,
28
- NotFound = 404,
29
- MethodNotAllowed = 405,
30
- NotAcceptable = 406,
31
- ProxyAuthenticationRequired = 407,
32
- RequestTimeout = 408,
33
- Conflict = 409,
34
- Gone = 410,
35
- LengthRequired = 411,
36
- PreconditionFailed = 412,
37
- PayloadTooLarge = 413,
38
- URITooLong = 414,
39
- UnsupportedMediaType = 415,
40
- RangeNotSatisfiable = 416,
41
- ExpectationFailed = 417,
42
- ImATeapot = 418,
43
- MisdirectedRequest = 421,
44
- UnprocessableEntity = 422,
45
- Locked = 423,
46
- FailedDependency = 424,
47
- TooEarly = 425,
48
- UpgradeRequired = 426,
49
- PreconditionRequired = 428,
50
- TooManyRequests = 429,
51
- RequestHeaderFieldsTooLarge = 431,
52
- UnavailableForLegalReasons = 451,
53
- InternalServerError = 500,
54
- NotImplemented = 501,
55
- BadGateway = 502,
56
- ServiceUnavailable = 503,
57
- GatewayTimeout = 504,
58
- HTTPVersionNotSupported = 505,
59
- VariantAlsoNegotiates = 506,
60
- InsufficientStorage = 507,
61
- LoopDetected = 508,
62
- NotExtended = 510,
63
- NetworkAuthenticationRequired = 511
64
- }
65
- export declare const HttpStatus: Record<HttpStatusCode, {
66
- code: number;
67
- name: string;
68
- category: string;
69
- }>;
70
- export declare enum Type {
71
- string = "string",
72
- number = "number",
73
- jsonb = "jsonb",
74
- boolean = "boolean",
75
- array = "array",
76
- date = "date",
77
- relation = "relation"
78
- }