Skip to content

Commit

Permalink
Small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sebelga committed Feb 1, 2024
1 parent 9046b00 commit 73a0d61
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ describe('ContentClient', () => {
storageContext: {} as any,
});
};
// With this test and runtime check we can rely on all the existing tests of the Content Crud.
// e.g. the tests about events being dispatched, etc.
expect(expectToThrow).toThrowError('Crud instance missing or not an instance of ContentCrud');
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/content_management/server/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ export class Core {
const clientFactory = getContentClientFactory({
contentRegistry: this.contentRegistry,
});
const client = clientFactory(contentTypeId);
const contentClient = clientFactory(contentTypeId);

return client.getForRequest<T>({
return contentClient.getForRequest<T>({
requestHandlerContext,
request,
version: version ?? contentDefinition.version.latest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export const bulkGet: ProcedureDefinition<Context, BulkGetIn<string>, BulkGetRes
const clientFactory = getContentClientFactory({
contentRegistry: ctx.contentRegistry,
});
const { getForRequest } = clientFactory(contentTypeId);

return getForRequest({
const client = clientFactory(contentTypeId).getForRequest({
...ctx,
version,
}).bulkGet(ids, options);
});

return client.bulkGet(ids, options);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export const create: ProcedureDefinition<Context, CreateIn<string>> = {
const clientFactory = getContentClientFactory({
contentRegistry: ctx.contentRegistry,
});
const { getForRequest } = clientFactory(contentTypeId);

return getForRequest({
const client = clientFactory(contentTypeId).getForRequest({
...ctx,
version,
}).create(data, options);
});

return client.create(data, options);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export const deleteProc: ProcedureDefinition<Context, DeleteIn<string>> = {
const clientFactory = getContentClientFactory({
contentRegistry: ctx.contentRegistry,
});
const { getForRequest } = clientFactory(contentTypeId);

return getForRequest({
const client = clientFactory(contentTypeId).getForRequest({
...ctx,
version,
}).delete(id, options);
});

return client.delete(id, options);
},
};
8 changes: 4 additions & 4 deletions src/plugins/content_management/server/rpc/procedures/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export const get: ProcedureDefinition<Context, GetIn<string>> = {
const clientFactory = getContentClientFactory({
contentRegistry: ctx.contentRegistry,
});
const { getForRequest } = clientFactory(contentTypeId);

return getForRequest({
const client = clientFactory(contentTypeId).getForRequest({
...ctx,
version,
}).get(id, options);
});

return client.get(id, options);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const mSearch: ProcedureDefinition<Context, MSearchIn, MSearchOut> = {
contentRegistry: ctx.contentRegistry,
mSearchService: ctx.mSearchService,
});
const mSearchClient = clientFactory(ctx);

return clientFactory(ctx).msearch({ contentTypes, query });
return mSearchClient.msearch({ contentTypes, query });
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export const search: ProcedureDefinition<Context, SearchIn<string>> = {
const clientFactory = getContentClientFactory({
contentRegistry: ctx.contentRegistry,
});
const { getForRequest } = clientFactory(contentTypeId);

return getForRequest({
const client = clientFactory(contentTypeId).getForRequest({
...ctx,
version,
}).search(query, options);
});

return client.search(query, options);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export const update: ProcedureDefinition<Context, UpdateIn<string>> = {
const clientFactory = getContentClientFactory({
contentRegistry: ctx.contentRegistry,
});
const { getForRequest } = clientFactory(contentTypeId);

return getForRequest({
const client = clientFactory(contentTypeId).getForRequest({
...ctx,
version,
}).update(id, data, options);
});

return client.update(id, data, options);
},
};

0 comments on commit 73a0d61

Please sign in to comment.