@chromahq/core 0.1.6 → 0.1.8

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 CHANGED
@@ -1079,8 +1079,8 @@ class Scheduler {
1079
1079
  this.alarm = new AlarmAdapter();
1080
1080
  this.timeout = new TimeoutAdapter();
1081
1081
  console.log("Scheduler initialized");
1082
- this.alarm.onTrigger((id) => this.execute(id));
1083
- this.timeout.onTrigger((id) => this.execute(id));
1082
+ this.alarm.onTrigger(this.execute.bind(this));
1083
+ this.timeout.onTrigger(this.execute.bind(this));
1084
1084
  }
1085
1085
  schedule(id, options) {
1086
1086
  const context = this.registry.getContext(id);
@@ -1090,7 +1090,6 @@ class Scheduler {
1090
1090
  }
1091
1091
  console.log(`Scheduling job ${id} with options:`, options);
1092
1092
  const when = this.getScheduleTime(options);
1093
- console.log(`Job ${id} will execute at:`, new Date(when).toISOString());
1094
1093
  const adapter = when - Date.now() < 6e4 ? this.timeout : this.alarm;
1095
1094
  const timerId = adapter.schedule(id, when);
1096
1095
  if (adapter === this.timeout) {
@@ -1127,7 +1126,7 @@ class Scheduler {
1127
1126
  try {
1128
1127
  this.registry.updateState(id, JobState.RUNNING);
1129
1128
  console.log(`Executing job ${id}`);
1130
- await job.handle(context);
1129
+ await job.handle.call(job, context);
1131
1130
  if (!context.isStopped() && !context.isPaused()) {
1132
1131
  this.registry.updateState(id, JobState.COMPLETED);
1133
1132
  const options = this.registry.meta(id);
@@ -1317,24 +1316,15 @@ class ApplicationBootstrap {
1317
1316
  const dependencies = [];
1318
1317
  for (const param of parameters) {
1319
1318
  const paramName = param.toLowerCase();
1320
- if (paramName === "store" || paramName.startsWith("store")) {
1319
+ if (paramName === "appstore") {
1321
1320
  let storeInstance;
1322
- if (paramName === "store" && container.isBound("CentralStore")) {
1321
+ if (paramName === "appstore" && container.isBound("CentralStore")) {
1323
1322
  storeInstance = container.get("CentralStore");
1324
- } else {
1325
- const storeKeyMatch = paramName.match(/^store(.+)$/);
1326
- if (storeKeyMatch && storeKeyMatch[1]) {
1327
- const storeName = storeKeyMatch[1].replace(/^([A-Z])/, (m) => m.toLowerCase());
1328
- const diKey = `CentralStore:${storeName}`;
1329
- if (container.isBound(diKey)) {
1330
- storeInstance = container.get(diKey);
1331
- }
1323
+ if (!storeInstance) {
1324
+ throw new Error(`No store found for parameter "${param}" in ${ServiceClass.name}`);
1332
1325
  }
1326
+ Reflect.defineMetadata("name", param, storeInstance);
1333
1327
  }
1334
- if (!storeInstance) {
1335
- this.logger.warn(`\u26A0\uFE0F No store found for parameter "${param}" in ${ServiceClass.name}`);
1336
- }
1337
- dependencies.push(storeInstance);
1338
1328
  continue;
1339
1329
  }
1340
1330
  const matchingService = Array.from(this.serviceRegistry.entries()).find(
@@ -1458,6 +1448,9 @@ class ApplicationBootstrap {
1458
1448
  serviceMetadata.dependencies.forEach((dependency, index) => {
1459
1449
  b(_$1(dependency), ServiceClass, index);
1460
1450
  });
1451
+ if (container.isBound("CentralStore")) {
1452
+ b(_$1("CentralStore"), ServiceClass, serviceMetadata.dependencies.length);
1453
+ }
1461
1454
  container.bind(ServiceClass).toSelf().inSingletonScope();
1462
1455
  serviceMetadata.registered = true;
1463
1456
  this.logger.success(`\u2705 Registered service: ${ServiceClass.name}`);
@@ -1519,6 +1512,9 @@ class ApplicationBootstrap {
1519
1512
  dependencies.forEach((dependency, index) => {
1520
1513
  b(_$1(dependency), MessageClass, index);
1521
1514
  });
1515
+ if (container.isBound("CentralStore")) {
1516
+ b(_$1("CentralStore"), MessageClass, dependencies.length);
1517
+ }
1522
1518
  const messageMetadata = Reflect.getMetadata("name", MessageClass);
1523
1519
  const messageName = messageMetadata || MessageClass.name;
1524
1520
  container.bind(messageName).to(MessageClass).inSingletonScope();
@@ -1565,9 +1561,11 @@ class ApplicationBootstrap {
1565
1561
  */
1566
1562
  async registerJobs() {
1567
1563
  this.logger.info("\u{1F552} Registering jobs...");
1568
- const jobModules = undefined("/src/app/jobs/*.job.{ts,js}", {
1569
- eager: true
1570
- });
1564
+ const jobModules = undefined(
1565
+ "/src/app/jobs/**/*.job.{ts,js}",
1566
+ { eager: true }
1567
+ );
1568
+ this.scheduler = new Scheduler();
1571
1569
  for (const module of Object.values(jobModules)) {
1572
1570
  const JobClass = module?.default;
1573
1571
  if (!JobClass) continue;
@@ -1577,13 +1575,15 @@ class ApplicationBootstrap {
1577
1575
  dependencies.forEach((dependency, index) => {
1578
1576
  b(_$1(dependency), JobClass, index);
1579
1577
  });
1578
+ if (container.isBound("CentralStore")) {
1579
+ b(_$1("CentralStore"), JobClass, dependencies.length);
1580
+ }
1580
1581
  const jobMetadata = Reflect.getMetadata("name", JobClass);
1581
1582
  const jobName = jobMetadata || JobClass.name;
1582
1583
  container.bind(JobClass).toSelf().inSingletonScope();
1583
- const id = "12";
1584
+ const id = `${jobName.toLowerCase()}:${JobClass.name.toLowerCase()} ${Math.random().toString(36).substring(2, 15)}`;
1584
1585
  const options = Reflect.getMetadata("job:options", JobClass) || {};
1585
1586
  const instance = container.get(JobClass);
1586
- this.scheduler = new Scheduler();
1587
1587
  JobRegistry.instance.register(id, instance, options);
1588
1588
  this.scheduler.schedule(id, options);
1589
1589
  this.logger.success(`\u2705 Registered job: ${jobName}`);
package/dist/index.es.js CHANGED
@@ -1077,8 +1077,8 @@ class Scheduler {
1077
1077
  this.alarm = new AlarmAdapter();
1078
1078
  this.timeout = new TimeoutAdapter();
1079
1079
  console.log("Scheduler initialized");
1080
- this.alarm.onTrigger((id) => this.execute(id));
1081
- this.timeout.onTrigger((id) => this.execute(id));
1080
+ this.alarm.onTrigger(this.execute.bind(this));
1081
+ this.timeout.onTrigger(this.execute.bind(this));
1082
1082
  }
1083
1083
  schedule(id, options) {
1084
1084
  const context = this.registry.getContext(id);
@@ -1088,7 +1088,6 @@ class Scheduler {
1088
1088
  }
1089
1089
  console.log(`Scheduling job ${id} with options:`, options);
1090
1090
  const when = this.getScheduleTime(options);
1091
- console.log(`Job ${id} will execute at:`, new Date(when).toISOString());
1092
1091
  const adapter = when - Date.now() < 6e4 ? this.timeout : this.alarm;
1093
1092
  const timerId = adapter.schedule(id, when);
1094
1093
  if (adapter === this.timeout) {
@@ -1125,7 +1124,7 @@ class Scheduler {
1125
1124
  try {
1126
1125
  this.registry.updateState(id, JobState.RUNNING);
1127
1126
  console.log(`Executing job ${id}`);
1128
- await job.handle(context);
1127
+ await job.handle.call(job, context);
1129
1128
  if (!context.isStopped() && !context.isPaused()) {
1130
1129
  this.registry.updateState(id, JobState.COMPLETED);
1131
1130
  const options = this.registry.meta(id);
@@ -1315,24 +1314,15 @@ class ApplicationBootstrap {
1315
1314
  const dependencies = [];
1316
1315
  for (const param of parameters) {
1317
1316
  const paramName = param.toLowerCase();
1318
- if (paramName === "store" || paramName.startsWith("store")) {
1317
+ if (paramName === "appstore") {
1319
1318
  let storeInstance;
1320
- if (paramName === "store" && container.isBound("CentralStore")) {
1319
+ if (paramName === "appstore" && container.isBound("CentralStore")) {
1321
1320
  storeInstance = container.get("CentralStore");
1322
- } else {
1323
- const storeKeyMatch = paramName.match(/^store(.+)$/);
1324
- if (storeKeyMatch && storeKeyMatch[1]) {
1325
- const storeName = storeKeyMatch[1].replace(/^([A-Z])/, (m) => m.toLowerCase());
1326
- const diKey = `CentralStore:${storeName}`;
1327
- if (container.isBound(diKey)) {
1328
- storeInstance = container.get(diKey);
1329
- }
1321
+ if (!storeInstance) {
1322
+ throw new Error(`No store found for parameter "${param}" in ${ServiceClass.name}`);
1330
1323
  }
1324
+ Reflect.defineMetadata("name", param, storeInstance);
1331
1325
  }
1332
- if (!storeInstance) {
1333
- this.logger.warn(`\u26A0\uFE0F No store found for parameter "${param}" in ${ServiceClass.name}`);
1334
- }
1335
- dependencies.push(storeInstance);
1336
1326
  continue;
1337
1327
  }
1338
1328
  const matchingService = Array.from(this.serviceRegistry.entries()).find(
@@ -1456,6 +1446,9 @@ class ApplicationBootstrap {
1456
1446
  serviceMetadata.dependencies.forEach((dependency, index) => {
1457
1447
  b(_$1(dependency), ServiceClass, index);
1458
1448
  });
1449
+ if (container.isBound("CentralStore")) {
1450
+ b(_$1("CentralStore"), ServiceClass, serviceMetadata.dependencies.length);
1451
+ }
1459
1452
  container.bind(ServiceClass).toSelf().inSingletonScope();
1460
1453
  serviceMetadata.registered = true;
1461
1454
  this.logger.success(`\u2705 Registered service: ${ServiceClass.name}`);
@@ -1517,6 +1510,9 @@ class ApplicationBootstrap {
1517
1510
  dependencies.forEach((dependency, index) => {
1518
1511
  b(_$1(dependency), MessageClass, index);
1519
1512
  });
1513
+ if (container.isBound("CentralStore")) {
1514
+ b(_$1("CentralStore"), MessageClass, dependencies.length);
1515
+ }
1520
1516
  const messageMetadata = Reflect.getMetadata("name", MessageClass);
1521
1517
  const messageName = messageMetadata || MessageClass.name;
1522
1518
  container.bind(messageName).to(MessageClass).inSingletonScope();
@@ -1563,9 +1559,11 @@ class ApplicationBootstrap {
1563
1559
  */
1564
1560
  async registerJobs() {
1565
1561
  this.logger.info("\u{1F552} Registering jobs...");
1566
- const jobModules = import.meta.glob("/src/app/jobs/*.job.{ts,js}", {
1567
- eager: true
1568
- });
1562
+ const jobModules = import.meta.glob(
1563
+ "/src/app/jobs/**/*.job.{ts,js}",
1564
+ { eager: true }
1565
+ );
1566
+ this.scheduler = new Scheduler();
1569
1567
  for (const module of Object.values(jobModules)) {
1570
1568
  const JobClass = module?.default;
1571
1569
  if (!JobClass) continue;
@@ -1575,13 +1573,15 @@ class ApplicationBootstrap {
1575
1573
  dependencies.forEach((dependency, index) => {
1576
1574
  b(_$1(dependency), JobClass, index);
1577
1575
  });
1576
+ if (container.isBound("CentralStore")) {
1577
+ b(_$1("CentralStore"), JobClass, dependencies.length);
1578
+ }
1578
1579
  const jobMetadata = Reflect.getMetadata("name", JobClass);
1579
1580
  const jobName = jobMetadata || JobClass.name;
1580
1581
  container.bind(JobClass).toSelf().inSingletonScope();
1581
- const id = "12";
1582
+ const id = `${jobName.toLowerCase()}:${JobClass.name.toLowerCase()} ${Math.random().toString(36).substring(2, 15)}`;
1582
1583
  const options = Reflect.getMetadata("job:options", JobClass) || {};
1583
1584
  const instance = container.get(JobClass);
1584
- this.scheduler = new Scheduler();
1585
1585
  JobRegistry.instance.register(id, instance, options);
1586
1586
  this.scheduler.schedule(id, options);
1587
1587
  this.logger.success(`\u2705 Registered job: ${jobName}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromahq/core",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Core library for building Chrome extensions with Chroma framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",