@chromahq/core 0.0.1 → 0.0.2
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 +92 -3
- package/dist/index.d.ts +17 -1
- package/dist/index.es.js +92 -4
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -230,7 +230,8 @@ class BridgeRuntimeManager {
|
|
|
230
230
|
this.logger.debug("\u{1F4E4} Response sent:", {
|
|
231
231
|
id: response.id,
|
|
232
232
|
hasData: !!response.data,
|
|
233
|
-
hasError: !!response.error
|
|
233
|
+
hasError: !!response.error,
|
|
234
|
+
data: response.data
|
|
234
235
|
});
|
|
235
236
|
} catch (error) {
|
|
236
237
|
this.logger.error("Failed to send response:", error);
|
|
@@ -278,8 +279,9 @@ class BridgeLogger {
|
|
|
278
279
|
if (context) console.debug(" Context:", context);
|
|
279
280
|
}
|
|
280
281
|
}
|
|
281
|
-
function bootstrap(options) {
|
|
282
|
+
function bootstrap$1(options) {
|
|
282
283
|
const runtime = new BridgeRuntimeManager(options);
|
|
284
|
+
console.debug("\u{1F309} Initializing Bridge Runtime with options:", options);
|
|
283
285
|
runtime.initialize();
|
|
284
286
|
}
|
|
285
287
|
|
|
@@ -1130,6 +1132,26 @@ class ApplicationBootstrap {
|
|
|
1130
1132
|
this.serviceDependencies = /* @__PURE__ */ new Map();
|
|
1131
1133
|
this.serviceRegistry = /* @__PURE__ */ new Map();
|
|
1132
1134
|
this.logger = new BootstrapLogger();
|
|
1135
|
+
this.storeDefinitions = [];
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Add a store definition to be initialized
|
|
1139
|
+
*/
|
|
1140
|
+
withStore(storeDefinition) {
|
|
1141
|
+
if (storeDefinition && storeDefinition.name) {
|
|
1142
|
+
this.storeDefinitions.push(storeDefinition);
|
|
1143
|
+
this.logger.debug(`\u{1F4E6} Added store definition: ${storeDefinition.name}`);
|
|
1144
|
+
}
|
|
1145
|
+
return this;
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Add multiple store definitions to be initialized
|
|
1149
|
+
*/
|
|
1150
|
+
withStores(storeDefinitions) {
|
|
1151
|
+
for (const store of storeDefinitions) {
|
|
1152
|
+
this.withStore(store);
|
|
1153
|
+
}
|
|
1154
|
+
return this;
|
|
1133
1155
|
}
|
|
1134
1156
|
/**
|
|
1135
1157
|
* Create and initialize a new Chroma application instance
|
|
@@ -1138,13 +1160,14 @@ class ApplicationBootstrap {
|
|
|
1138
1160
|
try {
|
|
1139
1161
|
this.logger.info("\u{1F680} Starting Chroma application bootstrap...");
|
|
1140
1162
|
await this.discoverServices();
|
|
1163
|
+
await this.discoverAndInitializeStores();
|
|
1141
1164
|
await this.validateDependencies();
|
|
1142
1165
|
await this.registerServices();
|
|
1143
1166
|
await this.registerMessages();
|
|
1144
1167
|
await this.registerJobs();
|
|
1145
1168
|
await this.bootMessages();
|
|
1146
1169
|
this.logger.success("\u{1F389} Chroma application initialization complete!");
|
|
1147
|
-
bootstrap({ container });
|
|
1170
|
+
bootstrap$1({ container });
|
|
1148
1171
|
} catch (error) {
|
|
1149
1172
|
this.logger.error("\u{1F4A5} Application bootstrap failed:", error);
|
|
1150
1173
|
throw error;
|
|
@@ -1179,6 +1202,34 @@ class ApplicationBootstrap {
|
|
|
1179
1202
|
}
|
|
1180
1203
|
this.logger.success(`\u2705 Discovered ${this.serviceDependencies.size} services`);
|
|
1181
1204
|
}
|
|
1205
|
+
/**
|
|
1206
|
+
* Initialize stores from provided definitions
|
|
1207
|
+
*/
|
|
1208
|
+
async discoverAndInitializeStores() {
|
|
1209
|
+
try {
|
|
1210
|
+
if (this.storeDefinitions.length === 0) {
|
|
1211
|
+
this.logger.debug("\u{1F4ED} No store definitions provided");
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
this.logger.info(`Initializing ${this.storeDefinitions.length} store(s)...`);
|
|
1215
|
+
const chromaGlobal = globalThis.__CHROMA__;
|
|
1216
|
+
if (chromaGlobal?.initStores && typeof chromaGlobal.initStores === "function") {
|
|
1217
|
+
for (const store of this.storeDefinitions) {
|
|
1218
|
+
const { classes } = await chromaGlobal.initStores(store);
|
|
1219
|
+
this.registerMessageClass(classes.GetStoreStateMessage, `store:${store.name}:getState`);
|
|
1220
|
+
this.registerMessageClass(classes.SetStoreStateMessage, `store:${store.name}:setState`);
|
|
1221
|
+
this.registerMessageClass(
|
|
1222
|
+
classes.SubscribeToStoreMessage,
|
|
1223
|
+
`store:${store.name}:subscribe`
|
|
1224
|
+
);
|
|
1225
|
+
this.logger.debug(`\u2705 Initialized store: ${store.name}`);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
this.logger.success(`\u2705 Initialized ${this.storeDefinitions.length} store(s)`);
|
|
1229
|
+
} catch (error) {
|
|
1230
|
+
this.logger.error("\u274C Failed to initialize stores:", error);
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1182
1233
|
/**
|
|
1183
1234
|
* Resolve service dependencies using reflection and fallback parsing
|
|
1184
1235
|
*/
|
|
@@ -1392,6 +1443,15 @@ class ApplicationBootstrap {
|
|
|
1392
1443
|
}
|
|
1393
1444
|
}
|
|
1394
1445
|
}
|
|
1446
|
+
async registerMessageClass(MessageClass, name) {
|
|
1447
|
+
const dependencies = this.resolveDependencies(MessageClass);
|
|
1448
|
+
b(L$1(), MessageClass);
|
|
1449
|
+
dependencies.forEach((dependency, index) => {
|
|
1450
|
+
b(_$1(dependency), MessageClass, index);
|
|
1451
|
+
});
|
|
1452
|
+
container.bind(name).to(MessageClass).inSingletonScope();
|
|
1453
|
+
this.logger.success(`\u2705 Registered message: ${name}`);
|
|
1454
|
+
}
|
|
1395
1455
|
/**
|
|
1396
1456
|
* Boot all registered messages
|
|
1397
1457
|
*/
|
|
@@ -1475,6 +1535,34 @@ async function create() {
|
|
|
1475
1535
|
const bootstrap2 = new ApplicationBootstrap();
|
|
1476
1536
|
await bootstrap2.create();
|
|
1477
1537
|
}
|
|
1538
|
+
function bootstrap() {
|
|
1539
|
+
return new BootstrapBuilder();
|
|
1540
|
+
}
|
|
1541
|
+
class BootstrapBuilder {
|
|
1542
|
+
constructor() {
|
|
1543
|
+
this.app = new ApplicationBootstrap();
|
|
1544
|
+
}
|
|
1545
|
+
/**
|
|
1546
|
+
* Add a store definition to be initialized
|
|
1547
|
+
*/
|
|
1548
|
+
withStore(storeDefinition) {
|
|
1549
|
+
this.app.withStore(storeDefinition);
|
|
1550
|
+
return this;
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* Add multiple store definitions to be initialized
|
|
1554
|
+
*/
|
|
1555
|
+
withStores(storeDefinitions) {
|
|
1556
|
+
this.app.withStores(storeDefinitions);
|
|
1557
|
+
return this;
|
|
1558
|
+
}
|
|
1559
|
+
/**
|
|
1560
|
+
* Create and start the application
|
|
1561
|
+
*/
|
|
1562
|
+
async create() {
|
|
1563
|
+
await this.app.create();
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1478
1566
|
|
|
1479
1567
|
class IMessage {
|
|
1480
1568
|
handle(...args) {
|
|
@@ -1551,6 +1639,7 @@ exports.JobState = JobState;
|
|
|
1551
1639
|
exports.METADATA_KEY = METADATA_KEY;
|
|
1552
1640
|
exports.Message = Message;
|
|
1553
1641
|
exports.bind = bind;
|
|
1642
|
+
exports.bootstrap = bootstrap;
|
|
1554
1643
|
exports.container = container;
|
|
1555
1644
|
exports.create = create;
|
|
1556
1645
|
exports.isBooteable = isBooteable;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,22 @@ declare const resolve: <T>(id: symbol | (new (...a: any[]) => T)) => T;
|
|
|
11
11
|
declare function isInjectable(target: any): boolean;
|
|
12
12
|
|
|
13
13
|
declare function create(): Promise<void>;
|
|
14
|
+
declare function bootstrap(): BootstrapBuilder;
|
|
15
|
+
declare class BootstrapBuilder {
|
|
16
|
+
private readonly app;
|
|
17
|
+
/**
|
|
18
|
+
* Add a store definition to be initialized
|
|
19
|
+
*/
|
|
20
|
+
withStore(storeDefinition: any): BootstrapBuilder;
|
|
21
|
+
/**
|
|
22
|
+
* Add multiple store definitions to be initialized
|
|
23
|
+
*/
|
|
24
|
+
withStores(storeDefinitions: any[]): BootstrapBuilder;
|
|
25
|
+
/**
|
|
26
|
+
* Create and start the application
|
|
27
|
+
*/
|
|
28
|
+
create(): Promise<void>;
|
|
29
|
+
}
|
|
14
30
|
|
|
15
31
|
declare abstract class IMessage {
|
|
16
32
|
handle(...args: any[]): Promise<void> | void;
|
|
@@ -105,5 +121,5 @@ declare const Delay: (ms: number) => (constructor: any) => any;
|
|
|
105
121
|
|
|
106
122
|
declare function Every(cron: string): (constructor: any) => any;
|
|
107
123
|
|
|
108
|
-
export { Booteable, Delay, Every, IMessage, Injectable, Job, JobState, METADATA_KEY, Message, bind, container, create, isBooteable, isDestroyable, isInjectable, resolve };
|
|
124
|
+
export { Booteable, Delay, Every, IMessage, Injectable, Job, JobState, METADATA_KEY, Message, bind, bootstrap, container, create, isBooteable, isDestroyable, isInjectable, resolve };
|
|
109
125
|
export type { IJob, JobContext };
|
package/dist/index.es.js
CHANGED
|
@@ -228,7 +228,8 @@ class BridgeRuntimeManager {
|
|
|
228
228
|
this.logger.debug("\u{1F4E4} Response sent:", {
|
|
229
229
|
id: response.id,
|
|
230
230
|
hasData: !!response.data,
|
|
231
|
-
hasError: !!response.error
|
|
231
|
+
hasError: !!response.error,
|
|
232
|
+
data: response.data
|
|
232
233
|
});
|
|
233
234
|
} catch (error) {
|
|
234
235
|
this.logger.error("Failed to send response:", error);
|
|
@@ -276,8 +277,9 @@ class BridgeLogger {
|
|
|
276
277
|
if (context) console.debug(" Context:", context);
|
|
277
278
|
}
|
|
278
279
|
}
|
|
279
|
-
function bootstrap(options) {
|
|
280
|
+
function bootstrap$1(options) {
|
|
280
281
|
const runtime = new BridgeRuntimeManager(options);
|
|
282
|
+
console.debug("\u{1F309} Initializing Bridge Runtime with options:", options);
|
|
281
283
|
runtime.initialize();
|
|
282
284
|
}
|
|
283
285
|
|
|
@@ -1128,6 +1130,26 @@ class ApplicationBootstrap {
|
|
|
1128
1130
|
this.serviceDependencies = /* @__PURE__ */ new Map();
|
|
1129
1131
|
this.serviceRegistry = /* @__PURE__ */ new Map();
|
|
1130
1132
|
this.logger = new BootstrapLogger();
|
|
1133
|
+
this.storeDefinitions = [];
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Add a store definition to be initialized
|
|
1137
|
+
*/
|
|
1138
|
+
withStore(storeDefinition) {
|
|
1139
|
+
if (storeDefinition && storeDefinition.name) {
|
|
1140
|
+
this.storeDefinitions.push(storeDefinition);
|
|
1141
|
+
this.logger.debug(`\u{1F4E6} Added store definition: ${storeDefinition.name}`);
|
|
1142
|
+
}
|
|
1143
|
+
return this;
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* Add multiple store definitions to be initialized
|
|
1147
|
+
*/
|
|
1148
|
+
withStores(storeDefinitions) {
|
|
1149
|
+
for (const store of storeDefinitions) {
|
|
1150
|
+
this.withStore(store);
|
|
1151
|
+
}
|
|
1152
|
+
return this;
|
|
1131
1153
|
}
|
|
1132
1154
|
/**
|
|
1133
1155
|
* Create and initialize a new Chroma application instance
|
|
@@ -1136,13 +1158,14 @@ class ApplicationBootstrap {
|
|
|
1136
1158
|
try {
|
|
1137
1159
|
this.logger.info("\u{1F680} Starting Chroma application bootstrap...");
|
|
1138
1160
|
await this.discoverServices();
|
|
1161
|
+
await this.discoverAndInitializeStores();
|
|
1139
1162
|
await this.validateDependencies();
|
|
1140
1163
|
await this.registerServices();
|
|
1141
1164
|
await this.registerMessages();
|
|
1142
1165
|
await this.registerJobs();
|
|
1143
1166
|
await this.bootMessages();
|
|
1144
1167
|
this.logger.success("\u{1F389} Chroma application initialization complete!");
|
|
1145
|
-
bootstrap({ container });
|
|
1168
|
+
bootstrap$1({ container });
|
|
1146
1169
|
} catch (error) {
|
|
1147
1170
|
this.logger.error("\u{1F4A5} Application bootstrap failed:", error);
|
|
1148
1171
|
throw error;
|
|
@@ -1177,6 +1200,34 @@ class ApplicationBootstrap {
|
|
|
1177
1200
|
}
|
|
1178
1201
|
this.logger.success(`\u2705 Discovered ${this.serviceDependencies.size} services`);
|
|
1179
1202
|
}
|
|
1203
|
+
/**
|
|
1204
|
+
* Initialize stores from provided definitions
|
|
1205
|
+
*/
|
|
1206
|
+
async discoverAndInitializeStores() {
|
|
1207
|
+
try {
|
|
1208
|
+
if (this.storeDefinitions.length === 0) {
|
|
1209
|
+
this.logger.debug("\u{1F4ED} No store definitions provided");
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
this.logger.info(`Initializing ${this.storeDefinitions.length} store(s)...`);
|
|
1213
|
+
const chromaGlobal = globalThis.__CHROMA__;
|
|
1214
|
+
if (chromaGlobal?.initStores && typeof chromaGlobal.initStores === "function") {
|
|
1215
|
+
for (const store of this.storeDefinitions) {
|
|
1216
|
+
const { classes } = await chromaGlobal.initStores(store);
|
|
1217
|
+
this.registerMessageClass(classes.GetStoreStateMessage, `store:${store.name}:getState`);
|
|
1218
|
+
this.registerMessageClass(classes.SetStoreStateMessage, `store:${store.name}:setState`);
|
|
1219
|
+
this.registerMessageClass(
|
|
1220
|
+
classes.SubscribeToStoreMessage,
|
|
1221
|
+
`store:${store.name}:subscribe`
|
|
1222
|
+
);
|
|
1223
|
+
this.logger.debug(`\u2705 Initialized store: ${store.name}`);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
this.logger.success(`\u2705 Initialized ${this.storeDefinitions.length} store(s)`);
|
|
1227
|
+
} catch (error) {
|
|
1228
|
+
this.logger.error("\u274C Failed to initialize stores:", error);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1180
1231
|
/**
|
|
1181
1232
|
* Resolve service dependencies using reflection and fallback parsing
|
|
1182
1233
|
*/
|
|
@@ -1390,6 +1441,15 @@ class ApplicationBootstrap {
|
|
|
1390
1441
|
}
|
|
1391
1442
|
}
|
|
1392
1443
|
}
|
|
1444
|
+
async registerMessageClass(MessageClass, name) {
|
|
1445
|
+
const dependencies = this.resolveDependencies(MessageClass);
|
|
1446
|
+
b(L$1(), MessageClass);
|
|
1447
|
+
dependencies.forEach((dependency, index) => {
|
|
1448
|
+
b(_$1(dependency), MessageClass, index);
|
|
1449
|
+
});
|
|
1450
|
+
container.bind(name).to(MessageClass).inSingletonScope();
|
|
1451
|
+
this.logger.success(`\u2705 Registered message: ${name}`);
|
|
1452
|
+
}
|
|
1393
1453
|
/**
|
|
1394
1454
|
* Boot all registered messages
|
|
1395
1455
|
*/
|
|
@@ -1473,6 +1533,34 @@ async function create() {
|
|
|
1473
1533
|
const bootstrap2 = new ApplicationBootstrap();
|
|
1474
1534
|
await bootstrap2.create();
|
|
1475
1535
|
}
|
|
1536
|
+
function bootstrap() {
|
|
1537
|
+
return new BootstrapBuilder();
|
|
1538
|
+
}
|
|
1539
|
+
class BootstrapBuilder {
|
|
1540
|
+
constructor() {
|
|
1541
|
+
this.app = new ApplicationBootstrap();
|
|
1542
|
+
}
|
|
1543
|
+
/**
|
|
1544
|
+
* Add a store definition to be initialized
|
|
1545
|
+
*/
|
|
1546
|
+
withStore(storeDefinition) {
|
|
1547
|
+
this.app.withStore(storeDefinition);
|
|
1548
|
+
return this;
|
|
1549
|
+
}
|
|
1550
|
+
/**
|
|
1551
|
+
* Add multiple store definitions to be initialized
|
|
1552
|
+
*/
|
|
1553
|
+
withStores(storeDefinitions) {
|
|
1554
|
+
this.app.withStores(storeDefinitions);
|
|
1555
|
+
return this;
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Create and start the application
|
|
1559
|
+
*/
|
|
1560
|
+
async create() {
|
|
1561
|
+
await this.app.create();
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1476
1564
|
|
|
1477
1565
|
class IMessage {
|
|
1478
1566
|
handle(...args) {
|
|
@@ -1538,4 +1626,4 @@ function Every(cron) {
|
|
|
1538
1626
|
};
|
|
1539
1627
|
}
|
|
1540
1628
|
|
|
1541
|
-
export { Booteable, Delay, Every, IMessage, _$1 as Inject, Injectable, Job, JobState, METADATA_KEY, Message, bind, container, create, isBooteable, isDestroyable, isInjectable, resolve };
|
|
1629
|
+
export { Booteable, Delay, Every, IMessage, _$1 as Inject, Injectable, Job, JobState, METADATA_KEY, Message, bind, bootstrap, container, create, isBooteable, isDestroyable, isInjectable, resolve };
|