@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.cjs.js +32 -27
- package/dist/boot.cjs.js.map +1 -1
- package/dist/boot.d.ts +2 -1
- package/dist/boot.es.js +32 -27
- package/dist/boot.es.js.map +1 -1
- package/dist/index.cjs.js +1 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.es.js +1 -1
- package/package.json +1 -1
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.
|
|
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
|
-
|
|
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,20 @@ class ApplicationBootstrap {
|
|
|
1243
1243
|
return;
|
|
1244
1244
|
}
|
|
1245
1245
|
this.logger.info(`Initializing ${this.storeDefinitions.length} store(s)...`);
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
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.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.name}:getState`);
|
|
1257
|
+
this.registerMessageClass(classes.SetStoreStateMessage, `store:${store.name}:setState`);
|
|
1258
|
+
this.registerMessageClass(classes.SubscribeToStoreMessage, `store:${store.name}:subscribe`);
|
|
1259
|
+
this.logger.debug(`\u2705 Initialized store: ${store.name}`);
|
|
1265
1260
|
}
|
|
1266
1261
|
this.logger.success(`\u2705 Initialized ${this.storeDefinitions.length} store(s)`);
|
|
1267
1262
|
} catch (error) {
|
|
@@ -1495,25 +1490,34 @@ class ApplicationBootstrap {
|
|
|
1495
1490
|
}
|
|
1496
1491
|
}
|
|
1497
1492
|
class BootstrapLogger {
|
|
1493
|
+
constructor(enableLogs = true) {
|
|
1494
|
+
this.enableLogs = enableLogs;
|
|
1495
|
+
}
|
|
1498
1496
|
info(message, context) {
|
|
1497
|
+
if (!this.enableLogs) return;
|
|
1499
1498
|
console.log(message);
|
|
1500
1499
|
if (context) console.log(" ", context);
|
|
1501
1500
|
}
|
|
1502
1501
|
success(message) {
|
|
1502
|
+
if (!this.enableLogs) return;
|
|
1503
1503
|
console.log(message);
|
|
1504
1504
|
}
|
|
1505
1505
|
warn(message) {
|
|
1506
|
+
if (!this.enableLogs) return;
|
|
1506
1507
|
console.warn(message);
|
|
1507
1508
|
}
|
|
1508
1509
|
error(message, error) {
|
|
1510
|
+
if (!this.enableLogs) return;
|
|
1509
1511
|
console.error(message);
|
|
1510
1512
|
if (error) console.error(" ", error);
|
|
1511
1513
|
}
|
|
1512
1514
|
debug(message, context) {
|
|
1515
|
+
if (!this.enableLogs) return;
|
|
1513
1516
|
console.debug(message);
|
|
1514
1517
|
if (context) console.debug(" ", context);
|
|
1515
1518
|
}
|
|
1516
1519
|
divider() {
|
|
1520
|
+
if (!this.enableLogs) return;
|
|
1517
1521
|
console.log("=".repeat(50));
|
|
1518
1522
|
}
|
|
1519
1523
|
}
|
|
@@ -1543,9 +1547,10 @@ class BootstrapBuilder {
|
|
|
1543
1547
|
*/
|
|
1544
1548
|
async create({
|
|
1545
1549
|
keepPortAlive = false,
|
|
1546
|
-
portName
|
|
1550
|
+
portName,
|
|
1551
|
+
enableLogs = true
|
|
1547
1552
|
} = {}) {
|
|
1548
|
-
await this.app.create({ keepPortAlive, portName });
|
|
1553
|
+
await this.app.create({ keepPortAlive, portName, enableLogs });
|
|
1549
1554
|
}
|
|
1550
1555
|
}
|
|
1551
1556
|
|