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