Resource Links support
We decided to launch to V1 without this feature, but the plan is to someday add support for resource links, and related resource links.
On a first glance, we have 4 big features to implement:
Any updates on this one? And what about pagination, should this be added to?
first: the first page of datalast: the last page of dataprev: the previous page of datanext: the next page of data
https://jsonapi.org/format/#fetching-pagination
@spersico would it be possible to add pagination with a custom Addon?
hi @isBatak!, it should... but the one that built the addons system is @joelalejandro.
@joelalejandro what do you think?
@isBatak @spersico Hey there! I think it's entirely possible, I made a couple of addons for features that can still be regarded as experimental for Kurier, so sure, it's possible. Once the feature is stable enough, we can consider bundling it as part of the core experience.
@joelalejandro 👋
Can you point out what should I do?
For the first step, I just want to support first, last, prev, next links for resources response.
I guess I need to extend this part https://github.com/kurierjs/kurier/blob/master/src/application.ts#L228 with links object, but how should I do it through Addon?
I figure out how to override buildOperationResponse inside of an addon.
import {
Addon,
Application,
ApplicationInstance,
HasId,
KnexProcessor,
Operation,
OperationResponse,
Resource,
} from 'kurier';
import { PaginationOptions } from './types';
const defaults: PaginationOptions = {
defaultPaginator: 'paged',
defaultPageSize: 10,
maximumPageSize: 20,
};
export class PaginationAddon extends Addon {
constructor(public readonly app: Application, public readonly options?: PaginationOptions) {
super(app);
this.options = { ...defaults, ...options };
}
async install(): Promise<void> {
const oldBuildOperationResponse = this.app.buildOperationResponse.bind(this.app);
this.app.buildOperationResponse = async (
data: Resource | Resource[] | void,
appInstance: ApplicationInstance
): Promise<OperationResponse> => {
const operationResponse = await oldBuildOperationResponse(data, appInstance);
let links = {};
if (Array.isArray(data)) {
// TODO
links = {
first: '',
last: '',
prev: '',
next: '',
};
}
return {
...operationResponse,
links,
};
};
}
}
but the problem is that I need to change this helper also https://github.com/kurierjs/kurier/blob/3ad3b655f8c10b08300e430fd02384486984a933/src/utils/http-utils.ts#L97 ... sad :(
@joelalejandro @spersico I made a draft PR #275 to fix the above issue. Could you check if I'm going in the right direction?
Sorry for the delay @isBatak, I was on vacation. I will take a look at it today or tomorrow.
@joelalejandro yeah no problem!
@isBatak I'm OK with the approach you describe in #275, feel free to go along with it 🚀