catalog-backend: rename enableRawJsonRespone -> disableRelationsCompatibility

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-12-13 00:53:50 +01:00
parent 8955923488
commit 14ce4026ed
7 changed files with 28 additions and 16 deletions
+10
View File
@@ -138,6 +138,16 @@ export interface Config {
}>;
}>;
/**
* Disables the compatibility layer for relations in returned entities that
* ensures that all relations objects have both `target` and `targetRef`.
*
* Enabling this option can very significantly improve the performance of
* the catalog, but may break consumers that rely on the existence of
* `target` in the relations objects.
*/
disableRelationsCompatibility?: boolean;
/**
* The strategy to use for entities that are orphaned, i.e. no longer have
* any other entities or providers referencing them. The default value is
@@ -486,8 +486,8 @@ export class CatalogBuilder {
discovery,
});
const enableRawJson = config.getOptionalBoolean(
'catalog.enableRawJsonResponses',
const disableRelationsCompatibility = config.getOptionalBoolean(
'catalog.disableRelationsCompatibility',
);
const policy = this.buildEntityPolicy();
@@ -526,7 +526,7 @@ export class CatalogBuilder {
database: dbClient,
logger,
stitcher,
enableRawJson,
disableRelationsCompatibility,
});
let permissionsService: PermissionsService;
@@ -638,7 +638,7 @@ export class CatalogBuilder {
auth,
httpAuth,
permissionsService,
enableRawJson,
disableRelationsCompatibility,
});
await connectEntityProviders(providerDatabase, entityProviders);
@@ -105,18 +105,20 @@ export class DefaultEntitiesCatalog implements EntitiesCatalog {
private readonly database: Knex;
private readonly logger: LoggerService;
private readonly stitcher: Stitcher;
private readonly enableRawJson: boolean;
private readonly disableRelationsCompatibility: boolean;
constructor(options: {
database: Knex;
logger: LoggerService;
stitcher: Stitcher;
enableRawJson?: boolean;
disableRelationsCompatibility?: boolean;
}) {
this.database = options.database;
this.logger = options.logger;
this.stitcher = options.stitcher;
this.enableRawJson = Boolean(options.enableRawJson);
this.disableRelationsCompatibility = Boolean(
options.disableRelationsCompatibility,
);
}
async entities(request?: EntitiesRequest): Promise<EntitiesResponse> {
@@ -197,7 +199,7 @@ export class DefaultEntitiesCatalog implements EntitiesCatalog {
return {
entities: processRawEntitiesResult(
rows.map(r => r.final_entity!),
this.enableRawJson
this.disableRelationsCompatibility
? request?.fields
: e => {
expandLegacyCompoundRelationsInEntity(e);
@@ -883,7 +883,7 @@ describe('createRouter readonly and raw json enabled', () => {
getLocationByEntity: jest.fn(),
};
const router = await createRouter({
enableRawJson: true,
disableRelationsCompatibility: true,
entitiesCatalog,
locationService,
logger: mockServices.logger.mock(),
@@ -85,7 +85,7 @@ export interface RouterOptions {
auth: AuthService;
httpAuth: HttpAuthService;
permissionsService: PermissionsService;
enableRawJson?: boolean;
disableRelationsCompatibility?: boolean;
}
/**
@@ -113,7 +113,7 @@ export async function createRouter(
permissionsService,
auth,
httpAuth,
enableRawJson = false,
disableRelationsCompatibility = false,
} = options;
const readonlyEnabled =
@@ -215,7 +215,7 @@ export async function createRouter(
signal.throwIfAborted();
if (!enableRawJson) {
if (!disableRelationsCompatibility) {
processEntitiesResponseItems(
result.items,
expandLegacyCompoundRelationsInEntity,
@@ -198,7 +198,7 @@ class TestHarness {
readonly #proxyProgressTracker: ProxyProgressTracker;
static async create(options?: {
enableRawJson?: boolean;
disableRelationsCompatibility?: boolean;
logger?: LoggerService;
db?: Knex;
permissions?: PermissionEvaluator;
@@ -277,7 +277,7 @@ class TestHarness {
database: db,
logger,
stitcher,
enableRawJson: options?.enableRawJson,
disableRelationsCompatibility: options?.disableRelationsCompatibility,
});
const proxyProgressTracker = new ProxyProgressTracker(
new NoopProgressTracker(),
@@ -788,7 +788,7 @@ describe('Catalog Backend Integration', () => {
it('should return valid responses in raw JSON mode', async () => {
const harness = await TestHarness.create({
enableRawJson: true,
disableRelationsCompatibility: true,
});
const entityA = {