From 94822f5670f7e623614b5bfbfcd1036a718640e2 Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Tue, 11 Jun 2024 17:22:47 +0300 Subject: [PATCH] fix(registerGlobalOrm): made it so that the nitro runtimeConfig is not cloned if not already cloned --- ...me_utils_errors.NuxtMikroOrmAlreadyInitialized.html | 8 ++++---- ...ntime_utils_errors.NuxtMikroOrmForkUnavailable.html | 8 ++++---- .../runtime_utils_errors.NuxtMikroOrmModuleError.html | 8 ++++---- ...untime_utils_errors.NuxtMikroOrmNotInitialized.html | 8 ++++---- docs/functions/module.default.html | 2 +- .../runtime_composables_em.useEntityManager.html | 2 +- docs/functions/runtime_server_utils_orm.closeOrm.html | 2 +- docs/functions/runtime_server_utils_orm.initOrm.html | 2 +- .../runtime_server_utils_orm.registerGlobalOrm.html | 2 +- .../runtime_server_utils_orm.useEntityManager.html | 2 +- docs/functions/runtime_server_utils_orm.useOrm.html | 2 +- docs/interfaces/module.ModuleOptions.html | 10 +++++----- docs/modules/module.html | 2 +- docs/modules/runtime_composables_em.html | 2 +- docs/modules/runtime_server_utils_orm.html | 2 +- docs/modules/runtime_utils_errors.html | 2 +- docs/types/module.ForkOptionsFactory.html | 2 +- src/runtime/server/utils/orm.ts | 5 +++-- 18 files changed, 36 insertions(+), 35 deletions(-) diff --git a/docs/classes/runtime_utils_errors.NuxtMikroOrmAlreadyInitialized.html b/docs/classes/runtime_utils_errors.NuxtMikroOrmAlreadyInitialized.html index 55f201c..111fcf2 100644 --- a/docs/classes/runtime_utils_errors.NuxtMikroOrmAlreadyInitialized.html +++ b/docs/classes/runtime_utils_errors.NuxtMikroOrmAlreadyInitialized.html @@ -1,7 +1,7 @@ NuxtMikroOrmAlreadyInitialized | nuxt-mikro-orm-module

Thrown when attempting to initialize a MikroORM instance that is already initialized.

-

Hierarchy (view full)

Constructors

Hierarchy (view full)

Constructors

Properties

Accessors

Constructors

Properties

#instanceName: string

The name of the instance to which the error refers to.

-

Accessors

  • get instanceName(): string
  • The name of the instance to which the error refers to.

    -

    Returns string

\ No newline at end of file +

Constructors

Properties

#instanceName: string

The name of the instance to which the error refers to.

+

Accessors

  • get instanceName(): string
  • The name of the instance to which the error refers to.

    +

    Returns string

\ No newline at end of file diff --git a/docs/classes/runtime_utils_errors.NuxtMikroOrmForkUnavailable.html b/docs/classes/runtime_utils_errors.NuxtMikroOrmForkUnavailable.html index 988c0d0..0cd9112 100644 --- a/docs/classes/runtime_utils_errors.NuxtMikroOrmForkUnavailable.html +++ b/docs/classes/runtime_utils_errors.NuxtMikroOrmForkUnavailable.html @@ -1,8 +1,8 @@ NuxtMikroOrmForkUnavailable | nuxt-mikro-orm-module

Thrown when trying to access the EntityManager from an island component, while the request's event handler did not fork the entity manager previously.

-

Hierarchy (view full)

Constructors

Hierarchy (view full)

Constructors

Properties

Accessors

Constructors

Properties

#instanceName: string

The name of the instance to which the error refers to.

-

Accessors

  • get instanceName(): string
  • The name of the instance to which the error refers to.

    -

    Returns string

\ No newline at end of file +

Constructors

Properties

#instanceName: string

The name of the instance to which the error refers to.

+

Accessors

  • get instanceName(): string
  • The name of the instance to which the error refers to.

    +

    Returns string

\ No newline at end of file diff --git a/docs/classes/runtime_utils_errors.NuxtMikroOrmModuleError.html b/docs/classes/runtime_utils_errors.NuxtMikroOrmModuleError.html index 36f427d..62d6ac8 100644 --- a/docs/classes/runtime_utils_errors.NuxtMikroOrmModuleError.html +++ b/docs/classes/runtime_utils_errors.NuxtMikroOrmModuleError.html @@ -1,7 +1,7 @@ NuxtMikroOrmModuleError | nuxt-mikro-orm-module

Base class for all errors thrown by this module.

-

Hierarchy (view full)

Constructors

Hierarchy (view full)

Constructors

Properties

Accessors

Constructors

Properties

#instanceName: string

The name of the instance to which the error refers to.

-

Accessors

  • get instanceName(): string
  • The name of the instance to which the error refers to.

    -

    Returns string

\ No newline at end of file +

Constructors

Properties

#instanceName: string

The name of the instance to which the error refers to.

+

Accessors

  • get instanceName(): string
  • The name of the instance to which the error refers to.

    +

    Returns string

\ No newline at end of file diff --git a/docs/classes/runtime_utils_errors.NuxtMikroOrmNotInitialized.html b/docs/classes/runtime_utils_errors.NuxtMikroOrmNotInitialized.html index 507a1c0..124d495 100644 --- a/docs/classes/runtime_utils_errors.NuxtMikroOrmNotInitialized.html +++ b/docs/classes/runtime_utils_errors.NuxtMikroOrmNotInitialized.html @@ -1,7 +1,7 @@ NuxtMikroOrmNotInitialized | nuxt-mikro-orm-module

Thrown when trying to access a MikroORM that is not initialized.

-

Hierarchy (view full)

Constructors

Hierarchy (view full)

Constructors

Properties

Accessors

Constructors

Properties

#instanceName: string

The name of the instance to which the error refers to.

-

Accessors

  • get instanceName(): string
  • The name of the instance to which the error refers to.

    -

    Returns string

\ No newline at end of file +

Constructors

Properties

#instanceName: string

The name of the instance to which the error refers to.

+

Accessors

  • get instanceName(): string
  • The name of the instance to which the error refers to.

    +

    Returns string

\ No newline at end of file diff --git a/docs/functions/module.default.html b/docs/functions/module.default.html index 278d205..fa836a6 100644 --- a/docs/functions/module.default.html +++ b/docs/functions/module.default.html @@ -1 +1 @@ -default | nuxt-mikro-orm-module
  • Parameters

    Returns _ModuleSetupReturn

\ No newline at end of file +default | nuxt-mikro-orm-module
  • Parameters

    Returns _ModuleSetupReturn

\ No newline at end of file diff --git a/docs/functions/runtime_composables_em.useEntityManager.html b/docs/functions/runtime_composables_em.useEntityManager.html index 8f4d916..aa0be9e 100644 --- a/docs/functions/runtime_composables_em.useEntityManager.html +++ b/docs/functions/runtime_composables_em.useEntityManager.html @@ -16,4 +16,4 @@

Returns T

The request's associated EntityManager fork.

Throws

NuxtMikroOrmForkUnavailable When trying to use an instance that wasn't forked previously.

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/functions/runtime_server_utils_orm.closeOrm.html b/docs/functions/runtime_server_utils_orm.closeOrm.html index d456c80..03e0e38 100644 --- a/docs/functions/runtime_server_utils_orm.closeOrm.html +++ b/docs/functions/runtime_server_utils_orm.closeOrm.html @@ -5,4 +5,4 @@

Parameters

Returns Promise<void>

A promise that resolves once the MikroORM instance is closed, and the name is unregistered.

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/functions/runtime_server_utils_orm.initOrm.html b/docs/functions/runtime_server_utils_orm.initOrm.html index bdbbd9b..5b5f422 100644 --- a/docs/functions/runtime_server_utils_orm.initOrm.html +++ b/docs/functions/runtime_server_utils_orm.initOrm.html @@ -8,4 +8,4 @@ This function is called the first time per request, when useEntityManager is used.

Returns Promise<T>

The initialized MikroORM instance (same as if you had called useOrm with the same name).

Throws

NuxtMikroOrmAlreadyInitialized When trying to initialize an instance that was previously initialized via initOrm or registerGlobalOrm, and still not closed via closeOrm.

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/functions/runtime_server_utils_orm.registerGlobalOrm.html b/docs/functions/runtime_server_utils_orm.registerGlobalOrm.html index af6d2c0..2fbc921 100644 --- a/docs/functions/runtime_server_utils_orm.registerGlobalOrm.html +++ b/docs/functions/runtime_server_utils_orm.registerGlobalOrm.html @@ -17,4 +17,4 @@ the default fork options defined in the runtime config are used. This function is called the first time per request, when useEntityManager is used.

Returns Promise<T>

The initialized MikroORM instance (same as if you had called useOrm with the same name).

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/functions/runtime_server_utils_orm.useEntityManager.html b/docs/functions/runtime_server_utils_orm.useEntityManager.html index e65db19..c37719a 100644 --- a/docs/functions/runtime_server_utils_orm.useEntityManager.html +++ b/docs/functions/runtime_server_utils_orm.useEntityManager.html @@ -14,4 +14,4 @@

Returns T

The request's associated EntityManager fork.

Throws

NuxtMikroOrmNotInitialized When trying to use an instance that wasn't previously initialized with initOrm or registerGlobalOrm.

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/functions/runtime_server_utils_orm.useOrm.html b/docs/functions/runtime_server_utils_orm.useOrm.html index 9d9ce64..0eb1936 100644 --- a/docs/functions/runtime_server_utils_orm.useOrm.html +++ b/docs/functions/runtime_server_utils_orm.useOrm.html @@ -4,4 +4,4 @@

Returns T

The MikroORM instance for the given name.

Throws

NuxtMikroOrmNotInitialized When trying to use an instance that wasn't previously initialized with initOrm or registerGlobalOrm.

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/interfaces/module.ModuleOptions.html b/docs/interfaces/module.ModuleOptions.html index 953b4fa..f1fbe45 100644 --- a/docs/interfaces/module.ModuleOptions.html +++ b/docs/interfaces/module.ModuleOptions.html @@ -2,18 +2,18 @@

Available in nuxt config from the "mikroOrm" key.

Copied to "runtimeConfig.mikroOrm" and "nitro.runtimeConfig.mikroOrm", when those are not defined.

-
interface ModuleOptions {
    forceClose?: boolean;
    forkOptions?: ForkOptions;
    globalHooks?: boolean | {
        api?: boolean;
        islandComponents?: boolean;
        routes?: boolean;
    };
    overrides?: {
        [instanceName: string]: Omit<ModuleOptions, "overrides">;
    };
}

Properties

interface ModuleOptions {
    forceClose?: boolean;
    forkOptions?: ForkOptions;
    globalHooks?: boolean | {
        api?: boolean;
        islandComponents?: boolean;
        routes?: boolean;
    };
    overrides?: {
        [instanceName: string]: Omit<ModuleOptions, "overrides">;
    };
}

Properties

forceClose?: boolean

Default force close option.

This is used in closeOrm whenever a force option is not explicitly provided. Notably, this includes the close hook registered with registerGlobalOrm.

-
forkOptions?: ForkOptions

Default fork options.

+
forkOptions?: ForkOptions

Default fork options.

This is used in initOrm and registerGlobalOrm when the forkOptionsFactory function is either undefined, or returns undefined.

-
globalHooks?: boolean | {
    api?: boolean;
    islandComponents?: boolean;
    routes?: boolean;
}

Default request hooking options.

+
globalHooks?: boolean | {
    api?: boolean;
    islandComponents?: boolean;
    routes?: boolean;
}

Default request hooking options.

When using registerGlobalOrm, "request" and "close" hooks get registered. This option fine-tunes the behavior of the request hook. The "close" hook is always registered.

@@ -27,11 +27,11 @@

Type declaration

  • Optional api?: boolean

    Whether to fork on api requests (URLs beginning with "/api/").

  • Optional islandComponents?: boolean

    Whether to fork on island component requests (URLs beginning with "/__nuxt_island/").

  • Optional routes?: boolean

    Whether to fork on any request other than api or island components.

    -
overrides?: {
    [instanceName: string]: Omit<ModuleOptions, "overrides">;
}

Overrides of the default options.

+
overrides?: {
    [instanceName: string]: Omit<ModuleOptions, "overrides">;
}

Overrides of the default options.

If an instance is not in this map, all the default options are used.

If an instance in its map, but misses a given option, the defaults for that option are used.

If an instance is in this map and specifies an option, the values are NOT merged, but instead, the specified value here is used in its entirety.

-

Type declaration

\ No newline at end of file +

Type declaration

\ No newline at end of file diff --git a/docs/modules/module.html b/docs/modules/module.html index 7304677..d540f85 100644 --- a/docs/modules/module.html +++ b/docs/modules/module.html @@ -1,4 +1,4 @@ -module | nuxt-mikro-orm-module

Index

Interfaces

ModuleOptions +module | nuxt-mikro-orm-module

Index

Interfaces

Type Aliases

Functions

\ No newline at end of file diff --git a/docs/modules/runtime_composables_em.html b/docs/modules/runtime_composables_em.html index e5ee136..e54ba66 100644 --- a/docs/modules/runtime_composables_em.html +++ b/docs/modules/runtime_composables_em.html @@ -1,2 +1,2 @@ -runtime/composables/em | nuxt-mikro-orm-module

Module runtime/composables/em

Index

Functions

useEntityManager +runtime/composables/em | nuxt-mikro-orm-module
\ No newline at end of file diff --git a/docs/modules/runtime_server_utils_orm.html b/docs/modules/runtime_server_utils_orm.html index 998dc9d..2a58c6f 100644 --- a/docs/modules/runtime_server_utils_orm.html +++ b/docs/modules/runtime_server_utils_orm.html @@ -1,4 +1,4 @@ -runtime/server/utils/orm | nuxt-mikro-orm-module

Module runtime/server/utils/orm

Index

Functions

closeOrm +runtime/server/utils/orm | nuxt-mikro-orm-module

Module runtime/server/utils/orm

Index

Functions

closeOrm initOrm registerGlobalOrm useEntityManager diff --git a/docs/modules/runtime_utils_errors.html b/docs/modules/runtime_utils_errors.html index c74793e..fd32a0a 100644 --- a/docs/modules/runtime_utils_errors.html +++ b/docs/modules/runtime_utils_errors.html @@ -1,4 +1,4 @@ -runtime/utils/errors | nuxt-mikro-orm-module

Index

Classes

NuxtMikroOrmAlreadyInitialized +runtime/utils/errors | nuxt-mikro-orm-module

Index

Classes

NuxtMikroOrmAlreadyInitialized NuxtMikroOrmForkUnavailable NuxtMikroOrmModuleError NuxtMikroOrmNotInitialized diff --git a/docs/types/module.ForkOptionsFactory.html b/docs/types/module.ForkOptionsFactory.html index 4aa14d9..b55cb0e 100644 --- a/docs/types/module.ForkOptionsFactory.html +++ b/docs/types/module.ForkOptionsFactory.html @@ -2,4 +2,4 @@

Type declaration

    • (event, name): ForkOptions | undefined
    • Parameters

      • event: H3Event<EventHandlerRequest>

        The request even for which a fork is about to be creted.

      • name: string

        The name of the instance being forked.

      Returns ForkOptions | undefined

Returns

The fork options that will be used in the new fork.

-
\ No newline at end of file +
\ No newline at end of file diff --git a/src/runtime/server/utils/orm.ts b/src/runtime/server/utils/orm.ts index 895f7ed..33e1c52 100644 --- a/src/runtime/server/utils/orm.ts +++ b/src/runtime/server/utils/orm.ts @@ -188,8 +188,9 @@ export async function registerGlobalOrm { - event.context.nitro ??= {}; - const runtimeOptions = useRuntimeConfig(event).mikroOrm; + const runtimeOptions = typeof event.context.nitro === 'undefined' + ? useRuntimeConfig().mikroOrm + : useRuntimeConfig(event).mikroOrm; const reqHookOptions = runtimeOptions.overrides?.[name]?.globalHooks ?? runtimeOptions.globalHooks ?? initTimeGlobalHooks; if (reqHookOptions === false) {