Currently, Kurier can parse meta in requests, but it cannot inject meta in an operation response. We need a way to inject meta in resources and documents.
The proposal is to add the meta property at the Resource type and add hook-like functions to OperationProcessor so the executeOperation() method can call them if needed:
Resource-level meta hooks:
resourceMeta: for any operation
resourceMetaFor*: for specific operations (get, add, update, custom ops)
Document-level meta hooks:
meta instance property: for any operation
metaFor*: for specific operations (get, add, update, custom ops)
Initially we won't support meta on remove operations, because we are not returning any response on transport layers (i.e. HTTP 204 No Content).
Execution of these hooks must take place at the Application level, in the executeOperation method, prior to calling buildOperationResponse.
Implementation example
export default class ArticleProcessor<ResourceT extends Article> extends KnexProcessor<ResourceT> {
/**
* Returns a `meta` object at the processor (document) level for any operations.
*/
async meta(resourceOrResources: Resource | Resource[]): Meta {
// ...
}
/**
* Returns a `meta` object at the resource level for any operations.
*/
async resourceMeta(resource: Resource): Meta {
// ...
}
/**
* Returns a `meta` object at the processor (document) level, providing the operation
* to help decide in which cases add a `meta`.
*/
async metaFor(op: Operation, resourceOrResources: Resource | Resource[]): Meta {
switch (op.op) {
case 'get':
// ...
break;
// ...
}
// ...
}
/**
* Returns a `meta` object at the processor (document) level for `get` operations.
*/
async metaForGet(resourceOrResources: Resource | Resource[]): Meta {
// ...
}
/**
* Returns a `meta` object at the processor (document) level for `add` operations.
*/
async metaForAdd(resourceOrResources: Resource | Resource[]): Meta {
// ...
}
/**
* Returns a `meta` object at the processor (document) level for `update` operations.
*/
async metaForUpdate(resourceOrResources: Resource | Resource[]): Meta {
// ...
}
/**
* Returns a `meta` object at the processor (document) level for a custom operation called `print`.
*/
async metaForPrint(resourceOrResources: Resource | Resource[]): Meta {
// ...
}
/**
* Returns a `meta` object at the resource level, providing the operation
* to help decide in which cases add a `meta`.
*/
async resourceMetaFor(op: Operation, resource: Resource): Meta {
switch (op.op) {
case 'get':
// ...
break;
// ...
}
// ...
}
/**
* Returns a `meta` object at the resource level for `get` operations.
*/
async resourceMetaForGet(resource: Resource): Meta {
// ...
}
/**
* Returns a `meta` object at the resource level for `add` operations.
*/
async resourceMetaForAdd(resource: Resource): Meta {
// ...
}
/**
* Returns a `meta` object at the resource level for `update` operations.
*/
async resourceMetaForUpdate(resource: Resource): Meta {
// ...
}
/**
* Returns a `meta` object at the resource level for a custom operation called `print`.
*/
async resourceMetaForPrint(resourceOrResources: Resource | Resource[]): Meta {
// ...
}
}
Currently, Kurier can parse
meta
in requests, but it cannot injectmeta
in an operation response. We need a way to injectmeta
in resources and documents.The proposal is to add the
meta
property at theResource
type and add hook-like functions toOperationProcessor
so theexecuteOperation()
method can call them if needed:resourceMeta
: for any operationresourceMetaFor*
: for specific operations (get, add, update, custom ops)meta
instance property: for any operationmetaFor*
: for specific operations (get, add, update, custom ops)Initially we won't support
meta
onremove
operations, because we are not returning any response on transport layers (i.e. HTTP 204 No Content).Execution of these hooks must take place at the Application level, in the
executeOperation
method, prior to callingbuildOperationResponse
.Implementation example