@chromahq/core 0.1.13 → 0.1.14

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,20 @@ 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.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.name}:getState`);
1255
+ this.registerMessageClass(classes.SetStoreStateMessage, `store:${store.name}:setState`);
1256
+ this.registerMessageClass(classes.SubscribeToStoreMessage, `store:${store.name}:subscribe`);
1257
+ this.logger.debug(`\u2705 Initialized store: ${store.name}`);
1263
1258
  }
1264
1259
  this.logger.success(`\u2705 Initialized ${this.storeDefinitions.length} store(s)`);
1265
1260
  } catch (error) {
@@ -1493,25 +1488,34 @@ class ApplicationBootstrap {
1493
1488
  }
1494
1489
  }
1495
1490
  class BootstrapLogger {
1491
+ constructor(enableLogs = true) {
1492
+ this.enableLogs = enableLogs;
1493
+ }
1496
1494
  info(message, context) {
1495
+ if (!this.enableLogs) return;
1497
1496
  console.log(message);
1498
1497
  if (context) console.log(" ", context);
1499
1498
  }
1500
1499
  success(message) {
1500
+ if (!this.enableLogs) return;
1501
1501
  console.log(message);
1502
1502
  }
1503
1503
  warn(message) {
1504
+ if (!this.enableLogs) return;
1504
1505
  console.warn(message);
1505
1506
  }
1506
1507
  error(message, error) {
1508
+ if (!this.enableLogs) return;
1507
1509
  console.error(message);
1508
1510
  if (error) console.error(" ", error);
1509
1511
  }
1510
1512
  debug(message, context) {
1513
+ if (!this.enableLogs) return;
1511
1514
  console.debug(message);
1512
1515
  if (context) console.debug(" ", context);
1513
1516
  }
1514
1517
  divider() {
1518
+ if (!this.enableLogs) return;
1515
1519
  console.log("=".repeat(50));
1516
1520
  }
1517
1521
  }
@@ -1541,9 +1545,10 @@ class BootstrapBuilder {
1541
1545
  */
1542
1546
  async create({
1543
1547
  keepPortAlive = false,
1544
- portName
1548
+ portName,
1549
+ enableLogs = true
1545
1550
  } = {}) {
1546
- await this.app.create({ keepPortAlive, portName });
1551
+ await this.app.create({ keepPortAlive, portName, enableLogs });
1547
1552
  }
1548
1553
  }
1549
1554