@chromahq/core 0.1.7 → 0.1.9

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
@@ -1073,14 +1073,28 @@ function getNextCronDate(expr) {
1073
1073
  }
1074
1074
  }
1075
1075
 
1076
- class Scheduler {
1076
+ function Injectable() {
1077
+ return function(constructor) {
1078
+ L$1()(constructor);
1079
+ };
1080
+ }
1081
+
1082
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
1083
+ var __decorateClass = (decorators, target, key, kind) => {
1084
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
1085
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1086
+ if (decorator = decorators[i])
1087
+ result = (decorator(result)) || result;
1088
+ return result;
1089
+ };
1090
+ let Scheduler = class {
1077
1091
  constructor() {
1078
1092
  this.registry = JobRegistry.instance;
1079
1093
  this.alarm = new AlarmAdapter();
1080
1094
  this.timeout = new TimeoutAdapter();
1081
1095
  console.log("Scheduler initialized");
1082
- this.alarm.onTrigger((id) => this.execute(id));
1083
- this.timeout.onTrigger((id) => this.execute(id));
1096
+ this.alarm.onTrigger(this.execute.bind(this));
1097
+ this.timeout.onTrigger(this.execute.bind(this));
1084
1098
  }
1085
1099
  schedule(id, options) {
1086
1100
  const context = this.registry.getContext(id);
@@ -1090,7 +1104,6 @@ class Scheduler {
1090
1104
  }
1091
1105
  console.log(`Scheduling job ${id} with options:`, options);
1092
1106
  const when = this.getScheduleTime(options);
1093
- console.log(`Job ${id} will execute at:`, new Date(when).toISOString());
1094
1107
  const adapter = when - Date.now() < 6e4 ? this.timeout : this.alarm;
1095
1108
  const timerId = adapter.schedule(id, when);
1096
1109
  if (adapter === this.timeout) {
@@ -1127,7 +1140,9 @@ class Scheduler {
1127
1140
  try {
1128
1141
  this.registry.updateState(id, JobState.RUNNING);
1129
1142
  console.log(`Executing job ${id}`);
1130
- await job.handle(context);
1143
+ const jobInstance = container.get(id);
1144
+ console.log(jobInstance);
1145
+ await jobInstance.handle.bind(jobInstance).call(jobInstance, context);
1131
1146
  if (!context.isStopped() && !context.isPaused()) {
1132
1147
  this.registry.updateState(id, JobState.COMPLETED);
1133
1148
  const options = this.registry.meta(id);
@@ -1160,7 +1175,10 @@ class Scheduler {
1160
1175
  const jobs = [];
1161
1176
  return jobs;
1162
1177
  }
1163
- }
1178
+ };
1179
+ Scheduler = __decorateClass([
1180
+ Injectable()
1181
+ ], Scheduler);
1164
1182
 
1165
1183
  class ApplicationBootstrap {
1166
1184
  constructor() {
@@ -1217,6 +1235,7 @@ class ApplicationBootstrap {
1217
1235
  */
1218
1236
  async bootServices() {
1219
1237
  this.logger.info("\u{1F680} Booting services...");
1238
+ console.log("services", this.serviceRegistry.entries());
1220
1239
  for (const [serviceName, ServiceClass] of this.serviceRegistry.entries()) {
1221
1240
  try {
1222
1241
  const instance = container.get(ServiceClass);
@@ -1276,7 +1295,7 @@ class ApplicationBootstrap {
1276
1295
  const diKey = `CentralStore:${store.name}`;
1277
1296
  container.bind(diKey).toConstantValue(storeInstance);
1278
1297
  if (isFirstStore) {
1279
- container.bind("CentralStore").toConstantValue(storeInstance);
1298
+ container.bind("appStore").toConstantValue(storeInstance);
1280
1299
  isFirstStore = false;
1281
1300
  }
1282
1301
  this.registerMessageClass(classes.GetStoreStateMessage, `store:${store.name}:getState`);
@@ -1319,13 +1338,11 @@ class ApplicationBootstrap {
1319
1338
  const paramName = param.toLowerCase();
1320
1339
  if (paramName === "appstore") {
1321
1340
  let storeInstance;
1322
- if (paramName === "appstore" && container.isBound("CentralStore")) {
1323
- storeInstance = container.get("CentralStore");
1324
- if (!storeInstance) {
1325
- throw new Error(`No store found for parameter "${param}" in ${ServiceClass.name}`);
1326
- }
1327
- Reflect.defineMetadata("name", param, storeInstance);
1341
+ storeInstance = container.get("appStore");
1342
+ if (!storeInstance) {
1343
+ throw new Error(`No store found for parameter "${param}" in ${ServiceClass.name}`);
1328
1344
  }
1345
+ dependencies.push("appStore");
1329
1346
  continue;
1330
1347
  }
1331
1348
  const matchingService = Array.from(this.serviceRegistry.entries()).find(
@@ -1449,9 +1466,6 @@ class ApplicationBootstrap {
1449
1466
  serviceMetadata.dependencies.forEach((dependency, index) => {
1450
1467
  b(_$1(dependency), ServiceClass, index);
1451
1468
  });
1452
- if (container.isBound("CentralStore")) {
1453
- b(_$1("CentralStore"), ServiceClass, serviceMetadata.dependencies.length);
1454
- }
1455
1469
  container.bind(ServiceClass).toSelf().inSingletonScope();
1456
1470
  serviceMetadata.registered = true;
1457
1471
  this.logger.success(`\u2705 Registered service: ${ServiceClass.name}`);
@@ -1513,9 +1527,6 @@ class ApplicationBootstrap {
1513
1527
  dependencies.forEach((dependency, index) => {
1514
1528
  b(_$1(dependency), MessageClass, index);
1515
1529
  });
1516
- if (container.isBound("CentralStore")) {
1517
- b(_$1("CentralStore"), MessageClass, dependencies.length);
1518
- }
1519
1530
  const messageMetadata = Reflect.getMetadata("name", MessageClass);
1520
1531
  const messageName = messageMetadata || MessageClass.name;
1521
1532
  container.bind(messageName).to(MessageClass).inSingletonScope();
@@ -1562,9 +1573,11 @@ class ApplicationBootstrap {
1562
1573
  */
1563
1574
  async registerJobs() {
1564
1575
  this.logger.info("\u{1F552} Registering jobs...");
1565
- const jobModules = undefined("/src/app/jobs/*.job.{ts,js}", {
1566
- eager: true
1567
- });
1576
+ const jobModules = undefined(
1577
+ "/src/app/jobs/**/*.job.{ts,js}",
1578
+ { eager: true }
1579
+ );
1580
+ this.scheduler = new Scheduler();
1568
1581
  for (const module of Object.values(jobModules)) {
1569
1582
  const JobClass = module?.default;
1570
1583
  if (!JobClass) continue;
@@ -1574,16 +1587,13 @@ class ApplicationBootstrap {
1574
1587
  dependencies.forEach((dependency, index) => {
1575
1588
  b(_$1(dependency), JobClass, index);
1576
1589
  });
1577
- if (container.isBound("CentralStore")) {
1578
- b(_$1("CentralStore"), JobClass, dependencies.length);
1579
- }
1580
1590
  const jobMetadata = Reflect.getMetadata("name", JobClass);
1581
1591
  const jobName = jobMetadata || JobClass.name;
1582
1592
  container.bind(JobClass).toSelf().inSingletonScope();
1583
- const id = "12";
1593
+ const id = `${jobName.toLowerCase()}:${JobClass.name.toLowerCase()} ${Math.random().toString(36).substring(2, 15)}`;
1594
+ container.bind(id).to(JobClass).inSingletonScope();
1584
1595
  const options = Reflect.getMetadata("job:options", JobClass) || {};
1585
1596
  const instance = container.get(JobClass);
1586
- this.scheduler = new Scheduler();
1587
1597
  JobRegistry.instance.register(id, instance, options);
1588
1598
  this.scheduler.schedule(id, options);
1589
1599
  this.logger.success(`\u2705 Registered job: ${jobName}`);
@@ -1670,12 +1680,6 @@ function Message(name) {
1670
1680
  };
1671
1681
  }
1672
1682
 
1673
- function Injectable() {
1674
- return function(constructor) {
1675
- L$1()(constructor);
1676
- };
1677
- }
1678
-
1679
1683
  class Booteable {
1680
1684
  /**
1681
1685
  * Optional destroy method to be called when the service is being destroyed.
package/dist/index.es.js CHANGED
@@ -1071,14 +1071,28 @@ function getNextCronDate(expr) {
1071
1071
  }
1072
1072
  }
1073
1073
 
1074
- class Scheduler {
1074
+ function Injectable() {
1075
+ return function(constructor) {
1076
+ L$1()(constructor);
1077
+ };
1078
+ }
1079
+
1080
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
1081
+ var __decorateClass = (decorators, target, key, kind) => {
1082
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
1083
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1084
+ if (decorator = decorators[i])
1085
+ result = (decorator(result)) || result;
1086
+ return result;
1087
+ };
1088
+ let Scheduler = class {
1075
1089
  constructor() {
1076
1090
  this.registry = JobRegistry.instance;
1077
1091
  this.alarm = new AlarmAdapter();
1078
1092
  this.timeout = new TimeoutAdapter();
1079
1093
  console.log("Scheduler initialized");
1080
- this.alarm.onTrigger((id) => this.execute(id));
1081
- this.timeout.onTrigger((id) => this.execute(id));
1094
+ this.alarm.onTrigger(this.execute.bind(this));
1095
+ this.timeout.onTrigger(this.execute.bind(this));
1082
1096
  }
1083
1097
  schedule(id, options) {
1084
1098
  const context = this.registry.getContext(id);
@@ -1088,7 +1102,6 @@ class Scheduler {
1088
1102
  }
1089
1103
  console.log(`Scheduling job ${id} with options:`, options);
1090
1104
  const when = this.getScheduleTime(options);
1091
- console.log(`Job ${id} will execute at:`, new Date(when).toISOString());
1092
1105
  const adapter = when - Date.now() < 6e4 ? this.timeout : this.alarm;
1093
1106
  const timerId = adapter.schedule(id, when);
1094
1107
  if (adapter === this.timeout) {
@@ -1125,7 +1138,9 @@ class Scheduler {
1125
1138
  try {
1126
1139
  this.registry.updateState(id, JobState.RUNNING);
1127
1140
  console.log(`Executing job ${id}`);
1128
- await job.handle(context);
1141
+ const jobInstance = container.get(id);
1142
+ console.log(jobInstance);
1143
+ await jobInstance.handle.bind(jobInstance).call(jobInstance, context);
1129
1144
  if (!context.isStopped() && !context.isPaused()) {
1130
1145
  this.registry.updateState(id, JobState.COMPLETED);
1131
1146
  const options = this.registry.meta(id);
@@ -1158,7 +1173,10 @@ class Scheduler {
1158
1173
  const jobs = [];
1159
1174
  return jobs;
1160
1175
  }
1161
- }
1176
+ };
1177
+ Scheduler = __decorateClass([
1178
+ Injectable()
1179
+ ], Scheduler);
1162
1180
 
1163
1181
  class ApplicationBootstrap {
1164
1182
  constructor() {
@@ -1215,6 +1233,7 @@ class ApplicationBootstrap {
1215
1233
  */
1216
1234
  async bootServices() {
1217
1235
  this.logger.info("\u{1F680} Booting services...");
1236
+ console.log("services", this.serviceRegistry.entries());
1218
1237
  for (const [serviceName, ServiceClass] of this.serviceRegistry.entries()) {
1219
1238
  try {
1220
1239
  const instance = container.get(ServiceClass);
@@ -1274,7 +1293,7 @@ class ApplicationBootstrap {
1274
1293
  const diKey = `CentralStore:${store.name}`;
1275
1294
  container.bind(diKey).toConstantValue(storeInstance);
1276
1295
  if (isFirstStore) {
1277
- container.bind("CentralStore").toConstantValue(storeInstance);
1296
+ container.bind("appStore").toConstantValue(storeInstance);
1278
1297
  isFirstStore = false;
1279
1298
  }
1280
1299
  this.registerMessageClass(classes.GetStoreStateMessage, `store:${store.name}:getState`);
@@ -1317,13 +1336,11 @@ class ApplicationBootstrap {
1317
1336
  const paramName = param.toLowerCase();
1318
1337
  if (paramName === "appstore") {
1319
1338
  let storeInstance;
1320
- if (paramName === "appstore" && container.isBound("CentralStore")) {
1321
- storeInstance = container.get("CentralStore");
1322
- if (!storeInstance) {
1323
- throw new Error(`No store found for parameter "${param}" in ${ServiceClass.name}`);
1324
- }
1325
- Reflect.defineMetadata("name", param, storeInstance);
1339
+ storeInstance = container.get("appStore");
1340
+ if (!storeInstance) {
1341
+ throw new Error(`No store found for parameter "${param}" in ${ServiceClass.name}`);
1326
1342
  }
1343
+ dependencies.push("appStore");
1327
1344
  continue;
1328
1345
  }
1329
1346
  const matchingService = Array.from(this.serviceRegistry.entries()).find(
@@ -1447,9 +1464,6 @@ class ApplicationBootstrap {
1447
1464
  serviceMetadata.dependencies.forEach((dependency, index) => {
1448
1465
  b(_$1(dependency), ServiceClass, index);
1449
1466
  });
1450
- if (container.isBound("CentralStore")) {
1451
- b(_$1("CentralStore"), ServiceClass, serviceMetadata.dependencies.length);
1452
- }
1453
1467
  container.bind(ServiceClass).toSelf().inSingletonScope();
1454
1468
  serviceMetadata.registered = true;
1455
1469
  this.logger.success(`\u2705 Registered service: ${ServiceClass.name}`);
@@ -1511,9 +1525,6 @@ class ApplicationBootstrap {
1511
1525
  dependencies.forEach((dependency, index) => {
1512
1526
  b(_$1(dependency), MessageClass, index);
1513
1527
  });
1514
- if (container.isBound("CentralStore")) {
1515
- b(_$1("CentralStore"), MessageClass, dependencies.length);
1516
- }
1517
1528
  const messageMetadata = Reflect.getMetadata("name", MessageClass);
1518
1529
  const messageName = messageMetadata || MessageClass.name;
1519
1530
  container.bind(messageName).to(MessageClass).inSingletonScope();
@@ -1560,9 +1571,11 @@ class ApplicationBootstrap {
1560
1571
  */
1561
1572
  async registerJobs() {
1562
1573
  this.logger.info("\u{1F552} Registering jobs...");
1563
- const jobModules = import.meta.glob("/src/app/jobs/*.job.{ts,js}", {
1564
- eager: true
1565
- });
1574
+ const jobModules = import.meta.glob(
1575
+ "/src/app/jobs/**/*.job.{ts,js}",
1576
+ { eager: true }
1577
+ );
1578
+ this.scheduler = new Scheduler();
1566
1579
  for (const module of Object.values(jobModules)) {
1567
1580
  const JobClass = module?.default;
1568
1581
  if (!JobClass) continue;
@@ -1572,16 +1585,13 @@ class ApplicationBootstrap {
1572
1585
  dependencies.forEach((dependency, index) => {
1573
1586
  b(_$1(dependency), JobClass, index);
1574
1587
  });
1575
- if (container.isBound("CentralStore")) {
1576
- b(_$1("CentralStore"), JobClass, dependencies.length);
1577
- }
1578
1588
  const jobMetadata = Reflect.getMetadata("name", JobClass);
1579
1589
  const jobName = jobMetadata || JobClass.name;
1580
1590
  container.bind(JobClass).toSelf().inSingletonScope();
1581
- const id = "12";
1591
+ const id = `${jobName.toLowerCase()}:${JobClass.name.toLowerCase()} ${Math.random().toString(36).substring(2, 15)}`;
1592
+ container.bind(id).to(JobClass).inSingletonScope();
1582
1593
  const options = Reflect.getMetadata("job:options", JobClass) || {};
1583
1594
  const instance = container.get(JobClass);
1584
- this.scheduler = new Scheduler();
1585
1595
  JobRegistry.instance.register(id, instance, options);
1586
1596
  this.scheduler.schedule(id, options);
1587
1597
  this.logger.success(`\u2705 Registered job: ${jobName}`);
@@ -1668,12 +1678,6 @@ function Message(name) {
1668
1678
  };
1669
1679
  }
1670
1680
 
1671
- function Injectable() {
1672
- return function(constructor) {
1673
- L$1()(constructor);
1674
- };
1675
- }
1676
-
1677
1681
  class Booteable {
1678
1682
  /**
1679
1683
  * Optional destroy method to be called when the service is being destroyed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromahq/core",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Core library for building Chrome extensions with Chroma framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",