@chromahq/core 0.1.8 → 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,7 +1073,21 @@ 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();
@@ -1126,7 +1140,9 @@ class Scheduler {
1126
1140
  try {
1127
1141
  this.registry.updateState(id, JobState.RUNNING);
1128
1142
  console.log(`Executing job ${id}`);
1129
- await job.handle.call(job, context);
1143
+ const jobInstance = container.get(id);
1144
+ console.log(jobInstance);
1145
+ await jobInstance.handle.bind(jobInstance).call(jobInstance, context);
1130
1146
  if (!context.isStopped() && !context.isPaused()) {
1131
1147
  this.registry.updateState(id, JobState.COMPLETED);
1132
1148
  const options = this.registry.meta(id);
@@ -1159,7 +1175,10 @@ class Scheduler {
1159
1175
  const jobs = [];
1160
1176
  return jobs;
1161
1177
  }
1162
- }
1178
+ };
1179
+ Scheduler = __decorateClass([
1180
+ Injectable()
1181
+ ], Scheduler);
1163
1182
 
1164
1183
  class ApplicationBootstrap {
1165
1184
  constructor() {
@@ -1216,6 +1235,7 @@ class ApplicationBootstrap {
1216
1235
  */
1217
1236
  async bootServices() {
1218
1237
  this.logger.info("\u{1F680} Booting services...");
1238
+ console.log("services", this.serviceRegistry.entries());
1219
1239
  for (const [serviceName, ServiceClass] of this.serviceRegistry.entries()) {
1220
1240
  try {
1221
1241
  const instance = container.get(ServiceClass);
@@ -1275,7 +1295,7 @@ class ApplicationBootstrap {
1275
1295
  const diKey = `CentralStore:${store.name}`;
1276
1296
  container.bind(diKey).toConstantValue(storeInstance);
1277
1297
  if (isFirstStore) {
1278
- container.bind("CentralStore").toConstantValue(storeInstance);
1298
+ container.bind("appStore").toConstantValue(storeInstance);
1279
1299
  isFirstStore = false;
1280
1300
  }
1281
1301
  this.registerMessageClass(classes.GetStoreStateMessage, `store:${store.name}:getState`);
@@ -1318,13 +1338,11 @@ class ApplicationBootstrap {
1318
1338
  const paramName = param.toLowerCase();
1319
1339
  if (paramName === "appstore") {
1320
1340
  let storeInstance;
1321
- if (paramName === "appstore" && container.isBound("CentralStore")) {
1322
- storeInstance = container.get("CentralStore");
1323
- if (!storeInstance) {
1324
- throw new Error(`No store found for parameter "${param}" in ${ServiceClass.name}`);
1325
- }
1326
- 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}`);
1327
1344
  }
1345
+ dependencies.push("appStore");
1328
1346
  continue;
1329
1347
  }
1330
1348
  const matchingService = Array.from(this.serviceRegistry.entries()).find(
@@ -1448,9 +1466,6 @@ class ApplicationBootstrap {
1448
1466
  serviceMetadata.dependencies.forEach((dependency, index) => {
1449
1467
  b(_$1(dependency), ServiceClass, index);
1450
1468
  });
1451
- if (container.isBound("CentralStore")) {
1452
- b(_$1("CentralStore"), ServiceClass, serviceMetadata.dependencies.length);
1453
- }
1454
1469
  container.bind(ServiceClass).toSelf().inSingletonScope();
1455
1470
  serviceMetadata.registered = true;
1456
1471
  this.logger.success(`\u2705 Registered service: ${ServiceClass.name}`);
@@ -1512,9 +1527,6 @@ class ApplicationBootstrap {
1512
1527
  dependencies.forEach((dependency, index) => {
1513
1528
  b(_$1(dependency), MessageClass, index);
1514
1529
  });
1515
- if (container.isBound("CentralStore")) {
1516
- b(_$1("CentralStore"), MessageClass, dependencies.length);
1517
- }
1518
1530
  const messageMetadata = Reflect.getMetadata("name", MessageClass);
1519
1531
  const messageName = messageMetadata || MessageClass.name;
1520
1532
  container.bind(messageName).to(MessageClass).inSingletonScope();
@@ -1575,13 +1587,11 @@ class ApplicationBootstrap {
1575
1587
  dependencies.forEach((dependency, index) => {
1576
1588
  b(_$1(dependency), JobClass, index);
1577
1589
  });
1578
- if (container.isBound("CentralStore")) {
1579
- b(_$1("CentralStore"), JobClass, dependencies.length);
1580
- }
1581
1590
  const jobMetadata = Reflect.getMetadata("name", JobClass);
1582
1591
  const jobName = jobMetadata || JobClass.name;
1583
1592
  container.bind(JobClass).toSelf().inSingletonScope();
1584
1593
  const id = `${jobName.toLowerCase()}:${JobClass.name.toLowerCase()} ${Math.random().toString(36).substring(2, 15)}`;
1594
+ container.bind(id).to(JobClass).inSingletonScope();
1585
1595
  const options = Reflect.getMetadata("job:options", JobClass) || {};
1586
1596
  const instance = container.get(JobClass);
1587
1597
  JobRegistry.instance.register(id, instance, options);
@@ -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,7 +1071,21 @@ 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();
@@ -1124,7 +1138,9 @@ class Scheduler {
1124
1138
  try {
1125
1139
  this.registry.updateState(id, JobState.RUNNING);
1126
1140
  console.log(`Executing job ${id}`);
1127
- await job.handle.call(job, context);
1141
+ const jobInstance = container.get(id);
1142
+ console.log(jobInstance);
1143
+ await jobInstance.handle.bind(jobInstance).call(jobInstance, context);
1128
1144
  if (!context.isStopped() && !context.isPaused()) {
1129
1145
  this.registry.updateState(id, JobState.COMPLETED);
1130
1146
  const options = this.registry.meta(id);
@@ -1157,7 +1173,10 @@ class Scheduler {
1157
1173
  const jobs = [];
1158
1174
  return jobs;
1159
1175
  }
1160
- }
1176
+ };
1177
+ Scheduler = __decorateClass([
1178
+ Injectable()
1179
+ ], Scheduler);
1161
1180
 
1162
1181
  class ApplicationBootstrap {
1163
1182
  constructor() {
@@ -1214,6 +1233,7 @@ class ApplicationBootstrap {
1214
1233
  */
1215
1234
  async bootServices() {
1216
1235
  this.logger.info("\u{1F680} Booting services...");
1236
+ console.log("services", this.serviceRegistry.entries());
1217
1237
  for (const [serviceName, ServiceClass] of this.serviceRegistry.entries()) {
1218
1238
  try {
1219
1239
  const instance = container.get(ServiceClass);
@@ -1273,7 +1293,7 @@ class ApplicationBootstrap {
1273
1293
  const diKey = `CentralStore:${store.name}`;
1274
1294
  container.bind(diKey).toConstantValue(storeInstance);
1275
1295
  if (isFirstStore) {
1276
- container.bind("CentralStore").toConstantValue(storeInstance);
1296
+ container.bind("appStore").toConstantValue(storeInstance);
1277
1297
  isFirstStore = false;
1278
1298
  }
1279
1299
  this.registerMessageClass(classes.GetStoreStateMessage, `store:${store.name}:getState`);
@@ -1316,13 +1336,11 @@ class ApplicationBootstrap {
1316
1336
  const paramName = param.toLowerCase();
1317
1337
  if (paramName === "appstore") {
1318
1338
  let storeInstance;
1319
- if (paramName === "appstore" && container.isBound("CentralStore")) {
1320
- storeInstance = container.get("CentralStore");
1321
- if (!storeInstance) {
1322
- throw new Error(`No store found for parameter "${param}" in ${ServiceClass.name}`);
1323
- }
1324
- 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}`);
1325
1342
  }
1343
+ dependencies.push("appStore");
1326
1344
  continue;
1327
1345
  }
1328
1346
  const matchingService = Array.from(this.serviceRegistry.entries()).find(
@@ -1446,9 +1464,6 @@ class ApplicationBootstrap {
1446
1464
  serviceMetadata.dependencies.forEach((dependency, index) => {
1447
1465
  b(_$1(dependency), ServiceClass, index);
1448
1466
  });
1449
- if (container.isBound("CentralStore")) {
1450
- b(_$1("CentralStore"), ServiceClass, serviceMetadata.dependencies.length);
1451
- }
1452
1467
  container.bind(ServiceClass).toSelf().inSingletonScope();
1453
1468
  serviceMetadata.registered = true;
1454
1469
  this.logger.success(`\u2705 Registered service: ${ServiceClass.name}`);
@@ -1510,9 +1525,6 @@ class ApplicationBootstrap {
1510
1525
  dependencies.forEach((dependency, index) => {
1511
1526
  b(_$1(dependency), MessageClass, index);
1512
1527
  });
1513
- if (container.isBound("CentralStore")) {
1514
- b(_$1("CentralStore"), MessageClass, dependencies.length);
1515
- }
1516
1528
  const messageMetadata = Reflect.getMetadata("name", MessageClass);
1517
1529
  const messageName = messageMetadata || MessageClass.name;
1518
1530
  container.bind(messageName).to(MessageClass).inSingletonScope();
@@ -1573,13 +1585,11 @@ class ApplicationBootstrap {
1573
1585
  dependencies.forEach((dependency, index) => {
1574
1586
  b(_$1(dependency), JobClass, index);
1575
1587
  });
1576
- if (container.isBound("CentralStore")) {
1577
- b(_$1("CentralStore"), JobClass, dependencies.length);
1578
- }
1579
1588
  const jobMetadata = Reflect.getMetadata("name", JobClass);
1580
1589
  const jobName = jobMetadata || JobClass.name;
1581
1590
  container.bind(JobClass).toSelf().inSingletonScope();
1582
1591
  const id = `${jobName.toLowerCase()}:${JobClass.name.toLowerCase()} ${Math.random().toString(36).substring(2, 15)}`;
1592
+ container.bind(id).to(JobClass).inSingletonScope();
1583
1593
  const options = Reflect.getMetadata("job:options", JobClass) || {};
1584
1594
  const instance = container.get(JobClass);
1585
1595
  JobRegistry.instance.register(id, instance, options);
@@ -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.8",
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",