@chromahq/core 0.1.13 → 0.1.15

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/boot.cjs.js CHANGED
@@ -1142,9 +1142,9 @@ class ApplicationBootstrap {
1142
1142
  * Add a store definition to be initialized
1143
1143
  */
1144
1144
  withStore(storeDefinition) {
1145
- if (storeDefinition && storeDefinition.name) {
1145
+ if (storeDefinition && storeDefinition.def && storeDefinition.store) {
1146
1146
  this.storeDefinitions.push(storeDefinition);
1147
- this.logger.debug(`\u{1F4E6} Added store definition: ${storeDefinition.name}`);
1147
+ this.logger.debug(`\u{1F4E6} Added store definition: ${storeDefinition.def.name}`);
1148
1148
  }
1149
1149
  return this;
1150
1150
  }
@@ -1152,9 +1152,7 @@ class ApplicationBootstrap {
1152
1152
  * Add multiple store definitions to be initialized
1153
1153
  */
1154
1154
  withStores(storeDefinitions) {
1155
- for (const store of storeDefinitions) {
1156
- this.withStore(store);
1157
- }
1155
+ storeDefinitions.forEach((store) => this.withStore(store));
1158
1156
  return this;
1159
1157
  }
1160
1158
  /**
@@ -1162,9 +1160,11 @@ class ApplicationBootstrap {
1162
1160
  */
1163
1161
  async create({
1164
1162
  keepPortAlive = false,
1165
- portName
1163
+ portName,
1164
+ enableLogs = true
1166
1165
  }) {
1167
1166
  try {
1167
+ this.logger = new BootstrapLogger(enableLogs);
1168
1168
  this.logger.info("\u{1F680} Starting Chroma application bootstrap...");
1169
1169
  await this.discoverAndInitializeStores();
1170
1170
  await this.discoverServices();
@@ -1212,7 +1212,7 @@ class ApplicationBootstrap {
1212
1212
  const ServiceClass = module?.default;
1213
1213
  if (!ServiceClass || typeof ServiceClass !== "function") {
1214
1214
  this.logger.warn(
1215
- `\u26A0\uFE0F Skipping invalid service module - no default export or not a constructor`
1215
+ `\u26A0\uFE0F Skipping invalid service module - no default export or not a constructor` + module
1216
1216
  );
1217
1217
  continue;
1218
1218
  }
@@ -1243,25 +1243,23 @@ class ApplicationBootstrap {
1243
1243
  return;
1244
1244
  }
1245
1245
  this.logger.info(`Initializing ${this.storeDefinitions.length} store(s)...`);
1246
- const chromaGlobal = globalThis.__CHROMA__;
1247
- if (chromaGlobal?.initStores && typeof chromaGlobal.initStores === "function") {
1248
- let isFirstStore = true;
1249
- for (const store of this.storeDefinitions) {
1250
- const { classes, store: storeInstance } = await chromaGlobal.initStores(store);
1251
- const diKey = `CentralStore:${store.name}`;
1252
- IJob.container.bind(diKey).toConstantValue(storeInstance);
1253
- if (isFirstStore) {
1254
- IJob.container.bind(IJob.TOKENS.Store).toConstantValue(storeInstance);
1255
- isFirstStore = false;
1256
- }
1257
- this.registerMessageClass(classes.GetStoreStateMessage, `store:${store.name}:getState`);
1258
- this.registerMessageClass(classes.SetStoreStateMessage, `store:${store.name}:setState`);
1259
- this.registerMessageClass(
1260
- classes.SubscribeToStoreMessage,
1261
- `store:${store.name}:subscribe`
1262
- );
1263
- this.logger.debug(`\u2705 Initialized store: ${store.name}`);
1246
+ let isFirstStore = true;
1247
+ for (const store of this.storeDefinitions) {
1248
+ const diKey = `CentralStore:${store.def.name}`;
1249
+ const storeInstance = store.store;
1250
+ const classes = store.classes;
1251
+ IJob.container.bind(diKey).toConstantValue(storeInstance);
1252
+ if (isFirstStore) {
1253
+ IJob.container.bind(IJob.TOKENS.Store).toConstantValue(storeInstance);
1254
+ isFirstStore = false;
1264
1255
  }
1256
+ this.registerMessageClass(classes.GetStoreStateMessage, `store:${store.def.name}:getState`);
1257
+ this.registerMessageClass(classes.SetStoreStateMessage, `store:${store.def.name}:setState`);
1258
+ this.registerMessageClass(
1259
+ classes.SubscribeToStoreMessage,
1260
+ `store:${store.def.name}:subscribe`
1261
+ );
1262
+ this.logger.debug(`\u2705 Initialized store: ${store.def.name}`);
1265
1263
  }
1266
1264
  this.logger.success(`\u2705 Initialized ${this.storeDefinitions.length} store(s)`);
1267
1265
  } catch (error) {
@@ -1495,25 +1493,34 @@ class ApplicationBootstrap {
1495
1493
  }
1496
1494
  }
1497
1495
  class BootstrapLogger {
1496
+ constructor(enableLogs = true) {
1497
+ this.enableLogs = enableLogs;
1498
+ }
1498
1499
  info(message, context) {
1500
+ if (!this.enableLogs) return;
1499
1501
  console.log(message);
1500
1502
  if (context) console.log(" ", context);
1501
1503
  }
1502
1504
  success(message) {
1505
+ if (!this.enableLogs) return;
1503
1506
  console.log(message);
1504
1507
  }
1505
1508
  warn(message) {
1509
+ if (!this.enableLogs) return;
1506
1510
  console.warn(message);
1507
1511
  }
1508
1512
  error(message, error) {
1513
+ if (!this.enableLogs) return;
1509
1514
  console.error(message);
1510
1515
  if (error) console.error(" ", error);
1511
1516
  }
1512
1517
  debug(message, context) {
1518
+ if (!this.enableLogs) return;
1513
1519
  console.debug(message);
1514
1520
  if (context) console.debug(" ", context);
1515
1521
  }
1516
1522
  divider() {
1523
+ if (!this.enableLogs) return;
1517
1524
  console.log("=".repeat(50));
1518
1525
  }
1519
1526
  }
@@ -1543,9 +1550,10 @@ class BootstrapBuilder {
1543
1550
  */
1544
1551
  async create({
1545
1552
  keepPortAlive = false,
1546
- portName
1553
+ portName,
1554
+ enableLogs = true
1547
1555
  } = {}) {
1548
- await this.app.create({ keepPortAlive, portName });
1556
+ await this.app.create({ keepPortAlive, portName, enableLogs });
1549
1557
  }
1550
1558
  }
1551
1559