@chromahq/core 0.1.3 → 0.1.5

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/dist/index.cjs.js CHANGED
@@ -1197,13 +1197,14 @@ class ApplicationBootstrap {
1197
1197
  }) {
1198
1198
  try {
1199
1199
  this.logger.info("\u{1F680} Starting Chroma application bootstrap...");
1200
- await this.discoverServices();
1201
1200
  await this.discoverAndInitializeStores();
1201
+ await this.discoverServices();
1202
1202
  await this.validateDependencies();
1203
1203
  await this.registerServices();
1204
1204
  await this.registerMessages();
1205
1205
  await this.registerJobs();
1206
1206
  await this.bootMessages();
1207
+ await this.bootServices();
1207
1208
  this.logger.success("\u{1F389} Chroma application initialization complete!");
1208
1209
  bootstrap$1({ container, keepAlive: keepPortAlive, portName });
1209
1210
  } catch (error) {
@@ -1211,6 +1212,23 @@ class ApplicationBootstrap {
1211
1212
  throw error;
1212
1213
  }
1213
1214
  }
1215
+ /**
1216
+ * Boot all registered services by calling their onBoot method if present
1217
+ */
1218
+ async bootServices() {
1219
+ this.logger.info("\u{1F680} Booting services...");
1220
+ for (const [serviceName, ServiceClass] of this.serviceRegistry.entries()) {
1221
+ try {
1222
+ const instance = container.get(ServiceClass);
1223
+ if (typeof instance.onBoot === "function") {
1224
+ await instance.onBoot();
1225
+ this.logger.success(`Booted service: ${serviceName}`);
1226
+ }
1227
+ } catch (error) {
1228
+ this.logger.error(`Failed to boot service ${serviceName}:`, error);
1229
+ }
1230
+ }
1231
+ }
1214
1232
  /**
1215
1233
  * Discover all services in the application directory
1216
1234
  */
@@ -1252,8 +1270,15 @@ class ApplicationBootstrap {
1252
1270
  this.logger.info(`Initializing ${this.storeDefinitions.length} store(s)...`);
1253
1271
  const chromaGlobal = globalThis.__CHROMA__;
1254
1272
  if (chromaGlobal?.initStores && typeof chromaGlobal.initStores === "function") {
1273
+ let isFirstStore = true;
1255
1274
  for (const store of this.storeDefinitions) {
1256
- const { classes } = await chromaGlobal.initStores(store);
1275
+ const { classes, store: storeInstance } = await chromaGlobal.initStores(store);
1276
+ const diKey = `CentralStore:${store.name}`;
1277
+ container.bind(diKey).toConstantValue(storeInstance);
1278
+ if (isFirstStore) {
1279
+ container.bind("CentralStore").toConstantValue(storeInstance);
1280
+ isFirstStore = false;
1281
+ }
1257
1282
  this.registerMessageClass(classes.GetStoreStateMessage, `store:${store.name}:getState`);
1258
1283
  this.registerMessageClass(classes.SetStoreStateMessage, `store:${store.name}:setState`);
1259
1284
  this.registerMessageClass(
package/dist/index.es.js CHANGED
@@ -1195,13 +1195,14 @@ class ApplicationBootstrap {
1195
1195
  }) {
1196
1196
  try {
1197
1197
  this.logger.info("\u{1F680} Starting Chroma application bootstrap...");
1198
- await this.discoverServices();
1199
1198
  await this.discoverAndInitializeStores();
1199
+ await this.discoverServices();
1200
1200
  await this.validateDependencies();
1201
1201
  await this.registerServices();
1202
1202
  await this.registerMessages();
1203
1203
  await this.registerJobs();
1204
1204
  await this.bootMessages();
1205
+ await this.bootServices();
1205
1206
  this.logger.success("\u{1F389} Chroma application initialization complete!");
1206
1207
  bootstrap$1({ container, keepAlive: keepPortAlive, portName });
1207
1208
  } catch (error) {
@@ -1209,6 +1210,23 @@ class ApplicationBootstrap {
1209
1210
  throw error;
1210
1211
  }
1211
1212
  }
1213
+ /**
1214
+ * Boot all registered services by calling their onBoot method if present
1215
+ */
1216
+ async bootServices() {
1217
+ this.logger.info("\u{1F680} Booting services...");
1218
+ for (const [serviceName, ServiceClass] of this.serviceRegistry.entries()) {
1219
+ try {
1220
+ const instance = container.get(ServiceClass);
1221
+ if (typeof instance.onBoot === "function") {
1222
+ await instance.onBoot();
1223
+ this.logger.success(`Booted service: ${serviceName}`);
1224
+ }
1225
+ } catch (error) {
1226
+ this.logger.error(`Failed to boot service ${serviceName}:`, error);
1227
+ }
1228
+ }
1229
+ }
1212
1230
  /**
1213
1231
  * Discover all services in the application directory
1214
1232
  */
@@ -1250,8 +1268,15 @@ class ApplicationBootstrap {
1250
1268
  this.logger.info(`Initializing ${this.storeDefinitions.length} store(s)...`);
1251
1269
  const chromaGlobal = globalThis.__CHROMA__;
1252
1270
  if (chromaGlobal?.initStores && typeof chromaGlobal.initStores === "function") {
1271
+ let isFirstStore = true;
1253
1272
  for (const store of this.storeDefinitions) {
1254
- const { classes } = await chromaGlobal.initStores(store);
1273
+ const { classes, store: storeInstance } = await chromaGlobal.initStores(store);
1274
+ const diKey = `CentralStore:${store.name}`;
1275
+ container.bind(diKey).toConstantValue(storeInstance);
1276
+ if (isFirstStore) {
1277
+ container.bind("CentralStore").toConstantValue(storeInstance);
1278
+ isFirstStore = false;
1279
+ }
1255
1280
  this.registerMessageClass(classes.GetStoreStateMessage, `store:${store.name}:getState`);
1256
1281
  this.registerMessageClass(classes.SetStoreStateMessage, `store:${store.name}:setState`);
1257
1282
  this.registerMessageClass(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromahq/core",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Core library for building Chrome extensions with Chroma framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",