feat: Flatten the provider config for all modules (#7930)

This commit is contained in:
Stevche Radevski authored and GitHub committed 2024-07-03 16:57:12 +02:00
1 parent b6e4435c23
commit 012a624ee4
24 files changed
+168 -292

No files matched your search

@@ -23,11 +23,7 @@ const moduleOptions = {
process.cwd() +
"/integration-tests/__fixtures__/providers/default-provider"
),
options: {
config: {
"test-provider": {},
},
},
id: "test-provider",
},
],
}
@@ -18,11 +18,7 @@ let moduleOptions = {
process.cwd() +
"/integration-tests/__fixtures__/providers/default-provider"
),
options: {
config: {
"test-provider": {},
},
},
id: "test-provider",
},
],
}
@@ -125,17 +121,13 @@ moduleIntegrationTestRunner({
definition: ModulesDefinition[Modules.FULFILLMENT],
options: {
databaseConfig,
providers: [
{
resolve: resolve(
process.cwd() +
"/integration-tests/__fixtures__/providers/default-provider"
),
options: {
config: providersConfig,
},
},
],
providers: Object.keys(providersConfig).map((id) => ({
resolve: resolve(
process.cwd() +
"/integration-tests/__fixtures__/providers/default-provider"
),
id,
})),
},
},
},
@@ -179,17 +171,13 @@ moduleIntegrationTestRunner({
definition: ModulesDefinition[Modules.FULFILLMENT],
options: {
databaseConfig,
providers: [
{
resolve: resolve(
process.cwd() +
"/integration-tests/__fixtures__/providers/default-provider"
),
options: {
config: providersConfig2,
},
},
],
providers: Object.keys(providersConfig2).map((id) => ({
resolve: resolve(
process.cwd() +
"/integration-tests/__fixtures__/providers/default-provider"
),
id,
})),
},
},
},
@@ -25,11 +25,7 @@ const moduleOptions = {
process.cwd() +
"/integration-tests/__fixtures__/providers/default-provider"
),
options: {
config: {
"test-provider": {},
},
},
id: "test-provider",
},
],
}
@@ -10,20 +10,21 @@ import { FulfillmentIdentifiersRegistrationName } from "@types"
import { Lifetime, asFunction, asValue } from "awilix"
const registrationFn = async (klass, container, pluginOptions) => {
Object.entries(pluginOptions.config || []).map(([name, config]) => {
const key = FulfillmentProviderService.getRegistrationIdentifier(
klass,
name
)
const key = FulfillmentProviderService.getRegistrationIdentifier(
klass,
pluginOptions.id
)
container.register({
["fp_" + key]: asFunction((cradle) => new klass(cradle, config), {
container.register({
["fp_" + key]: asFunction(
(cradle) => new klass(cradle, pluginOptions.options),
{
lifetime: klass.LIFE_TIME || Lifetime.SINGLETON,
}),
})
container.registerAdd(FulfillmentIdentifiersRegistrationName, asValue(key))
}
),
})
container.registerAdd(FulfillmentIdentifiersRegistrationName, asValue(key))
}
export default async ({
@@ -23,11 +23,13 @@ export type FulfillmentModuleOptions =
* The module provider to be registered
*/
resolve: string | ModuleProviderExports
options: {
/**
* key value pair of the provider name and the configuration to be passed to the provider constructor
*/
config: Record<string, unknown>
}
/**
* The id of the provider
*/
id: string
/**
* key value pair of the configuration to be passed to the provider constructor
*/
options?: Record<string, unknown>
}[]
}