Registry API Refactoring (#144)
* Refactor core to use a flexible registry pattern - Introduce a new registry mechanism for mailer providers - Extract mailer provider enum to a separate file - Implement dynamic mailer loading using a registry - Update package dependencies and exports - Improve modularity and extensibility of mailer implementation * Refactor monitoring and billing services to use a flexible registry pattern - Introduce a shared registry mechanism for dynamic service loading - Replace static switch-based implementations with a registry-based approach - Update instrumentation, CMS, and monitoring services to use the new registry - Improve modularity and extensibility of service implementations - Add Zod-based type-safe provider validation * Simplify async registration in monitoring and billing services - Remove unnecessary async wrappers for no-op registrations - Update type definitions to support both async and sync registration functions - Standardize registration approach for Paddle and Sentry providers * Remove Tailwind package from packages where it is not being needed * Remove Tailwind config references from pnpm-lock.yaml * Update instrumentation registry to support dynamic monitoring providers - Modify type definition to use NonNullable MonitoringProvider - Import MonitoringProvider type from get-monitoring-provider - Enhance type safety for instrumentation registration
This commit is contained in:
committed by
GitHub
parent
3140f0cf21
commit
4a47df81db
@@ -17,6 +17,7 @@
|
||||
"@kit/eslint-config": "workspace:*",
|
||||
"@kit/keystatic": "workspace:*",
|
||||
"@kit/prettier-config": "workspace:*",
|
||||
"@kit/shared": "workspace:*",
|
||||
"@kit/tsconfig": "workspace:*",
|
||||
"@kit/wordpress": "workspace:*",
|
||||
"@types/node": "^22.13.0"
|
||||
@@ -35,4 +36,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,26 @@
|
||||
import { CmsClient, CmsType } from '@kit/cms-types';
|
||||
import { createRegistry } from '@kit/shared/registry';
|
||||
|
||||
/**
|
||||
* The type of CMS client to use.
|
||||
*/
|
||||
const CMS_CLIENT = process.env.CMS_CLIENT as CmsType;
|
||||
|
||||
// Create a registry for CMS client implementations
|
||||
const cmsRegistry = createRegistry<CmsClient, CmsType>();
|
||||
|
||||
// Register the WordPress CMS client implementation
|
||||
cmsRegistry.register('wordpress', async () => {
|
||||
const { createWordpressClient } = await import('@kit/wordpress');
|
||||
return createWordpressClient();
|
||||
});
|
||||
|
||||
// Register the Keystatic CMS client implementation
|
||||
cmsRegistry.register('keystatic', async () => {
|
||||
const { createKeystaticClient } = await import('@kit/keystatic');
|
||||
return createKeystaticClient();
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates a CMS client based on the specified type.
|
||||
*
|
||||
@@ -12,33 +28,6 @@ const CMS_CLIENT = process.env.CMS_CLIENT as CmsType;
|
||||
* @returns {Promise<CmsClient>} A Promise that resolves to the created CMS client.
|
||||
* @throws {Error} If the specified CMS type is unknown.
|
||||
*/
|
||||
export async function createCmsClient(
|
||||
type: CmsType = CMS_CLIENT,
|
||||
): Promise<CmsClient> {
|
||||
return cmsClientFactory(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a CMS client based on the specified type.
|
||||
*
|
||||
* @param {CmsType} type - The type of CMS client to create.
|
||||
* @returns {Promise<CmsClient>} A Promise that resolves to the created CMS client.
|
||||
*/
|
||||
async function cmsClientFactory(type: CmsType): Promise<CmsClient> {
|
||||
switch (type) {
|
||||
case 'wordpress': {
|
||||
const { createWordpressClient } = await import('@kit/wordpress');
|
||||
|
||||
return createWordpressClient();
|
||||
}
|
||||
|
||||
case 'keystatic': {
|
||||
const { createKeystaticClient } = await import('@kit/keystatic');
|
||||
|
||||
return createKeystaticClient();
|
||||
}
|
||||
|
||||
default:
|
||||
throw new Error(`Unknown CMS type`);
|
||||
}
|
||||
export async function createCmsClient(type: CmsType = CMS_CLIENT) {
|
||||
return cmsRegistry.get(type);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user