@objectstack/service-messaging 10.3.0 → 11.1.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.
package/dist/index.cjs CHANGED
@@ -2591,6 +2591,12 @@ var MessagingServicePlugin = class {
2591
2591
  }
2592
2592
  ]
2593
2593
  });
2594
+ if (typeof ctx.hook === "function") {
2595
+ ctx.hook("kernel:ready", async () => {
2596
+ const engine = getData();
2597
+ if (engine) await this.provisionSystemTables(engine, ctx);
2598
+ });
2599
+ }
2594
2600
  if (typeof ctx.hook === "function") {
2595
2601
  const templateStore = new NotificationTemplateStore({ getData });
2596
2602
  const getEmail = () => {
@@ -2673,6 +2679,38 @@ var MessagingServicePlugin = class {
2673
2679
  `[messaging] service registered with channels: ${service.getRegisteredChannels().join(", ") || "(none)"}`
2674
2680
  );
2675
2681
  }
2682
+ /**
2683
+ * Provision the physical tables for this service's system objects up-front.
2684
+ *
2685
+ * These objects are lazy-created on first WRITE (the SQL driver issues DDL
2686
+ * when the first row is inserted), so an env that READS them first — the
2687
+ * Console bell / inbox queries sys_inbox_message + sys_notification_receipt
2688
+ * before any notification has been delivered — hits "no such table", which
2689
+ * the engine logs as a `Find operation failed` ERROR on every page load.
2690
+ * Creating the tables at kernel:ready makes a new env consistent from the
2691
+ * start. Idempotent (the driver only creates a table when absent), so it is
2692
+ * safe on every boot; per-object failures are isolated.
2693
+ */
2694
+ async provisionSystemTables(engine, ctx) {
2695
+ const sync = engine.syncObjectSchema;
2696
+ if (typeof sync !== "function") return;
2697
+ const objects = [
2698
+ InboxMessage,
2699
+ NotificationReceipt,
2700
+ NotificationDelivery,
2701
+ NotificationPreference,
2702
+ NotificationSubscription,
2703
+ NotificationTemplate,
2704
+ HttpDelivery
2705
+ ];
2706
+ for (const obj of objects) {
2707
+ try {
2708
+ await sync.call(engine, obj.name);
2709
+ } catch (err) {
2710
+ ctx.logger.warn(`[messaging] could not provision ${obj.name} storage \u2014 ${err?.message ?? err}`);
2711
+ }
2712
+ }
2713
+ }
2676
2714
  /** Stop the dispatcher loop + retention sweep on shutdown. */
2677
2715
  async stop() {
2678
2716
  await this.dispatcher?.stop();