or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-10/

Async Catalog Models

Module that registers catalog-related models using asynchronous configuration sources before the Nest application starts.

Capabilities

Registers product model with async options

  • When the configuration loader resolves collection: "products" and ttlDays: 14, importing the module exposes a model bound to that collection with base fields sku, price, apiKey, token, createdAt, and expiresAt, plus a TTL index on expiresAt that expires documents 14 days after createdAt. @test
  • If the loader resolves collection: "products-archived" before module initialization, the exposed model uses that collection name while preserving all base fields. @test

Applies async secrets policy

  • When the secret list loader resolves ["apiKey", "token"], fields with matching keys are required strings that are excluded from query selection and removed from secondary indexes. @test

Builds discriminators from async metadata

  • When the discriminator loader returns child types digital and physical, the child models share base fields sku and price while adding downloadUrl or weight; saving and retrieving each child preserves both base and child-specific fields. @test

Implementation

@generates

API

export interface ProductConfig {
  collection: string;
  ttlDays: number;
}

export interface SecretsPolicy {
  secrets: string[];
}

export interface DiscriminatorShape {
  name: string;
  fields: Record<string, unknown>;
}

export interface ProductAttributes {
  sku: string;
  price: number;
  apiKey?: string;
  token?: string;
  createdAt: Date;
  expiresAt?: Date;
}

export interface AsyncModelsOptions {
  connectionName?: string;
  loadConfig(): Promise<ProductConfig>;
  loadSecrets?(): Promise<SecretsPolicy>;
  loadDiscriminators?(): Promise<DiscriminatorShape[]>;
}

export class AsyncModelsModule {
  /**
   * Registers the product model and optional discriminators using asynchronous factories.
   */
  static register(options: AsyncModelsOptions): import('@nestjs/common').DynamicModule;
}

Dependencies { .dependencies }

@nestjs/mongoose { .dependency }

Provides MongoDB model integration with asynchronous schema registration. @satisfied-by