@objectstack/service-messaging 10.3.0 → 11.0.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.js CHANGED
@@ -2520,6 +2520,12 @@ var MessagingServicePlugin = class {
2520
2520
  }
2521
2521
  ]
2522
2522
  });
2523
+ if (typeof ctx.hook === "function") {
2524
+ ctx.hook("kernel:ready", async () => {
2525
+ const engine = getData();
2526
+ if (engine) await this.provisionSystemTables(engine, ctx);
2527
+ });
2528
+ }
2523
2529
  if (typeof ctx.hook === "function") {
2524
2530
  const templateStore = new NotificationTemplateStore({ getData });
2525
2531
  const getEmail = () => {
@@ -2602,6 +2608,38 @@ var MessagingServicePlugin = class {
2602
2608
  `[messaging] service registered with channels: ${service.getRegisteredChannels().join(", ") || "(none)"}`
2603
2609
  );
2604
2610
  }
2611
+ /**
2612
+ * Provision the physical tables for this service's system objects up-front.
2613
+ *
2614
+ * These objects are lazy-created on first WRITE (the SQL driver issues DDL
2615
+ * when the first row is inserted), so an env that READS them first — the
2616
+ * Console bell / inbox queries sys_inbox_message + sys_notification_receipt
2617
+ * before any notification has been delivered — hits "no such table", which
2618
+ * the engine logs as a `Find operation failed` ERROR on every page load.
2619
+ * Creating the tables at kernel:ready makes a new env consistent from the
2620
+ * start. Idempotent (the driver only creates a table when absent), so it is
2621
+ * safe on every boot; per-object failures are isolated.
2622
+ */
2623
+ async provisionSystemTables(engine, ctx) {
2624
+ const sync = engine.syncObjectSchema;
2625
+ if (typeof sync !== "function") return;
2626
+ const objects = [
2627
+ InboxMessage,
2628
+ NotificationReceipt,
2629
+ NotificationDelivery,
2630
+ NotificationPreference,
2631
+ NotificationSubscription,
2632
+ NotificationTemplate,
2633
+ HttpDelivery
2634
+ ];
2635
+ for (const obj of objects) {
2636
+ try {
2637
+ await sync.call(engine, obj.name);
2638
+ } catch (err) {
2639
+ ctx.logger.warn(`[messaging] could not provision ${obj.name} storage \u2014 ${err?.message ?? err}`);
2640
+ }
2641
+ }
2642
+ }
2605
2643
  /** Stop the dispatcher loop + retention sweep on shutdown. */
2606
2644
  async stop() {
2607
2645
  await this.dispatcher?.stop();