mirror of
https://github.com/strapi/strapi.git
synced 2025-11-05 04:13:36 +00:00
* fix: content-api route extension for i18n and users-permissions * refactor: simplify tests to catch breaking change * test: cli for openapi plugin routes * refactor: implement createcontentapiroutesfactory for content-api routes across multiple packages * fix: more accurate message * chore: formatting * chore: cleanup backward compatibility tests --------- Co-authored-by: Ziyi Yuan <daydreamnation@live.com>
38 lines
975 B
TypeScript
38 lines
975 B
TypeScript
/**
|
|
* Creates a content-api route factory that exposes `routes` on the factory function for backward compatibility.
|
|
*
|
|
* This allows legacy extensions to mutate `plugin.routes["content-api"].routes` directly.
|
|
*/
|
|
export const createContentApiRoutesFactory = <TRoutes>(buildRoutes: () => TRoutes) => {
|
|
let sharedRoutes: TRoutes | undefined;
|
|
|
|
const ensureSharedRoutes = (): TRoutes => {
|
|
if (!sharedRoutes) {
|
|
sharedRoutes = buildRoutes();
|
|
}
|
|
|
|
return sharedRoutes;
|
|
};
|
|
|
|
const createContentApiRoutes = () => {
|
|
return {
|
|
type: 'content-api' as const,
|
|
routes: ensureSharedRoutes(),
|
|
};
|
|
};
|
|
|
|
Object.defineProperty(createContentApiRoutes, 'routes', {
|
|
get: ensureSharedRoutes,
|
|
set(next: TRoutes) {
|
|
sharedRoutes = next;
|
|
},
|
|
enumerable: true,
|
|
});
|
|
|
|
return createContentApiRoutes;
|
|
};
|
|
|
|
export type ContentApiRoutesFactory<TRoutes> = ReturnType<
|
|
typeof createContentApiRoutesFactory<TRoutes>
|
|
> & { routes: TRoutes };
|