
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@janiscommerce/api-list
Advanced tools
A package to handle JANIS List APIs
npm install @janiscommerce/api-list
'use strict';
const { ApiListData } = require('@janiscommerce/api-list');
class MyApiListData extends ApiListData {
get fieldsToSelect() {
return ['id', 'name', 'status'];
}
get sortableFields() {
return [
'id',
'status'
];
}
get availableFilters() {
return [
'id',
{
name: 'status',
valueMapper: Number
}
];
}
async formatRows(rows) {
return rows.map(row => ({ ...row, oneMoreField: true }));
}
}
module.exports = MyApiListData;
If you have for example, a list API for a sub-entity of one specific record, the parent will be automatically be added as a filter.
Important: The parent entity must be listed as an available filter
For example, the following endpoint: /api/parent-entity/1/sub-entity
, will be a list of the sub-entity, and parentEntity: '1'
will be set as a filter.
It could be thought as if it's equivalent to the following request: /api/sub-entity?filters[parentEntity]=1
The following getters and methods can be used to customize and validate your List API. All of them are optional.
This is used to indicate which fields should be selected from the DB. This allows you to select fields from other tables, and automatically join them in relational databases. This fields must be defined in the model.
This is used to indicate which fields can be used to sort the list. Any other sort field will return a 400 status code.
This is used to indicate which fields can be used to filter the list. Any other filter will return a 400 status code. Filters can be customized by passing an object with the following properties:
name
: The name of the filter param. This property is required.internalName
: The name of the field, as defined in the model. This should not be defined in case it's equal to name
valueMapper
: A function to be called on the filter's value. This is optional.You can use this to format your records before they are returned. For example, mapping DB friendly values to user friendly values, add default values, translation keys, etc.
[3.0.1] - 2019-10-01
FAQs
A package to handle Janis List APIs
The npm package @janiscommerce/api-list receives a total of 389 weekly downloads. As such, @janiscommerce/api-list popularity was classified as not popular.
We found that @janiscommerce/api-list demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.