@itrocks/framework 0.6.0 → 0.6.1

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.
package/README.md CHANGED
@@ -59,15 +59,21 @@ framework once at startup. It will:
59
59
  // index.ts
60
60
  import '@itrocks/framework'
61
61
 
62
- // Import your application modules so that their configuration, actions
63
- // and templates are discovered during composition.
64
- import '@itrocks/home'
65
- import './src/domain'
66
62
  ```
67
63
 
68
64
  When this file is executed with Node (after TypeScript compilation), the
69
65
  framework starts automatically and exposes your routes and actions.
70
66
 
67
+ Application code that must run after module composition but before the HTTP
68
+ server starts can register an initializer without loading domain decorators
69
+ during bootstrap:
70
+
71
+ ```ts
72
+ import { beforeFrameworkRun } from '@itrocks/framework'
73
+
74
+ beforeFrameworkRun(() => import('./src/dependencies'))
75
+ ```
76
+
71
77
  ### Using framework reflection helpers
72
78
 
73
79
  `ReflectClass` and `ReflectProperty` behave like their counterparts from
@@ -119,7 +125,7 @@ In this example:
119
125
 
120
126
  ## API
121
127
 
122
- `@itrocks/framework` exposes two main public symbols and the side‑effect
128
+ `@itrocks/framework` exposes its bootstrap initializer, two reflection helpers and the side‑effect
123
129
  of bootstrapping the framework when its main module is imported.
124
130
 
125
131
  ### Framework bootstrap (side‑effect of importing `@itrocks/framework`)
@@ -145,6 +151,13 @@ You normally do not call any of these functions directly. Importing the
145
151
  module once at startup is enough to run your application, provided that
146
152
  you have configured your routes and modules.
147
153
 
154
+ ### `beforeFrameworkRun(initializer)`
155
+
156
+ Registers application wiring that must load after it.rocks composition and dependency binding,
157
+ but before routes are loaded and the HTTP server starts. Initializers run sequentially in their
158
+ registration order and may be asynchronous. Use this for application-specific dependency hooks;
159
+ keep domain imports inside the callback.
160
+
148
161
  ### `class ReflectClass<T extends object = object> extends RC<T>`
149
162
 
150
163
  Enhanced reflection class that extends
@@ -1,4 +1,6 @@
1
1
  import '@itrocks/class-file/automation';
2
+ export type FrameworkInitializer = () => Promise<void> | void;
2
3
  export { servers } from './main';
3
4
  export { ReflectClass } from './reflect-class';
4
5
  export { ReflectProperty } from './reflect-property';
6
+ export declare function beforeFrameworkRun(initializer: FrameworkInitializer): void;
package/cjs/framework.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReflectProperty = exports.ReflectClass = exports.servers = void 0;
4
+ exports.beforeFrameworkRun = beforeFrameworkRun;
4
5
  require("@itrocks/class-file/automation");
5
6
  const compose_1 = require("@itrocks/compose");
6
7
  const config_1 = require("@itrocks/config");
@@ -11,13 +12,19 @@ var reflect_class_1 = require("./reflect-class");
11
12
  Object.defineProperty(exports, "ReflectClass", { enumerable: true, get: function () { return reflect_class_1.ReflectClass; } });
12
13
  var reflect_property_1 = require("./reflect-property");
13
14
  Object.defineProperty(exports, "ReflectProperty", { enumerable: true, get: function () { return reflect_property_1.ReflectProperty; } });
14
- (0, config_2.scanConfigFiles)().then(() => {
15
+ const initializers = new Array();
16
+ function beforeFrameworkRun(initializer) {
17
+ initializers.push(initializer);
18
+ }
19
+ (0, config_2.scanConfigFiles)().then(async () => {
15
20
  const frameworkCompose = {
16
21
  '@itrocks/store:Store': '/store-representative:Store'
17
22
  };
18
23
  (0, compose_1.compose)(__dirname, Object.assign(frameworkCompose, config_1.config.compose));
19
24
  require('@itrocks/default-action-workflow').build();
20
25
  require('./dependencies').bind();
21
- require('./main').run();
26
+ for (const initializer of initializers)
27
+ await initializer();
28
+ await require('./main').run();
22
29
  });
23
30
  //# sourceMappingURL=framework.js.map
package/cjs/main.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare function run(): Promise<void>;
2
1
  export declare const servers: {
3
2
  stop: () => void;
4
3
  }[];
4
+ export declare function run(): Promise<void>;
package/cjs/main.js CHANGED
@@ -2,23 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.servers = void 0;
4
4
  exports.run = run;
5
- const action_1 = require("@itrocks/action");
6
- const action_2 = require("@itrocks/action");
7
5
  const action_request_1 = require("@itrocks/action-request");
8
6
  const action_request_2 = require("@itrocks/action-request");
7
+ const action_1 = require("@itrocks/action");
8
+ const action_2 = require("@itrocks/action");
9
9
  const app_dir_1 = require("@itrocks/app-dir");
10
10
  const class_type_1 = require("@itrocks/class-type");
11
11
  const config_1 = require("@itrocks/config");
12
- const fastify_1 = require("@itrocks/fastify");
13
12
  const fastify_file_session_store_1 = require("@itrocks/fastify-file-session-store");
13
+ const fastify_1 = require("@itrocks/fastify");
14
14
  const request_response_1 = require("@itrocks/request-response");
15
15
  const route_1 = require("@itrocks/route");
16
+ const session_1 = require("@itrocks/session");
16
17
  const store_1 = require("@itrocks/store");
17
18
  const template_1 = require("@itrocks/template");
18
19
  const node_crypto_1 = require("node:crypto");
19
20
  const node_path_1 = require("node:path");
20
21
  const node_path_2 = require("node:path");
21
22
  const ephemeralSessionSecret = (0, node_crypto_1.randomBytes)(32).toString('base64url');
23
+ exports.servers = new Array();
22
24
  template_1.frontScripts.push('/lib/air-datepicker/locale/en.js', '/lib/air-datepicker/locale/fr.js');
23
25
  async function execute(request) {
24
26
  // Access control
@@ -63,6 +65,8 @@ async function run() {
63
65
  getModule: route_1.routes.resolve.bind(route_1.routes),
64
66
  isDomainObject: object => (0, class_type_1.isAnyType)(object) && !(object.prototype instanceof action_1.Action)
65
67
  });
68
+ const sessionStore = new fastify_file_session_store_1.FileStore((0, node_path_2.normalize)((0, node_path_1.join)(app_dir_1.appDir, config_1.config.session.path)));
69
+ (0, session_1.sessionDependsOn)({ store: sessionStore });
66
70
  const server = new fastify_1.FastifyServer({
67
71
  assetPath: app_dir_1.appDir,
68
72
  cookie: config_1.config.session.cookie,
@@ -76,12 +80,11 @@ async function run() {
76
80
  scriptCalls: ['loadCss', 'loadScript'],
77
81
  secret: config_1.config.session.secret ?? config_1.config.secret ?? ephemeralSessionSecret,
78
82
  secure: config_1.config.server.secure ?? 'auto',
79
- store: new fastify_file_session_store_1.FileStore((0, node_path_2.normalize)((0, node_path_1.join)(app_dir_1.appDir, config_1.config.session.path)))
83
+ store: sessionStore
80
84
  });
81
85
  server.run();
82
86
  exports.servers.push(server);
83
87
  }
84
- exports.servers = new Array();
85
88
  function toResponse(mixedResponse) {
86
89
  return (typeof mixedResponse === 'string')
87
90
  ? new request_response_1.Response(mixedResponse)
package/package.json CHANGED
@@ -44,6 +44,7 @@
44
44
  "@itrocks/request-response": "latest",
45
45
  "@itrocks/required": "latest",
46
46
  "@itrocks/route": "latest",
47
+ "@itrocks/session": "latest",
47
48
  "@itrocks/sql-build": "latest",
48
49
  "@itrocks/sql-functions": "latest",
49
50
  "@itrocks/sql-join": "latest",
@@ -101,5 +102,5 @@
101
102
  "build:back": "tsc",
102
103
  "build:front": "tsc -p src/front/tsconfig.json && node -e \"const fs=require('node:fs');for(const file of fs.readdirSync('.').filter(file=>file.endsWith('.js')||file.endsWith('.d.ts')))fs.writeFileSync(file,fs.readFileSync(file,'utf8').replaceAll('../../',''))\""
103
104
  },
104
- "version": "0.6.0"
105
+ "version": "0.6.1"
105
106
  }