@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,23 +1,23 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { spawn } from 'child_process';
4
- import system from '../../../esm/system/index.js';
4
+ import system from '../../esm/system/index.js';
5
5
 
6
- export const command = "build";
7
- export const desc = "Bundle the project into a single minified file.";
6
+ export const command = 'build';
7
+ export const desc = 'Bundle the project into a single minified file.';
8
8
 
9
9
  export const builder = {
10
10
  entry: {
11
- alias: "e",
12
- type: "string",
13
- default: "src/index.ts",
14
- describe: "Entry point of the application",
11
+ alias: 'e',
12
+ type: 'string',
13
+ default: 'src/index.ts',
14
+ describe: 'Entry point of the application',
15
15
  },
16
16
  output: {
17
- alias: "o",
18
- type: "string",
19
- default: "dist/index.js",
20
- describe: "Output file path",
17
+ alias: 'o',
18
+ type: 'string',
19
+ default: 'dist/index.js',
20
+ describe: 'Output file path',
21
21
  },
22
22
  };
23
23
 
@@ -31,7 +31,7 @@ export const handler = async (argv) => {
31
31
  try {
32
32
  // 1. Discover all entities
33
33
  console.log('--> Scanning for controllers, models and schedules...');
34
-
34
+
35
35
  // We don't actually need to await these here if we are just calling esbuild,
36
36
  // but it's a good check to see if the project is valid.
37
37
  await system.getAllControllers();
@@ -40,23 +40,11 @@ export const handler = async (argv) => {
40
40
 
41
41
  console.log('--> Invoking build engine...');
42
42
 
43
- const esbuildArgs = [
44
- 'esbuild',
45
- argv.entry,
46
- '--bundle',
47
- '--minify',
48
- '--platform=node',
49
- '--format=esm',
50
- `--outfile=${argv.output}`,
51
- '--external:bcrypt',
52
- '--external:sqlite3',
53
- '--external:mysql2',
54
- '--external:pg'
55
- ];
43
+ const esbuildArgs = ['esbuild', argv.entry, '--bundle', '--minify', '--platform=node', '--format=esm', `--outfile=${argv.output}`, '--external:bcrypt', '--external:sqlite3', '--external:mysql2', '--external:pg'];
56
44
 
57
- const child = spawn('npx', esbuildArgs, {
45
+ const child = spawn('npx', esbuildArgs, {
58
46
  stdio: 'inherit',
59
- shell: true
47
+ shell: true,
60
48
  });
61
49
 
62
50
  child.on('close', (code) => {
@@ -68,7 +56,6 @@ export const handler = async (argv) => {
68
56
  console.log('--> Ensure you have "esbuild" installed or accessible via npx.');
69
57
  }
70
58
  });
71
-
72
59
  } catch (error) {
73
60
  console.error('--> Build error:', error.message);
74
61
  }
@@ -1,25 +1,20 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
 
4
- export const command = "init";
5
- export const desc = "Scaffold a new Opposer project structure.";
4
+ export const command = 'init';
5
+ export const desc = 'Scaffold a new Opposer project structure.';
6
6
 
7
7
  export const builder = {};
8
8
 
9
9
  export const handler = async () => {
10
10
  const root = process.cwd();
11
-
11
+
12
12
  // 1. Create Directories
13
- const dirs = [
14
- 'src',
15
- 'src/controllers',
16
- 'src/models',
17
- 'src/schedules'
18
- ];
13
+ const dirs = ['src', 'src/controllers', 'src/models', 'src/schedules'];
19
14
 
20
15
  console.log('--> Creating project structure...');
21
-
22
- dirs.forEach(dir => {
16
+
17
+ dirs.forEach((dir) => {
23
18
  const fullPath = path.join(root, dir);
24
19
  if (!fs.existsSync(fullPath)) {
25
20
  fs.mkdirSync(fullPath, { recursive: true });
@@ -30,18 +25,20 @@ export const handler = async () => {
30
25
  });
31
26
 
32
27
  // 2. Create Files Content
33
-
28
+
34
29
  // src/index.ts
35
30
  const indexTsContent = `import { Server } from "@ug.software/opposer";
36
31
 
37
- const app = await Server({
38
- models: "./src/models",
39
- controllers: "./src/controllers",
40
- schedules: "./src/schedules",
41
- cors: { origin: "*" }
42
- });
43
-
44
- app.initialize();
32
+ (async () => {
33
+ const app = await Server({
34
+ models: "./models",
35
+ controllers: "./controllers",
36
+ schedules: "./schedules",
37
+ cors: { origin: "*" }
38
+ });
39
+
40
+ app.initialize();
41
+ })()
45
42
  `;
46
43
 
47
44
  // src/controllers/health.ts
@@ -68,7 +65,7 @@ export default class Example {
68
65
  @PrimaryColumn({ type: "uuid" })
69
66
  id!: string;
70
67
 
71
- @Field(() => f().string().required())
68
+ @Field(() => f().string("typeof field is string").required("field is required"))
72
69
  name!: string;
73
70
 
74
71
  @CreateDateColumn()
@@ -124,10 +121,10 @@ OPPOSER_DATABASE_LOGGING=true
124
121
  { path: 'src/controllers/health.ts', content: healthControllerContent },
125
122
  { path: 'src/models/example.ts', content: exampleModelContent },
126
123
  { path: 'opposer-settings.json', content: settingsContent },
127
- { path: '.env', content: envContent }
124
+ { path: '.env', content: envContent },
128
125
  ];
129
126
 
130
- files.forEach(file => {
127
+ files.forEach((file) => {
131
128
  const fullPath = path.join(root, file.path);
132
129
  if (!fs.existsSync(fullPath)) {
133
130
  fs.writeFileSync(fullPath, file.content);
@@ -146,19 +143,19 @@ OPPOSER_DATABASE_LOGGING=true
146
143
  } else {
147
144
  packageJson = {
148
145
  name: path.basename(root),
149
- version: "1.0.0",
150
- type: "module",
151
- description: "Opposer project",
152
- main: "src/index.ts",
146
+ version: '1.0.0',
147
+ type: 'module',
148
+ description: 'Opposer project',
149
+ main: 'src/index.ts',
153
150
  dependencies: {},
154
- devDependencies: {}
151
+ devDependencies: {},
155
152
  };
156
153
  }
157
154
 
158
155
  packageJson.scripts = {
159
156
  ...(packageJson.scripts || {}),
160
- "dev": "npx tsx src/index.ts",
161
- "build": "npx opposer build"
157
+ dev: 'npx tsx src/index.ts',
158
+ build: 'npx opposer build',
162
159
  };
163
160
 
164
161
  fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
@@ -1,4 +1,4 @@
1
- import { ForgetJwt, SignJwt } from "../../../interfaces/jwt.js";
1
+ import { ForgetJwt, SignJwt } from '../../../interfaces/jwt.js';
2
2
  declare function access(token: string): Promise<string | SignJwt | undefined>;
3
3
  declare function refresh(token: string): Promise<string | SignJwt | undefined>;
4
4
  declare function sign({ exp, ...payload }: SignJwt): Promise<{
@@ -1,16 +1,10 @@
1
1
  //@ts-ignore
2
- import jwt from "jsonwebtoken";
3
- import system from "../../../system/index.js";
2
+ import jwt from 'jsonwebtoken';
3
+ import system from '../../../system/index.js';
4
4
  const settings = system.getSettingsFile();
5
- const accessJwt = process.env.ACCESS_JWT
6
- ? process.env.ACCESS_JWT
7
- : settings.jwt.access;
8
- const refreshJwt = process.env.REFRESH_JWT
9
- ? process.env.REFRESH_JWT
10
- : settings.jwt.refresh;
11
- const recoverJwt = process.env.RECOVER_JWT
12
- ? process.env.RECOVER_JWT
13
- : settings.jwt.recover;
5
+ const accessJwt = process.env.OPPOSER_JWT_ACCESS ? process.env.OPPOSER_JWT_ACCESS : settings.jwt.access;
6
+ const refreshJwt = process.env.OPPOSER_JWT_REFRESH ? process.env.OPPOSER_JWT_REFRESH : settings.jwt.refresh;
7
+ const recoverJwt = process.env.OPPOSER_JWT_RECOVER ? process.env.OPPOSER_JWT_RECOVER : settings.jwt.recover;
14
8
  async function access(token) {
15
9
  if (!accessJwt) {
16
10
  throw new Error("[jwt] - Don't finded token for access jwt, generate running 'npx @ug.software/opposer jwt generate' or consulting documentation.");
@@ -21,11 +15,11 @@ async function access(token) {
21
15
  }
22
16
  catch (err) {
23
17
  var erro = err;
24
- if (erro.name === "TokenExpiredError") {
18
+ if (erro.name === 'TokenExpiredError') {
25
19
  return erro.message;
26
20
  }
27
- if (erro.name === "JsonWebTokenError") {
28
- return "Check your data and try again.";
21
+ if (erro.name === 'JsonWebTokenError') {
22
+ return 'Check your data and try again.';
29
23
  }
30
24
  }
31
25
  }
@@ -39,11 +33,11 @@ async function refresh(token) {
39
33
  }
40
34
  catch (err) {
41
35
  var erro = err;
42
- if (erro.name === "TokenExpiredError") {
36
+ if (erro.name === 'TokenExpiredError') {
43
37
  return erro.message;
44
38
  }
45
- if (erro.name === "JsonWebTokenError") {
46
- return "Check your data and try again.";
39
+ if (erro.name === 'JsonWebTokenError') {
40
+ return 'Check your data and try again.';
47
41
  }
48
42
  }
49
43
  }
@@ -51,9 +45,9 @@ async function sign({ exp, ...payload }) {
51
45
  if (!accessJwt) {
52
46
  throw new Error("[jwt] - Don't finded token secret, generate running 'npx @ug.software/opposer jwt generate' or consulting documentation.");
53
47
  }
54
- const token = jwt.sign({ ...payload }, accessJwt, { expiresIn: "15m" });
48
+ const token = jwt.sign({ ...payload }, accessJwt, { expiresIn: '15m' });
55
49
  const refresh = jwt.sign({ ...payload }, refreshJwt, {
56
- expiresIn: "15d",
50
+ expiresIn: '15d',
57
51
  });
58
52
  return { token, refresh };
59
53
  }
@@ -61,7 +55,7 @@ async function forget(payload) {
61
55
  if (!recoverJwt) {
62
56
  throw new Error("[jwt] - Don't finded token secret for recover password, generate running 'npx @ug.software/opposer jwt generate' or consulting documentation.");
63
57
  }
64
- const token = jwt.sign(payload, accessJwt, { expiresIn: "5m" });
58
+ const token = jwt.sign(payload, accessJwt, { expiresIn: '5m' });
65
59
  return { token };
66
60
  }
67
61
  async function recover(token) {
@@ -74,29 +68,27 @@ async function recover(token) {
74
68
  }
75
69
  catch (err) {
76
70
  var erro = err;
77
- if (erro.name === "TokenExpiredError") {
71
+ if (erro.name === 'TokenExpiredError') {
78
72
  return erro.message;
79
73
  }
80
- if (erro.name === "JsonWebTokenError") {
81
- return "Check your data and try again.";
74
+ if (erro.name === 'JsonWebTokenError') {
75
+ return 'Check your data and try again.';
82
76
  }
83
77
  }
84
78
  }
85
79
  async function verify(token) {
86
80
  try {
87
- const secret = process.env.ACCESS_JWT
88
- ? process.env.ACCESS_JWT
89
- : settings.jwt;
81
+ const secret = process.env.OPPOSER_JWT_ACCESS ? process.env.OPPOSER_JWT_ACCESS : settings.jwt;
90
82
  jwt.verify(token, secret);
91
83
  return true;
92
84
  }
93
85
  catch (err) {
94
86
  var erro = err;
95
- if (erro.name === "TokenExpiredError") {
87
+ if (erro.name === 'TokenExpiredError') {
96
88
  return erro.message;
97
89
  }
98
- if (erro.name === "JsonWebTokenError") {
99
- return "Check your data and try again.";
90
+ if (erro.name === 'JsonWebTokenError') {
91
+ return 'Check your data and try again.';
100
92
  }
101
93
  }
102
94
  }
@@ -1,4 +1,4 @@
1
- import { OpposerSystemConfigOptions, ClassType, ModelDefinition } from "../interfaces/system.js";
1
+ import { OpposerSystemConfigOptions, ClassType, ModelDefinition } from '../interfaces/system.js';
2
2
  export declare class OpposerSystem {
3
3
  getFileName(filePath: string, withExtension?: boolean): string;
4
4
  getAllModels(customModels?: string | ClassType<unknown>[]): Promise<ModelDefinition[]>;
@@ -1,13 +1,13 @@
1
- import { pathToFileURL } from "url";
2
- import path from "path";
3
- import fs from "fs";
4
- import ChangeRequestPassword from "../server/security/models/crp.js";
5
- import Key from "../server/security/models/ke.js";
6
- import Role from "../server/security/models/rl.js";
7
- import Session from "../server/security/models/se.js";
8
- import User from "../server/security/models/usr.js";
9
- import ScheduleHistory from "../scheduler/models/history.js";
10
- import { MetadataStore } from "../orm/metadata.js";
1
+ import { pathToFileURL } from 'url';
2
+ import path from 'path';
3
+ import fs from 'fs';
4
+ import ChangeRequestPassword from '../server/security/models/crp.js';
5
+ import Key from '../server/security/models/ke.js';
6
+ import Role from '../server/security/models/rl.js';
7
+ import Session from '../server/security/models/se.js';
8
+ import User from '../server/security/models/usr.js';
9
+ import ScheduleHistory from '../scheduler/models/history.js';
10
+ import { MetadataStore } from '../orm/metadata.js';
11
11
  export class OpposerSystem {
12
12
  getFileName(filePath, withExtension = true) {
13
13
  if (withExtension) {
@@ -20,7 +20,7 @@ export class OpposerSystem {
20
20
  async getAllModels(customModels) {
21
21
  const settings = this.getSettingsFile();
22
22
  const root = process.cwd();
23
- if (typeof customModels === "string") {
23
+ if (typeof customModels === 'string') {
24
24
  const modelsPath = path.resolve(root, customModels);
25
25
  if (fs.existsSync(modelsPath)) {
26
26
  const modelsFiles = this.getAllFiles(modelsPath);
@@ -52,24 +52,24 @@ export class OpposerSystem {
52
52
  getAuthModels(settings) {
53
53
  const models = [];
54
54
  if (settings.auth) {
55
- models.push({ name: "crp", entity: ChangeRequestPassword }, { name: "ke", entity: Key }, { name: "rl", entity: Role }, { name: "se", entity: Session }, { name: "usr", entity: User });
55
+ models.push({ name: 'crp', entity: ChangeRequestPassword }, { name: 'ke', entity: Key }, { name: 'rl', entity: Role }, { name: 'se', entity: Session }, { name: 'usr', entity: User });
56
56
  }
57
57
  // Always include ScheduleHistory as it's a core feature
58
- models.push({ name: "sh", entity: ScheduleHistory });
58
+ models.push({ name: 'sh', entity: ScheduleHistory });
59
59
  return models;
60
60
  }
61
61
  async getAllControllers(customControllers) {
62
62
  const settings = this.getSettingsFile();
63
63
  const root = process.cwd();
64
64
  // Dynamic import to avoid circular dependency
65
- const SchedulerController = (await import("../scheduler/controllers/index.js")).default;
65
+ const SchedulerController = (await import('../scheduler/controllers/index.js')).default;
66
66
  const internalControllers = [SchedulerController];
67
67
  if (Array.isArray(customControllers)) {
68
68
  return [...internalControllers, ...customControllers];
69
69
  }
70
- let controllersPath = customControllers || path.resolve(root, "src", "controllers");
70
+ let controllersPath = customControllers || path.resolve(root, 'src', 'controllers');
71
71
  if (!customControllers && settings.controllers) {
72
- controllersPath = path.resolve(root, settings.controllers, "controllers");
72
+ controllersPath = path.resolve(root, settings.controllers, 'controllers');
73
73
  }
74
74
  if (!fs.existsSync(controllersPath)) {
75
75
  return internalControllers;
@@ -88,9 +88,9 @@ export class OpposerSystem {
88
88
  if (Array.isArray(customSchedules)) {
89
89
  return customSchedules;
90
90
  }
91
- let schedulesPath = customSchedules || path.resolve(root, "src", "schedules");
91
+ let schedulesPath = customSchedules || path.resolve(root, 'src', 'schedules');
92
92
  if (!customSchedules && settings.schedules) {
93
- schedulesPath = path.resolve(root, settings.schedules, "schedules");
93
+ schedulesPath = path.resolve(root, settings.schedules, 'schedules');
94
94
  }
95
95
  if (!fs.existsSync(schedulesPath)) {
96
96
  return [];
@@ -107,9 +107,9 @@ export class OpposerSystem {
107
107
  let config = {};
108
108
  try {
109
109
  const root = process.cwd();
110
- const configPath = path.resolve(root, "opposer-settings.json");
110
+ const configPath = path.resolve(root, 'opposer-settings.json');
111
111
  if (fs.existsSync(configPath)) {
112
- const fileContent = fs.readFileSync(configPath, "utf8");
112
+ const fileContent = fs.readFileSync(configPath, 'utf8');
113
113
  config = JSON.parse(fileContent);
114
114
  }
115
115
  }
@@ -117,53 +117,41 @@ export class OpposerSystem {
117
117
  // Normal if file doesn't exist
118
118
  }
119
119
  // Override with Environment Variables
120
- config.port = process.env.OPPOSER_PORT
121
- ? parseInt(process.env.OPPOSER_PORT)
122
- : config.port || 3000;
120
+ config.port = process.env.OPPOSER_PORT ? parseInt(process.env.OPPOSER_PORT) : config.port || 3000;
123
121
  config.url = process.env.OPPOSER_URL || config.url;
122
+ config.auth = process.env.OPPOSER_AUTH ? JSON.parse(process.env.OPPOSER_AUTH) : config.auth || false;
124
123
  if (process.env.OPPOSER_DATABASE_TYPE || config.database) {
125
124
  config.database = {
126
125
  ...config.database,
127
- type: process.env.OPPOSER_DATABASE_TYPE ||
128
- config.database?.type,
126
+ type: process.env.OPPOSER_DATABASE_TYPE || config.database?.type,
129
127
  host: process.env.OPPOSER_DATABASE_HOST || config.database?.host,
130
- port: process.env.OPPOSER_DATABASE_PORT
131
- ? parseInt(process.env.OPPOSER_DATABASE_PORT)
132
- : config.database?.port,
133
- username: process.env.OPPOSER_DATABASE_USER ||
134
- config.database?.username,
135
- password: process.env.OPPOSER_DATABASE_PASSWORD ||
136
- config.database?.password,
128
+ port: process.env.OPPOSER_DATABASE_PORT ? parseInt(process.env.OPPOSER_DATABASE_PORT) : config.database?.port,
129
+ username: process.env.OPPOSER_DATABASE_USER || config.database?.username,
130
+ password: process.env.OPPOSER_DATABASE_PASSWORD || config.database?.password,
137
131
  database: process.env.OPPOSER_DATABASE_NAME || config.database?.database,
138
- logging: process.env.OPPOSER_DATABASE_LOGGING === "true" || config.database?.logging,
132
+ logging: process.env.OPPOSER_DATABASE_LOGGING === 'true' || config.database?.logging,
139
133
  };
140
134
  }
141
135
  if (process.env.OPPOSER_JWT_ACCESS || config.jwt) {
142
136
  config.jwt = {
143
- ...(config.jwt || { access: "", refresh: "", recover: "" }),
144
- access: process.env.OPPOSER_JWT_ACCESS || config.jwt?.access || "",
145
- refresh: process.env.OPPOSER_JWT_REFRESH || config.jwt?.refresh || "",
146
- recover: process.env.OPPOSER_JWT_RECOVER || config.jwt?.recover || "",
137
+ ...(config.jwt || { access: '', refresh: '', recover: '' }),
138
+ access: process.env.OPPOSER_JWT_ACCESS || config.jwt?.access || '',
139
+ refresh: process.env.OPPOSER_JWT_REFRESH || config.jwt?.refresh || '',
140
+ recover: process.env.OPPOSER_JWT_RECOVER || config.jwt?.recover || '',
147
141
  };
148
142
  }
149
143
  if (process.env.OPPOSER_MANAGER_LOGIN || config.manager) {
150
144
  config.manager = {
151
145
  ...(config.manager || {
152
- login: "",
153
- password: "",
154
- firstName: "",
155
- lastName: "",
146
+ login: '',
147
+ password: '',
148
+ firstName: '',
149
+ lastName: '',
156
150
  }),
157
- login: process.env.OPPOSER_MANAGER_LOGIN || config.manager?.login || "",
158
- password: process.env.OPPOSER_MANAGER_PASSWORD ||
159
- config.manager?.password ||
160
- "",
161
- firstName: process.env.OPPOSER_MANAGER_FIRST_NAME ||
162
- config.manager?.firstName ||
163
- "",
164
- lastName: process.env.OPPOSER_MANAGER_LAST_NAME ||
165
- config.manager?.lastName ||
166
- "",
151
+ login: process.env.OPPOSER_MANAGER_LOGIN || config.manager?.login || '',
152
+ password: process.env.OPPOSER_MANAGER_PASSWORD || config.manager?.password || '',
153
+ firstName: process.env.OPPOSER_MANAGER_FIRST_NAME || config.manager?.firstName || '',
154
+ lastName: process.env.OPPOSER_MANAGER_LAST_NAME || config.manager?.lastName || '',
167
155
  };
168
156
  }
169
157
  return config;
@@ -178,8 +166,7 @@ export class OpposerSystem {
178
166
  if (file.isDirectory()) {
179
167
  results = results.concat(this.getAllFiles(filePath));
180
168
  }
181
- else if (file.isFile() &&
182
- (file.name.endsWith(".js") || file.name.endsWith(".ts"))) {
169
+ else if (file.isFile() && (file.name.endsWith('.js') || file.name.endsWith('.ts'))) {
183
170
  results.push(filePath);
184
171
  }
185
172
  });
@@ -187,9 +174,9 @@ export class OpposerSystem {
187
174
  }
188
175
  saveSettingsFile(settings) {
189
176
  const root = process.cwd();
190
- const configPath = path.resolve(root, "opposer-settings.json");
177
+ const configPath = path.resolve(root, 'opposer-settings.json');
191
178
  return fs.writeFileSync(configPath, JSON.stringify(settings, null, 2), {
192
- encoding: "utf8",
179
+ encoding: 'utf8',
193
180
  });
194
181
  }
195
182
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ug.software/opposer",
3
- "version": "3.0.10",
3
+ "version": "3.0.11",
4
4
  "description": "Ecossistema modular para construção de aplicações modernas focado em alta produtividade e organização por Domínios.",
5
5
  "type": "module",
6
6
  "main": "./lib/cjs/index.js",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "https://www.opposer.uiaranguilherme.com"
17
+ "url": "https://github.com/ug-software/opposer"
18
18
  },
19
19
  "keywords": [
20
20
  "orm",
@@ -31,7 +31,7 @@
31
31
  "bugs": {
32
32
  "url": "https://github.com/ug-software/opposer/issues"
33
33
  },
34
- "homepage": "https://github.com/ug-software/opposer#readme",
34
+ "homepage": "https://opposer.uiaranguilherme.com",
35
35
  "exports": {
36
36
  ".": {
37
37
  "import": "./lib/esm/index.js",
@@ -1 +0,0 @@
1
- export {};
@@ -1,102 +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
- const index_js_1 = __importStar(require("../../server/index.js"));
40
- const author_js_1 = __importDefault(require("./models/author.js"));
41
- const book_js_1 = __importDefault(require("./models/book.js"));
42
- const category_js_1 = __importDefault(require("./models/category.js"));
43
- const path_1 = __importDefault(require("path"));
44
- const url_1 = require("url");
45
- // @ts-ignore
46
- const _dirname = typeof __dirname !== 'undefined'
47
- ? __dirname
48
- : // @ts-ignore
49
- path_1.default.dirname((0, url_1.fileURLToPath)(import.meta.url));
50
- async function runFullExample() {
51
- console.log('🚀 Initializing Full Opposer Example...');
52
- // 1. Setup Environment
53
- process.env.OPPOSER_PORT = '4000';
54
- process.env.OPPOSER_DATABASE_TYPE = 'sqlite';
55
- process.env.OPPOSER_DATABASE_NAME = './full-app.db';
56
- try {
57
- // 2. Start Opposer Server
58
- // Passing the local models and schedules path so initialization can find our entities
59
- const { initialize } = await (0, index_js_1.default)({
60
- cors: { origin: '*' },
61
- models: path_1.default.resolve(_dirname, 'models'),
62
- schedules: path_1.default.resolve(_dirname, 'schedules'),
63
- });
64
- // 3. Populate Initial Data
65
- // Using the new global Context to get the database
66
- const db = index_js_1.Context.get('db');
67
- console.log('📝 Populating initial data...');
68
- const authorRepo = db.getRepository(author_js_1.default);
69
- const categoryRepo = db.getRepository(category_js_1.default);
70
- const bookRepo = db.getRepository(book_js_1.default);
71
- //@ts-ignore
72
- const { randomUUID } = await Promise.resolve().then(() => __importStar(require('crypto')));
73
- // Insert Author
74
- let author = await authorRepo.findOne({ where: { name: 'J.K. Rowling' } });
75
- if (!author) {
76
- author = await authorRepo.insert({ id: randomUUID(), name: 'J.K. Rowling', nationality: 'British' });
77
- }
78
- // Insert Category
79
- let category = await categoryRepo.findOne({ where: { title: 'Fantasy' } });
80
- if (!category) {
81
- category = await categoryRepo.insert({ id: randomUUID(), title: 'Fantasy' });
82
- }
83
- // Insert Books
84
- const bookCount = await bookRepo.count({});
85
- if (bookCount === 0) {
86
- await bookRepo.insert({ id: randomUUID(), title: "Harry Potter and the Philosopher's Stone", price: 39.9, author: author.id, category: category.id });
87
- await bookRepo.insert({ id: randomUUID(), title: 'Harry Potter and the Chamber of Secrets', price: 42.5, author: author.id, category: category.id });
88
- console.log('✅ Data populated.');
89
- }
90
- // 4. Start listening
91
- initialize();
92
- console.log('\n--- Example Info ---');
93
- console.log('API URL: http://localhost:4000/opposer');
94
- console.log('Playground Map: http://localhost:4000/opposer-map.json');
95
- console.log('Playground Status: http://localhost:4000/playground');
96
- console.log('--------------------\n');
97
- }
98
- catch (error) {
99
- console.error('❌ Failed to start example:', error);
100
- }
101
- }
102
- runFullExample();
@@ -1,7 +0,0 @@
1
- import Book from "./book.js";
2
- export default class Author {
3
- id: string;
4
- name: string;
5
- nationality?: string;
6
- books: Book[];
7
- }