@rvoh/dream
    Preparing search index...

    Class DreamApp

    Index

    Constructors

    Properties

    loadedModels: boolean = false

    Accessors

    • get dbCredentials(): Record<string, DreamDbCredentialOptions>

      Returns Record<string, DreamDbCredentialOptions>

    • get inflections(): (() => void | Promise<void>) | undefined

      Returns (() => void | Promise<void>) | undefined

    • get packageManager(): "pnpm" | "yarn" | "npm" | "bun" | "deno"

      Returns "pnpm" | "yarn" | "npm" | "bun" | "deno"

    • get system(): {
          absoluteDreamPath: (
              destinationDreamPathType: SupportedDestinations,
              fullyQualifiedDestinationModelName: string,
          ) => string;
          autogeneratedFileDisclaimer: (
              startComment?: string,
              endComment?: string,
          ) => string;
          dreamPath: (dreamPathType: keyof DreamDirectoryPaths) => string;
          expandStiClasses: (
              dreamsOrViewModels:
                  | typeof Dream
                  | ViewModelClass
                  | (typeof Dream | ViewModelClass)[],
          ) => (typeof Dream | ViewModelClass)[];
          globalClassNameFromFullyQualifiedModelName: (str: string) => string;
          inferSerializerFromDreamOrViewModel: <
              T extends Dream
              | ViewModel
              | null
              | undefined,
              ReturnType extends SerializerType | null,
          >(
              obj: T,
              serializerKey?: string | undefined,
          ) => ReturnType;
          inferSerializersFromDreamClassOrViewModelClass: (
              classDef: typeof Dream | ViewModelClass | null | undefined,
              serializerKey?: string | undefined,
          ) => (DreamModelSerializerType | SimpleObjectSerializerType)[];
          isDreamSerializer: (dreamOrSerializerClass: any) => boolean;
          modelClassNameFrom: (
              fullyQualifiedModelName: string,
              modelNameOverride?: string,
          ) => string;
          serializerNameFromFullyQualifiedModelName: (
              fullyQualifiedModelName: string,
              serializerType?: "default" | "summary",
          ) => string;
          standardizeFullyQualifiedModelName: (str: string) => string;
      }
      Internal

      Returns {
          absoluteDreamPath: (
              destinationDreamPathType: SupportedDestinations,
              fullyQualifiedDestinationModelName: string,
          ) => string;
          autogeneratedFileDisclaimer: (
              startComment?: string,
              endComment?: string,
          ) => string;
          dreamPath: (dreamPathType: keyof DreamDirectoryPaths) => string;
          expandStiClasses: (
              dreamsOrViewModels:
                  | typeof Dream
                  | ViewModelClass
                  | (typeof Dream | ViewModelClass)[],
          ) => (typeof Dream | ViewModelClass)[];
          globalClassNameFromFullyQualifiedModelName: (str: string) => string;
          inferSerializerFromDreamOrViewModel: <
              T extends Dream
              | ViewModel
              | null
              | undefined,
              ReturnType extends SerializerType | null,
          >(
              obj: T,
              serializerKey?: string | undefined,
          ) => ReturnType;
          inferSerializersFromDreamClassOrViewModelClass: (
              classDef: typeof Dream | ViewModelClass | null | undefined,
              serializerKey?: string | undefined,
          ) => (DreamModelSerializerType | SimpleObjectSerializerType)[];
          isDreamSerializer: (dreamOrSerializerClass: any) => boolean;
          modelClassNameFrom: (
              fullyQualifiedModelName: string,
              modelNameOverride?: string,
          ) => string;
          serializerNameFromFullyQualifiedModelName: (
              fullyQualifiedModelName: string,
              serializerType?: "default" | "summary",
          ) => string;
          standardizeFullyQualifiedModelName: (str: string) => string;
      }

      • absoluteDreamPath: (
            destinationDreamPathType: SupportedDestinations,
            fullyQualifiedDestinationModelName: string,
        ) => string
      • autogeneratedFileDisclaimer: (startComment?: string, endComment?: string) => string
      • dreamPath: (dreamPathType: keyof DreamDirectoryPaths) => string
      • expandStiClasses: (
            dreamsOrViewModels:
                | typeof Dream
                | ViewModelClass
                | (typeof Dream | ViewModelClass)[],
        ) => (typeof Dream | ViewModelClass)[]
      • globalClassNameFromFullyQualifiedModelName: (str: string) => string
      • inferSerializerFromDreamOrViewModel: <
            T extends Dream
            | ViewModel
            | null
            | undefined,
            ReturnType extends SerializerType | null,
        >(
            obj: T,
            serializerKey?: string | undefined,
        ) => ReturnType
      • inferSerializersFromDreamClassOrViewModelClass: (
            classDef: typeof Dream | ViewModelClass | null | undefined,
            serializerKey?: string | undefined,
        ) => (DreamModelSerializerType | SimpleObjectSerializerType)[]
      • isDreamSerializer: (dreamOrSerializerClass: any) => boolean
      • modelClassNameFrom: (fullyQualifiedModelName: string, modelNameOverride?: string) => string
      • serializerNameFromFullyQualifiedModelName: (
            fullyQualifiedModelName: string,
            serializerType?: "default" | "summary",
        ) => string
      • standardizeFullyQualifiedModelName: (str: string) => string

    Methods

    • Parameters

      • connectionName: string

      Returns DreamDbCredentialOptions | null

    • Parameters

      • connectionName: string

      Returns boolean

    • Type Parameters

      • RT extends "models" | "serializers"

      Parameters

      • resourceType: RT
      • resourcePath: string
      • importCb: (path: string) => Promise<any>

      Returns Promise<void>

    • Type Parameters

      • T extends DreamHookEventType

      Parameters

      • hookEventType: T
      • cb: T extends "db:log"
            ? (event: KyselyLogEvent) => void
            : T extends "repl:start"
                ? (context: Context) => void | Promise<void>
                : never

      Returns void

    • Type Parameters

      • ApplyOpt extends DreamAppSetOption

      Parameters

      • applyOption: ApplyOpt
      • options: ApplyOpt extends "bypassDeprecationChecks"
            ? boolean
            : ApplyOpt extends "db"
                ? string
                | DreamDbCredentialOptions
                : ApplyOpt extends "encryption"
                    ? DreamAppEncryptionOptions
                    : ApplyOpt extends "primaryKeyType"
                        ? LegacyCompatiblePrimaryKeyType
                        : ApplyOpt extends "importExtension"
                            ? ".js"
                            | ".ts"
                            | "none"
                            : ApplyOpt extends "logger"
                                ? DreamLogger
                                : ApplyOpt extends "projectRoot"
                                    ? string
                                    : ApplyOpt extends "inflections"
                                        ? () => void | Promise<(...)>
                                        : ApplyOpt extends "packageManager"
                                            ? "pnpm"
                                            | "yarn"
                                            | "npm"
                                            | "bun"
                                            | "deno"
                                            : ApplyOpt extends "paths"
                                                ? DreamDirectoryPaths
                                                : (...) extends (...) ? (...) : (...)
      • OptionalsecondaryOptions: ApplyOpt extends "db" ? DreamDbCredentialOptions : never

      Returns void

    • Returns the cached dream application if it has been set. If it has not been set, an exception is raised.

      The dream application can be set by calling DreamApp#init, or alternatively, if you are using Psychic along with Dream, it can be set during PsychicApp#init, which will set caches for both the dream and psychic applications at once.

      Returns DreamApp

    • initializes a new dream application and caches it for use within this processes lifecycle.

      Within dream, we rely on cached information about your app to be able to serve routes, perform serializer lookups, generate files, connect to the database, etc...

      In order for this to work properly, the DreamApp#init function must be called before anything else is called within Dream.

      Parameters

      Returns Promise<DreamApp>

    • Since javascript is inherently vulnerable to circular dependencies, this function provides a workaround by enabling you to dynamically bring in classes that, if imported directly, would result in circular dependency issues.

      NOTE: You should only use this as a last resort, since it can create quite a headache for you when leaning into your editor to apply renames, etc...

      Parameters

      • name: string

        the global name you are trying to look up, i.e. 'User', or 'UserSerializer'.

      Returns any

      // this pattern is safe from circular imports, since _UserSerializer
      // is only being used to type something else, which will not result
      // in the circular dependency issue.

      import _UserSerializer from '../serializers/UserSerializer.js'
      const UserSerializer = PsychicApp.lookupClassByGlobalName('UserSerializer') as _UserSerializer