pepr 0.15.0 → 0.17.0

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.
@@ -0,0 +1,76 @@
1
+ /// <reference types="node" />
2
+ import { PeprStore } from "./storage";
3
+ type Unit = "seconds" | "second" | "minute" | "minutes" | "hours" | "hour";
4
+ export interface Schedule {
5
+ /**
6
+ * * The name of the store
7
+ */
8
+ name: string;
9
+ /**
10
+ * The value associated with a unit of time
11
+ */
12
+ every: number;
13
+ /**
14
+ * The unit of time
15
+ */
16
+ unit: Unit;
17
+ /**
18
+ * The code to run
19
+ */
20
+ run: () => void;
21
+ /**
22
+ * The start time of the schedule
23
+ */
24
+ startTime?: Date | undefined;
25
+ /**
26
+ * The number of times the schedule has run
27
+ */
28
+ completions?: number | undefined;
29
+ /**
30
+ * Tje intervalID to clear the interval
31
+ */
32
+ intervalID?: NodeJS.Timeout;
33
+ }
34
+ export declare class OnSchedule implements Schedule {
35
+ intervalId: NodeJS.Timeout | null;
36
+ store: PeprStore | undefined;
37
+ name: string;
38
+ completions?: number | undefined;
39
+ every: number;
40
+ unit: Unit;
41
+ run: () => void;
42
+ startTime?: Date | undefined;
43
+ duration: number | undefined;
44
+ lastTimestamp: Date | undefined;
45
+ constructor(schedule: Schedule);
46
+ setStore(store: PeprStore): void;
47
+ startInterval(): void;
48
+ /**
49
+ * Checks the store for this schedule and sets the values if it exists
50
+ * @returns
51
+ */
52
+ checkStore(): void;
53
+ /**
54
+ * Saves the schedule to the store
55
+ * @returns
56
+ */
57
+ saveToStore(): void;
58
+ /**
59
+ * Gets the durations in milliseconds
60
+ */
61
+ getDuration(): void;
62
+ /**
63
+ * Sets up the interval
64
+ */
65
+ setupInterval(): void;
66
+ /**
67
+ * Starts the interval
68
+ */
69
+ start(): void;
70
+ /**
71
+ * Stops the interval
72
+ */
73
+ stop(): void;
74
+ }
75
+ export {};
76
+ //# sourceMappingURL=schedule.d.ts.map
@@ -0,0 +1 @@
1
+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AEG;IACH,KAAK;IAgBL;;OAEG;IACH,IAAI;CAOL"}
@@ -31,6 +31,11 @@ export interface PeprStore {
31
31
  * Register a function to be called when the store is ready.
32
32
  */
33
33
  onReady(callback: DataReceiver): void;
34
+ /**
35
+ * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
36
+ * Resolves when the key/value show up in the store.
37
+ */
38
+ setItemAndWait(key: string, value: string): Promise<void>;
34
39
  }
35
40
  /**
36
41
  * A key-value data store that can be used to persist data that should be shared across Pepr controllers and capabilities.
@@ -45,6 +50,15 @@ export declare class Storage implements PeprStore {
45
50
  clear: () => void;
46
51
  removeItem: (key: string) => void;
47
52
  setItem: (key: string, value: string) => void;
53
+ /**
54
+ * Creates a promise and subscribes to the store, the promise resolves when
55
+ * the key and value are seen in the store.
56
+ *
57
+ * @param key - The key to add into the store
58
+ * @param value - The value of the key
59
+ * @returns
60
+ */
61
+ setItemAndWait: (key: string, value: string) => Promise<void>;
48
62
  subscribe: (subscriber: DataReceiver) => () => void;
49
63
  onReady: (callback: DataReceiver) => void;
50
64
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/lib/storage.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;AACtC,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAC9E,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;AACrD,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI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,GAAG,MAAM,GAAG,IAAI,CAAC;IACpC;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;IACd;;OAEG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE1C;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,YAAY,GAAG,WAAW,CAAC;IAE/C;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;IAEtC;;;OAGG;IACH,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3D;AAED;;;;GAIG;AACH,qBAAa,OAAQ,YAAW,SAAS;;IAOvC,cAAc,SAAU,UAAU,UAEhC;IAEF,OAAO,SAAU,SAAS,UAWxB;IAEF,OAAO,QAAS,MAAM,mBAGpB;IAEF,KAAK,aAEH;IAEF,UAAU,QAAS,MAAM,UAEvB;IAEF,OAAO,QAAS,MAAM,SAAS,MAAM,UAEnC;IAEF;;;;;;;OAOG;IACH,cAAc,QAAS,MAAM,SAAS,MAAM,mBAgB1C;IAEF,SAAS,eAAgB,YAAY,gBAInC;IAEF,OAAO,aAAc,YAAY,UAE/B;IAEF;;;OAGG;IACH,WAAW,QAAS,MAAM,UAExB;CAqBH"}
@@ -35,6 +35,7 @@ export interface CapabilityCfg {
35
35
  }
36
36
  export interface CapabilityExport extends CapabilityCfg {
37
37
  bindings: Binding[];
38
+ hasSchedule: boolean;
38
39
  }
39
40
  export type WhenSelector<T extends GenericClass> = {
40
41
  /** Register an action to be executed when a Kubernetes resource is created or updated. */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB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M,MAAM,iBAAiB,CAAC,CAAC,SAAS,YAAY,IAAI,mBAAmB,CAAC,CAAC,CAAC,GAAG;IAC/E;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK,mBAAmB,CAAC,CAAC,CAAC,CAAC;CAClF,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,IAAI,CAC/F,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,KACtB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAEjF,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,IAAI,CACjG,GAAG,EAAE,mBAAmB,CAAC,CAAC,CAAC,KACxB,OAAO,CAAC,sBAAsB,CAAC,GAAG,sBAAsB,CAAC;AAE9D,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC"}
package/dist/lib.d.ts CHANGED
@@ -1,13 +1,10 @@
1
- import { K8s, RegisterKind, fetch, kind, kind as a, fetchStatus } from "kubernetes-fluent-client";
1
+ import { K8s, RegisterKind, kind as a, fetch, fetchStatus, kind } from "kubernetes-fluent-client";
2
2
  import * as R from "ramda";
3
3
  import { Capability } from "./lib/capability";
4
4
  import Log from "./lib/logger";
5
5
  import { PeprModule } from "./lib/module";
6
6
  import { PeprMutateRequest } from "./lib/mutate-request";
7
- import { PeprValidateRequest } from "./lib/validate-request";
8
7
  import * as PeprUtils from "./lib/utils";
9
- import type * as RTypes from "ramda";
10
- export { a, kind,
11
- /** PeprModule is used to setup a complete Pepr Module: `new PeprModule(cfg, {...capabilities})` */
12
- PeprModule, PeprMutateRequest, PeprValidateRequest, PeprUtils, RegisterKind, K8s, Capability, Log, R, fetch, fetchStatus, RTypes, };
8
+ import { PeprValidateRequest } from "./lib/validate-request";
9
+ export { Capability, K8s, Log, PeprModule, PeprMutateRequest, PeprUtils, PeprValidateRequest, R, RegisterKind, a, fetch, fetchStatus, kind, };
13
10
  //# sourceMappingURL=lib.d.ts.map
package/dist/lib.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAGzC,OAAO,KAAK,KAAK,MAAM,MAAM,OAAO,CAAC;AAErC,OAAO,EACL,CAAC,EACD,IAAI;AACJ,mGAAmG;AACnG,UAAU,EACV,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACZ,GAAG,EACH,UAAU,EACV,GAAG,EACH,CAAC,EACD,KAAK,EACL,WAAW,EAGX,MAAM,GACP,CAAC"}
1
+ {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,EACL,UAAU,EACV,GAAG,EACH,GAAG,EACH,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,mBAAmB,EACnB,CAAC,EACD,YAAY,EACZ,CAAC,EACD,KAAK,EACL,WAAW,EACX,IAAI,GACL,CAAC"}
package/dist/lib.js CHANGED
@@ -617,13 +617,24 @@ var PeprControllerStore = class {
617
617
  #stores = {};
618
618
  #sendDebounce;
619
619
  #onReady;
620
- constructor(config, capabilities, onReady) {
620
+ constructor(config, capabilities, name, onReady) {
621
621
  this.#onReady = onReady;
622
- this.#name = `pepr-${config.uuid}-store`;
623
- for (const { name, registerStore } of capabilities) {
624
- const { store } = registerStore();
625
- store.registerSender(this.#send(name));
626
- this.#stores[name] = store;
622
+ this.#name = name;
623
+ if (name.includes("schedule")) {
624
+ for (const { name: name2, registerScheduleStore, hasSchedule } of capabilities) {
625
+ if (hasSchedule !== true) {
626
+ return;
627
+ }
628
+ const { scheduleStore } = registerScheduleStore();
629
+ scheduleStore.registerSender(this.#send(name2));
630
+ this.#stores[name2] = scheduleStore;
631
+ }
632
+ } else {
633
+ for (const { name: name2, registerStore } of capabilities) {
634
+ const { store } = registerStore();
635
+ store.registerSender(this.#send(name2));
636
+ this.#stores[name2] = store;
637
+ }
627
638
  }
628
639
  setTimeout(
629
640
  () => (0, import_kubernetes_fluent_client2.K8s)(PeprStore).InNamespace(namespace).Get(this.#name).then(this.#setupWatch).catch(this.#createStoreResource),
@@ -743,10 +754,13 @@ var Controller = class _Controller {
743
754
  constructor(config, capabilities, beforeHook, afterHook, onReady) {
744
755
  this.#config = config;
745
756
  this.#capabilities = capabilities;
746
- new PeprControllerStore(config, capabilities, () => {
757
+ new PeprControllerStore(config, capabilities, `pepr-${config.uuid}-store`, () => {
747
758
  this.#bindEndpoints();
748
759
  onReady && onReady();
749
760
  logger_default.info("\u2705 Controller startup complete");
761
+ new PeprControllerStore(config, capabilities, `pepr-${config.uuid}-schedule`, () => {
762
+ logger_default.info("\u2705 Scheduling processed");
763
+ });
750
764
  });
751
765
  this.#app.use(_Controller.#logger);
752
766
  this.#app.use(import_express.default.json({ limit: "2mb" }));
@@ -984,7 +998,8 @@ var PeprModule = class {
984
998
  name: capability.name,
985
999
  description: capability.description,
986
1000
  namespaces: capability.namespaces,
987
- bindings: capability.bindings
1001
+ bindings: capability.bindings,
1002
+ hasSchedule: capability.hasSchedule
988
1003
  });
989
1004
  }
990
1005
  process.send(exportedCapabilities);
@@ -1013,6 +1028,7 @@ var PeprModule = class {
1013
1028
 
1014
1029
  // src/lib/storage.ts
1015
1030
  var import_ramda5 = require("ramda");
1031
+ var MAX_WAIT_TIME = 15e3;
1016
1032
  var Storage = class {
1017
1033
  #store = {};
1018
1034
  #send;
@@ -1042,6 +1058,29 @@ var Storage = class {
1042
1058
  setItem = (key, value) => {
1043
1059
  this.#dispatchUpdate("add", [key], value);
1044
1060
  };
1061
+ /**
1062
+ * Creates a promise and subscribes to the store, the promise resolves when
1063
+ * the key and value are seen in the store.
1064
+ *
1065
+ * @param key - The key to add into the store
1066
+ * @param value - The value of the key
1067
+ * @returns
1068
+ */
1069
+ setItemAndWait = (key, value) => {
1070
+ this.#dispatchUpdate("add", [key], value);
1071
+ return new Promise((resolve, reject) => {
1072
+ const unsubscribe = this.subscribe((data) => {
1073
+ if (data[key] === value) {
1074
+ unsubscribe();
1075
+ resolve();
1076
+ }
1077
+ });
1078
+ setTimeout(() => {
1079
+ unsubscribe();
1080
+ return reject();
1081
+ }, MAX_WAIT_TIME);
1082
+ });
1083
+ };
1045
1084
  subscribe = (subscriber) => {
1046
1085
  const idx = this.#subscriberId++;
1047
1086
  this.#subscribers[idx] = subscriber;
@@ -1075,6 +1114,135 @@ var Storage = class {
1075
1114
  };
1076
1115
  };
1077
1116
 
1117
+ // src/lib/schedule.ts
1118
+ var OnSchedule = class {
1119
+ intervalId = null;
1120
+ store;
1121
+ name;
1122
+ completions;
1123
+ every;
1124
+ unit;
1125
+ run;
1126
+ startTime;
1127
+ duration;
1128
+ lastTimestamp;
1129
+ constructor(schedule) {
1130
+ this.name = schedule.name;
1131
+ this.run = schedule.run;
1132
+ this.every = schedule.every;
1133
+ this.unit = schedule.unit;
1134
+ this.startTime = schedule?.startTime;
1135
+ this.completions = schedule?.completions;
1136
+ }
1137
+ setStore(store) {
1138
+ this.store = store;
1139
+ this.startInterval();
1140
+ }
1141
+ startInterval() {
1142
+ this.checkStore();
1143
+ this.getDuration();
1144
+ this.setupInterval();
1145
+ }
1146
+ /**
1147
+ * Checks the store for this schedule and sets the values if it exists
1148
+ * @returns
1149
+ */
1150
+ checkStore() {
1151
+ const result = this.store && this.store.getItem(this.name);
1152
+ if (result) {
1153
+ const storedSchedule = JSON.parse(result);
1154
+ this.completions = storedSchedule?.completions;
1155
+ this.startTime = storedSchedule?.startTime;
1156
+ this.lastTimestamp = storedSchedule?.lastTimestamp;
1157
+ }
1158
+ }
1159
+ /**
1160
+ * Saves the schedule to the store
1161
+ * @returns
1162
+ */
1163
+ saveToStore() {
1164
+ const schedule = {
1165
+ completions: this.completions,
1166
+ startTime: this.startTime,
1167
+ lastTimestamp: /* @__PURE__ */ new Date(),
1168
+ name: this.name
1169
+ };
1170
+ this.store && this.store.setItem(this.name, JSON.stringify(schedule));
1171
+ }
1172
+ /**
1173
+ * Gets the durations in milliseconds
1174
+ */
1175
+ getDuration() {
1176
+ switch (this.unit) {
1177
+ case "seconds":
1178
+ if (this.every < 10)
1179
+ throw new Error("10 Seconds in the smallest interval allowed");
1180
+ this.duration = 1e3 * this.every;
1181
+ break;
1182
+ case "minutes":
1183
+ case "minute":
1184
+ this.duration = 1e3 * 60 * this.every;
1185
+ break;
1186
+ case "hours":
1187
+ case "hour":
1188
+ this.duration = 1e3 * 60 * 60 * this.every;
1189
+ break;
1190
+ default:
1191
+ throw new Error("Invalid time unit");
1192
+ }
1193
+ }
1194
+ /**
1195
+ * Sets up the interval
1196
+ */
1197
+ setupInterval() {
1198
+ const now = /* @__PURE__ */ new Date();
1199
+ let delay;
1200
+ if (this.lastTimestamp && this.startTime) {
1201
+ this.startTime = void 0;
1202
+ }
1203
+ if (this.startTime) {
1204
+ delay = this.startTime.getTime() - now.getTime();
1205
+ } else if (this.lastTimestamp && this.duration) {
1206
+ const lastTimestamp = new Date(this.lastTimestamp);
1207
+ delay = this.duration - (now.getTime() - lastTimestamp.getTime());
1208
+ }
1209
+ if (delay === void 0 || delay <= 0) {
1210
+ this.start();
1211
+ } else {
1212
+ setTimeout(() => {
1213
+ this.start();
1214
+ }, delay);
1215
+ }
1216
+ }
1217
+ /**
1218
+ * Starts the interval
1219
+ */
1220
+ start() {
1221
+ this.intervalId = setInterval(() => {
1222
+ if (this.completions === 0) {
1223
+ this.stop();
1224
+ return;
1225
+ } else {
1226
+ this.run();
1227
+ if (this.completions && this.completions !== 0) {
1228
+ this.completions -= 1;
1229
+ }
1230
+ this.saveToStore();
1231
+ }
1232
+ }, this.duration);
1233
+ }
1234
+ /**
1235
+ * Stops the interval
1236
+ */
1237
+ stop() {
1238
+ if (this.intervalId) {
1239
+ clearInterval(this.intervalId);
1240
+ this.intervalId = null;
1241
+ }
1242
+ this.store && this.store.removeItem(this.name);
1243
+ }
1244
+ };
1245
+
1078
1246
  // src/lib/capability.ts
1079
1247
  var registerAdmission = isBuildMode() || !isWatchMode();
1080
1248
  var registerWatch = isBuildMode() || isWatchMode() || isDevMode();
@@ -1084,7 +1252,33 @@ var Capability = class {
1084
1252
  #namespaces;
1085
1253
  #bindings = [];
1086
1254
  #store = new Storage();
1255
+ #scheduleStore = new Storage();
1087
1256
  #registered = false;
1257
+ #scheduleRegistered = false;
1258
+ hasSchedule;
1259
+ /**
1260
+ * Run code on a schedule with the capability.
1261
+ *
1262
+ * @param schedule The schedule to run the code on
1263
+ * @returns
1264
+ */
1265
+ OnSchedule = (schedule) => {
1266
+ const { name, every, unit, run, startTime, completions } = schedule;
1267
+ if (process.env.PEPR_WATCH_MODE === "true") {
1268
+ this.hasSchedule = true;
1269
+ const newSchedule = {
1270
+ name,
1271
+ every,
1272
+ unit,
1273
+ run,
1274
+ startTime,
1275
+ completions
1276
+ };
1277
+ this.#scheduleStore.onReady(() => {
1278
+ new OnSchedule(newSchedule).setStore(this.#scheduleStore);
1279
+ });
1280
+ }
1281
+ };
1088
1282
  /**
1089
1283
  * Store is a key-value data store that can be used to persist data that should be shared
1090
1284
  * between requests. Each capability has its own store, and the data is persisted in Kubernetes
@@ -1098,7 +1292,24 @@ var Capability = class {
1098
1292
  removeItem: this.#store.removeItem,
1099
1293
  setItem: this.#store.setItem,
1100
1294
  subscribe: this.#store.subscribe,
1101
- onReady: this.#store.onReady
1295
+ onReady: this.#store.onReady,
1296
+ setItemAndWait: this.#store.setItemAndWait
1297
+ };
1298
+ /**
1299
+ * ScheduleStore is a key-value data store used to persist schedule data that should be shared
1300
+ * between intervals. Each Schedule shares store, and the data is persisted in Kubernetes
1301
+ * in the `pepr-system` namespace.
1302
+ *
1303
+ * Note: There is no direct access to schedule store
1304
+ */
1305
+ ScheduleStore = {
1306
+ clear: this.#scheduleStore.clear,
1307
+ getItem: this.#scheduleStore.getItem,
1308
+ removeItem: this.#scheduleStore.removeItem,
1309
+ setItemAndWait: this.#scheduleStore.setItemAndWait,
1310
+ setItem: this.#scheduleStore.setItem,
1311
+ subscribe: this.#scheduleStore.subscribe,
1312
+ onReady: this.#scheduleStore.onReady
1102
1313
  };
1103
1314
  get bindings() {
1104
1315
  return this.#bindings;
@@ -1116,9 +1327,25 @@ var Capability = class {
1116
1327
  this.#name = cfg.name;
1117
1328
  this.#description = cfg.description;
1118
1329
  this.#namespaces = cfg.namespaces;
1330
+ this.hasSchedule = false;
1119
1331
  logger_default.info(`Capability ${this.#name} registered`);
1120
1332
  logger_default.debug(cfg);
1121
1333
  }
1334
+ /**
1335
+ * Register the store with the capability. This is called automatically by the Pepr controller.
1336
+ *
1337
+ * @param store
1338
+ */
1339
+ registerScheduleStore = () => {
1340
+ logger_default.info(`Registering schedule store for ${this.#name}`);
1341
+ if (this.#scheduleRegistered) {
1342
+ throw new Error(`Schedule store already registered for ${this.#name}`);
1343
+ }
1344
+ this.#scheduleRegistered = true;
1345
+ return {
1346
+ scheduleStore: this.#scheduleStore
1347
+ };
1348
+ };
1122
1349
  /**
1123
1350
  * Register the store with the capability. This is called automatically by the Pepr controller.
1124
1351
  *