@dudousxd/nestjs-notifications-database 0.3.0 → 0.4.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.
@@ -10,7 +10,7 @@ export declare class DatabaseChannel implements ChannelDriver {
10
10
  private readonly store;
11
11
  readonly channel = "database";
12
12
  constructor(store: NotificationStore);
13
- send(notifiable: Notifiable, notification: Notification): Promise<void>;
13
+ send(notifiable: Notifiable, notification: Notification): Promise<unknown>;
14
14
  private referenceFor;
15
15
  private payloadFor;
16
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"database.channel.d.ts","sourceRoot":"","sources":["../src/database.channel.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,UAAU,EAEf,KAAK,YAAY,EAGlB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,KAAK,EAAwB,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAG5E,0FAA0F;AAC1F,eAAO,MAAM,QAAQ,6DAA4B,CAAC;AAElD;;;GAGG;AACH,qBACa,eAAgB,YAAW,aAAa;IAKjD,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJxB,QAAQ,CAAC,OAAO,cAAc;gBAIX,KAAK,EAAE,iBAAiB;IAGrC,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAe7E,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,UAAU;CAUnB"}
1
+ {"version":3,"file":"database.channel.d.ts","sourceRoot":"","sources":["../src/database.channel.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,UAAU,EAEf,KAAK,YAAY,EAKlB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,KAAK,EAAwB,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAG5E,0FAA0F;AAC1F,eAAO,MAAM,QAAQ,6DAA4B,CAAC;AAElD;;;GAGG;AACH,qBACa,eAAgB,YAAW,aAAa;IAKjD,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJxB,QAAQ,CAAC,OAAO,cAAc;gBAIX,KAAK,EAAE,iBAAiB;IAGrC,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAgBhF,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,UAAU;CAUnB"}
@@ -33,7 +33,8 @@ let DatabaseChannel = class DatabaseChannel {
33
33
  const data = this.payloadFor(notifiable, notification);
34
34
  const type = notification.constructor.notificationName ??
35
35
  notification.constructor.name;
36
- await this.store.save({
36
+ // Return the stored row so it flows into afterSending() and the SendResult.
37
+ return this.store.save({
37
38
  type,
38
39
  notifiableType: ref.type,
39
40
  notifiableId: String(ref.id),
@@ -41,13 +42,12 @@ let DatabaseChannel = class DatabaseChannel {
41
42
  });
42
43
  }
43
44
  referenceFor(notifiable, notification) {
44
- const routed = notifiable.routeNotificationFor('database', notification);
45
+ // A { type, id } returned from the 'database' route wins; otherwise derive the ref from
46
+ // toNotifiableRef() or the @Notifiable/@NotifiableId decorators.
47
+ const routed = (0, nestjs_notifications_core_1.routeFor)(notifiable, 'database', notification);
45
48
  if (isRef(routed))
46
49
  return routed;
47
- if (typeof notifiable.toNotifiableRef === 'function')
48
- return notifiable.toNotifiableRef();
49
- throw new Error('The database channel needs a notifiable reference. Implement toNotifiableRef() on the ' +
50
- 'notifiable, or return { type, id } from routeNotificationFor("database").');
50
+ return (0, nestjs_notifications_core_1.notifiableRef)(notifiable);
51
51
  }
52
52
  payloadFor(notifiable, notification) {
53
53
  const handler = (0, nestjs_notifications_core_1.getHandler)(notification, 'database', 'toDatabase');
@@ -1 +1 @@
1
- {"version":3,"file":"database.channel.js","sourceRoot":"","sources":["../src/database.channel.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mFAO6C;AAC7C,2CAAoD;AAEpD,qCAA8C;AAE9C,0FAA0F;AAC7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export interface DatabaseChannelOptions {
7
7
  global?: boolean;
8
8
  /** Extra modules to import (e.g. the ORM module providing the store's dependencies). */
9
9
  imports?: DynamicModule['imports'];
10
+ /**
11
+ * Create the backing schema on bootstrap if it's missing (non-destructive). Default true —
12
+ * set to false to manage the schema through your ORM's migrations instead.
13
+ */
14
+ autoCreateSchema?: boolean;
15
+ }
16
+ export interface DatabaseChannelFeatureOptions {
17
+ /** See {@link DatabaseChannelOptions.autoCreateSchema}. Default true. */
18
+ autoCreateSchema?: boolean;
10
19
  }
11
20
  /**
12
21
  * Registers the database channel. Pair with an ORM adapter package
13
- * (`@dudousxd/nestjs-notifications-database-typeorm` or `-mikro-orm`) or pass a custom store.
22
+ * (`@dudousxd/nestjs-notifications-database-typeorm`, `-mikro-orm`, `-prisma`) or pass a store.
14
23
  *
15
24
  * ```ts
16
25
  * DatabaseChannelModule.forRoot({ store: TypeOrmNotificationStore, imports: [TypeOrmModule.forFeature([...])] })
@@ -19,6 +28,6 @@ export interface DatabaseChannelOptions {
19
28
  export declare class DatabaseChannelModule {
20
29
  static forRoot(options?: DatabaseChannelOptions): DynamicModule;
21
30
  /** Register with an already-provided store token (e.g. provided by an ORM adapter module). */
22
- static forFeature(): DynamicModule;
31
+ static forFeature(options?: DatabaseChannelFeatureOptions): DynamicModule;
23
32
  }
24
33
  //# sourceMappingURL=database.module.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"database.module.d.ts","sourceRoot":"","sources":["../src/database.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAyB,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGtF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAItD,MAAM,WAAW,sBAAsB;IACrC,wEAAwE;IACxE,KAAK,CAAC,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAChC,+EAA+E;IAC/E,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,wFAAwF;IACxF,OAAO,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CACpC;AAED;;;;;;;GAOG;AACH,qBACa,qBAAqB;IAChC,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,sBAA2B,GAAG,aAAa;IAiBnE,8FAA8F;IAC9F,MAAM,CAAC,UAAU,IAAI,aAAa;CAOnC"}
1
+ {"version":3,"file":"database.module.d.ts","sourceRoot":"","sources":["../src/database.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAyB,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGtF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAKtD,MAAM,WAAW,sBAAsB;IACrC,wEAAwE;IACxE,KAAK,CAAC,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAChC,+EAA+E;IAC/E,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,wFAAwF;IACxF,OAAO,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACnC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,6BAA6B;IAC5C,yEAAyE;IACzE,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,qBACa,qBAAqB;IAChC,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,sBAA2B,GAAG,aAAa;IAmBnE,8FAA8F;IAC9F,MAAM,CAAC,UAAU,CAAC,OAAO,GAAE,6BAAkC,GAAG,aAAa;CAY9E"}
@@ -12,10 +12,11 @@ const common_1 = require("@nestjs/common");
12
12
  const database_channel_1 = require("./database.channel");
13
13
  const in_memory_store_1 = require("./in-memory.store");
14
14
  const notifications_query_service_1 = require("./notifications-query.service");
15
+ const schema_initializer_1 = require("./schema-initializer");
15
16
  const tokens_1 = require("./tokens");
16
17
  /**
17
18
  * Registers the database channel. Pair with an ORM adapter package
18
- * (`@dudousxd/nestjs-notifications-database-typeorm` or `-mikro-orm`) or pass a custom store.
19
+ * (`@dudousxd/nestjs-notifications-database-typeorm`, `-mikro-orm`, `-prisma`) or pass a store.
19
20
  *
20
21
  * ```ts
21
22
  * DatabaseChannelModule.forRoot({ store: TypeOrmNotificationStore, imports: [TypeOrmModule.forFeature([...])] })
@@ -27,8 +28,10 @@ let DatabaseChannelModule = DatabaseChannelModule_1 = class DatabaseChannelModul
27
28
  const providers = [
28
29
  storeClass,
29
30
  { provide: tokens_1.NOTIFICATION_STORE, useExisting: storeClass },
31
+ { provide: tokens_1.AUTO_CREATE_SCHEMA, useValue: options.autoCreateSchema ?? true },
30
32
  database_channel_1.DatabaseChannel,
31
33
  notifications_query_service_1.NotificationsQueryService,
34
+ schema_initializer_1.SchemaInitializer,
32
35
  ];
33
36
  return {
34
37
  module: DatabaseChannelModule_1,
@@ -39,10 +42,15 @@ let DatabaseChannelModule = DatabaseChannelModule_1 = class DatabaseChannelModul
39
42
  };
40
43
  }
41
44
  /** Register with an already-provided store token (e.g. provided by an ORM adapter module). */
42
- static forFeature() {
45
+ static forFeature(options = {}) {
43
46
  return {
44
47
  module: DatabaseChannelModule_1,
45
- providers: [database_channel_1.DatabaseChannel, notifications_query_service_1.NotificationsQueryService],
48
+ providers: [
49
+ { provide: tokens_1.AUTO_CREATE_SCHEMA, useValue: options.autoCreateSchema ?? true },
50
+ database_channel_1.DatabaseChannel,
51
+ notifications_query_service_1.NotificationsQueryService,
52
+ schema_initializer_1.SchemaInitializer,
53
+ ],
46
54
  exports: [database_channel_1.DatabaseChannel, notifications_query_service_1.NotificationsQueryService],
47
55
  };
48
56
  }
@@ -1 +1 @@
1
- {"version":3,"file":"database.module.js","sourceRoot":"","sources":["../src/database.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAsF;AACtF,yDAAqD;AACrD,uDAAkD;AAElD,+EAA0E;AAC1E,qCAA8C;AAW9C;;;;;;;GAOG;AAEI,IAAM,qBAAqB,6BAA3B,MAAM,qB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EAAE,OAAO,EAAE,2BAAkB,EAAE,QAAQ,EAAE,OAAO,CAAC,gBAAgB,IAAI,IAAI,EAAE;YAC3E,kCAAe;YACf,uDAAyB;YACzB,sCAAiB;SAClB,CAAC;QACF,OAAO;YACL,MAAM,EAAE,uBAAqB;YAC7B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI;YAC9B,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;YAC9B,SAAS;YACT,OAAO,EAAE,CAAC,kCAAe,EAAE,2BAAkB,EAAE,uDAAyB,CAAC;SAC1E,CAAC;IACJ,CAAC;IAED,8FAA8F;IAC9F,MAAM,CAAC,UAAU,CAAC,UAAyC,EAAE;QAC3D,OAAO;YACL,MAAM,EAAE,uBAAqB;YAC7B,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,2BAAkB,EAAE,QAAQ,EAAE,OAAO,CAAC,gBAAgB,IAAI,IAAI,EAAE;gBAC3E,kCAAe;gBACf,uDAAyB;gBACzB,sCAAiB;aAClB;YACD,OAAO,EAAE,CAAC,kCAAe,EAAE,uDAAyB,CAAC;SACtD,CAAC;IACJ,CAAC;CACF,CAAA;AAjCY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,qBAAqB,CAiCjC"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  export * from './interfaces';
2
- export { NOTIFICATION_STORE } from './tokens';
2
+ export { NOTIFICATION_STORE, AUTO_CREATE_SCHEMA } from './tokens';
3
3
  export { Database, DatabaseChannel } from './database.channel';
4
4
  export { InMemoryStore } from './in-memory.store';
5
- export { DatabaseChannelModule, type DatabaseChannelOptions } from './database.module';
5
+ export { DatabaseChannelModule, type DatabaseChannelOptions, type DatabaseChannelFeatureOptions, } from './database.module';
6
+ export { SchemaInitializer } from './schema-initializer';
6
7
  export { NotificationsQueryService, type NotifiableTarget, type PaginateOptions, type PaginatedNotifications, } from './notifications-query.service';
7
8
  export { createNotificationsController, type NotificationsControllerOptions, } from './notifications.controller';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,KAAK,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AACvF,OAAO,EACL,yBAAyB,EACzB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,sBAAsB,GAC5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,6BAA6B,EAC7B,KAAK,8BAA8B,GACpC,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EACL,qBAAqB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,6BAA6B,GACnC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EACL,yBAAyB,EACzB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,sBAAsB,GAC5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,6BAA6B,EAC7B,KAAK,8BAA8B,GACpC,MAAM,4BAA4B,CAAC"}
package/dist/index.js CHANGED
@@ -14,10 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.createNotificationsController = exports.NotificationsQueryService = exports.DatabaseChannelModule = exports.InMemoryStore = exports.DatabaseChannel = exports.Database = exports.NOTIFICATION_STORE = void 0;
17
+ exports.createNotificationsController = exports.NotificationsQueryService = exports.SchemaInitializer = exports.DatabaseChannelModule = exports.InMemoryStore = exports.DatabaseChannel = exports.Database = exports.AUTO_CREATE_SCHEMA = exports.NOTIFICATION_STORE = void 0;
18
18
  __exportStar(require("./interfaces"), exports);
19
19
  var tokens_1 = require("./tokens");
20
20
  Object.defineProperty(exports, "NOTIFICATION_STORE", { enumerable: true, get: function () { return tokens_1.NOTIFICATION_STORE; } });
21
+ Object.defineProperty(exports, "AUTO_CREATE_SCHEMA", { enumerable: true, get: function () { return tokens_1.AUTO_CREATE_SCHEMA; } });
21
22
  var database_channel_1 = require("./database.channel");
22
23
  Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return database_channel_1.Database; } });
23
24
  Object.defineProperty(exports, "DatabaseChannel", { enumerable: true, get: function () { return database_channel_1.DatabaseChannel; } });
@@ -25,6 +26,8 @@ var in_memory_store_1 = require("./in-memory.store");
25
26
  Object.defineProperty(exports, "InMemoryStore", { enumerable: true, get: function () { return in_memory_store_1.InMemoryStore; } });
26
27
  var database_module_1 = require("./database.module");
27
28
  Object.defineProperty(exports, "DatabaseChannelModule", { enumerable: true, get: function () { return database_module_1.DatabaseChannelModule; } });
29
+ var schema_initializer_1 = require("./schema-initializer");
30
+ Object.defineProperty(exports, "SchemaInitializer", { enumerable: true, get: function () { return schema_initializer_1.SchemaInitializer; } });
28
31
  var notifications_query_service_1 = require("./notifications-query.service");
29
32
  Object.defineProperty(exports, "NotificationsQueryService", { enumerable: true, get: function () { return notifications_query_service_1.NotificationsQueryService; } });
30
33
  var notifications_controller_1 = require("./notifications.controller");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,mCAA8C;AAArC,4GAAA,kBAAkB,OAAA;AAC3B,uDAA+D;AAAtD,4GAAA,QAAQ,OAAA;AAAE,mHAAA,eAAe,OAAA;AAClC,qDAAkD;AAAzC,gHAAA,aAAa,OAAA;AACtB,qDAAuF;AAA9E,wHAAA,qBAAqB,OAAA;AAC9B,6EAKuC;AAJrC,wIAAA,yBAAyB,OAAA;AAK3B,uEAGoC;AAFlC,yIAAA,6BAA6B,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,mCAAkE;AAAzD,4GAAA,kBAAkB,OAAA;AAAE,4GAAA,kBAAkB,OAAA;AAC/C,uDAA+D;AAAtD,4GAAA,QAAQ,OAAA;AAAE,mHAAA,eAAe,OAAA;AAClC,qDAAkD;AAAzC,gHAAA,aAAa,OAAA;AACtB,qDAI2B;AAHzB,wHAAA,qBAAqB,OAAA;AAIvB,2DAAyD;AAAhD,uHAAA,iBAAiB,OAAA;AAC1B,6EAKuC;AAJrC,wIAAA,yBAAyB,OAAA;AAK3B,uEAGoC;AAFlC,yIAAA,6BAA6B,OAAA"}
@@ -29,6 +29,12 @@ export interface NotificationStore {
29
29
  getForNotifiable(notifiableType: string, notifiableId: string): Promise<StoredNotification[]>;
30
30
  getUnread(notifiableType: string, notifiableId: string): Promise<StoredNotification[]>;
31
31
  delete(id: string): Promise<void>;
32
+ /**
33
+ * Optionally create the backing schema if it's missing — non-destructively (never drops).
34
+ * Called on bootstrap when `autoCreateSchema` is enabled. Stores that don't manage schema
35
+ * (in-memory, or schema-first ORMs like Prisma) may omit it or make it a no-op.
36
+ */
37
+ ensureSchema?(): Promise<void>;
32
38
  }
33
39
  /**
34
40
  * Implement this on a notification to define its persisted payload. Falls back to
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAEpF,+EAA+E;AAC/E,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,+CAA+C;IAC/C,cAAc,EAAE,MAAM,CAAC;IACvB,+BAA+B;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,MAAM,EAAE,IAAI,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,gGAAgG;AAChG,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,4FAA4F;AAC5F,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,YAAY,EAAE,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACvE,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,aAAa,CAAC,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,gBAAgB,CAAC,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAC9F,SAAS,CAAC,cAAc,EAAE,MA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,CAAC;IACvE,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,aAAa,CAAC,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,gBAAgB,CAAC,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAC9F,SAAS,CAAC,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACvF,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC;;;;OAIG;IACH,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACxD,UAAU,CAAC,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7D,OAAO,CAAC,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3D"}
@@ -0,0 +1,15 @@
1
+ import { type OnApplicationBootstrap } from '@nestjs/common';
2
+ import type { NotificationStore } from './interfaces';
3
+ /**
4
+ * On bootstrap, asks the store to create its schema if missing (non-destructively), so the
5
+ * library is self-contained out of the box. Disable with `autoCreateSchema: false` and manage
6
+ * the schema through your ORM's migrations instead.
7
+ */
8
+ export declare class SchemaInitializer implements OnApplicationBootstrap {
9
+ private readonly store;
10
+ private readonly autoCreateSchema;
11
+ private readonly logger;
12
+ constructor(store: NotificationStore, autoCreateSchema: boolean);
13
+ onApplicationBootstrap(): Promise<void>;
14
+ }
15
+ //# sourceMappingURL=schema-initializer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-initializer.d.ts","sourceRoot":"","sources":["../src/schema-initializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACzF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGtD;;;;GAIG;AACH,qBACa,iBAAkB,YAAW,sBAAsB;IAK5D,OAAO,CAAC,QAAQ,CAAC,KAAK;IAEtB,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IANnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA+B;gBAInC,KAAK,EAAE,iBAAiB,EAExB,gBAAgB,EAAE,OAAO;IAGtC,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;CAa9C"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SchemaInitializer = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const tokens_1 = require("./tokens");
18
+ /**
19
+ * On bootstrap, asks the store to create its schema if missing (non-destructively), so the
20
+ * library is self-contained out of the box. Disable with `autoCreateSchema: false` and manage
21
+ * the schema through your ORM's migrations instead.
22
+ */
23
+ let SchemaInitializer = class SchemaInitializer {
24
+ store;
25
+ autoCreateSchema;
26
+ logger = new common_1.Logger('Notifications');
27
+ constructor(store, autoCreateSchema) {
28
+ this.store = store;
29
+ this.autoCreateSchema = autoCreateSchema;
30
+ }
31
+ async onApplicationBootstrap() {
32
+ if (!this.autoCreateSchema)
33
+ return;
34
+ if (typeof this.store.ensureSchema !== 'function')
35
+ return;
36
+ try {
37
+ await this.store.ensureSchema();
38
+ }
39
+ catch (error) {
40
+ this.logger.error(`Failed to ensure the notifications schema: ${error instanceof Error ? error.message : String(error)}. Set autoCreateSchema: false and manage the schema via migrations if this is expected.`);
41
+ }
42
+ }
43
+ };
44
+ exports.SchemaInitializer = SchemaInitializer;
45
+ exports.SchemaInitializer = SchemaInitializer = __decorate([
46
+ (0, common_1.Injectable)(),
47
+ __param(0, (0, common_1.Inject)(tokens_1.NOTIFICATION_STORE)),
48
+ __param(1, (0, common_1.Inject)(tokens_1.AUTO_CREATE_SCHEMA)),
49
+ __metadata("design:paramtypes", [Object, Boolean])
50
+ ], SchemaInitializer);
51
+ //# sourceMappingURL=schema-initializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-initializer.js","sourceRoot":"","sources":["../src/schema-initializer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAyF;AAEzF,qCAAkE;AAElE;;;;GAIG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAKT;IAEA;IANF,MAAM,GAAG,IAAI,eAAM,CAAC,eAAe,CAAC,CAAC;IAEtD,YAEmB,KAAwB,EAExB,gBAAyB;QAFzB,UAAK,GAAL,KAAK,CAAmB;QAExB,qBAAgB,GAAhB,gBAAgB,CAAS;IACzC,CAAC;IAEJ,KAAK,CAAC,sBAAsB;QAC1B,IAAI,CAAC,IAAI,CAAC,gBAAgB;YAAE,OAAO;QACnC,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,KAAK,UAAU;YAAE,OAAO;QAC1D,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,8CACE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CACvD,yFAAyF,CAC1F,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAA;AAvBY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,2BAAkB,CAAC,CAAA;IAE1B,WAAA,IAAA,eAAM,EAAC,2BAAkB,CAAC,CAAA;;GANlB,iBAAiB,CAuB7B"}
package/dist/tokens.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  /** DI token for the {@link NotificationStore} implementation backing the database channel. */
2
2
  export declare const NOTIFICATION_STORE: unique symbol;
3
+ /** DI token for the `autoCreateSchema` flag consumed by the SchemaInitializer. */
4
+ export declare const AUTO_CREATE_SCHEMA: unique symbol;
3
5
  //# sourceMappingURL=tokens.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,eAAO,MAAM,kBAAkB,eAA+B,CAAC"}
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,eAAO,MAAM,kBAAkB,eAA+B,CAAC;AAE/D,kFAAkF;AAClF,eAAO,MAAM,kBAAkB,eAA+B,CAAC"}
package/dist/tokens.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NOTIFICATION_STORE = void 0;
3
+ exports.AUTO_CREATE_SCHEMA = exports.NOTIFICATION_STORE = void 0;
4
4
  /** DI token for the {@link NotificationStore} implementation backing the database channel. */
5
5
  exports.NOTIFICATION_STORE = Symbol('NOTIFICATION_STORE');
6
+ /** DI token for the `autoCreateSchema` flag consumed by the SchemaInitializer. */
7
+ exports.AUTO_CREATE_SCHEMA = Symbol('AUTO_CREATE_SCHEMA');
6
8
  //# sourceMappingURL=tokens.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":";;;AAAA,8FAA8F;AACjF,QAAA,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC"}
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":";;;AAAA,8FAA8F;AACjF,QAAA,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAE/D,kFAAkF;AACrE,QAAA,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-notifications-database",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Database channel for nestjs-notifications — persist notifications for in-app display",
5
5
  "license": "MIT",
6
6
  "author": "Davide Carvalho",
@@ -23,7 +23,7 @@
23
23
  "@nestjs/common": "^11.0.0",
24
24
  "reflect-metadata": "^0.2.2",
25
25
  "typescript": "^5.7.2",
26
- "@dudousxd/nestjs-notifications-core": "^0.2.0"
26
+ "@dudousxd/nestjs-notifications-core": "^0.3.0"
27
27
  },
28
28
  "scripts": {
29
29
  "build": "tsc -p tsconfig.json",