Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
drupal-jsonapi-params
Advanced tools
The JSON:API is now part of Drupal Core.
The JSON:API specifications defines standard query parameters to be used to do filtering, sorting, restricting fields that are returned, pagination and so on.
This module provides a helper Class to create the required query. While doing so, it also tries to optimise the query by using the short form, whenever possible.
Install the package via npm
:
$ npm i drupal-jsonapi-params
Import DrupalJsonApiParams
from drupal-jsonapi-params
import {DrupalJsonApiParams} from 'drupal-jsonapi-params';
const apiParams = new DrupalJsonApiParams();
var drupalJsonapiParams = require("drupal-jsonapi-params")
const apiParams = new drupalJsonapiParams.DrupalJsonApiParams();
apiParams
// Add Group within Groups.
.addGroup('publish_status', 'OR', 'parent_group')
.addGroup('child_group_B', 'AND', 'parent_group')
.addGroup('parent_group', 'AND')
// Add Filters.
.addFilter('status', '1')
// Add Filter to Group.
.addFilter('status', '2', '!=', 'publish_status')
// Add Page Limit.
.addPageLimit(5)
// Add Fields.
.addFields('node--article', ['field_a.id', 'field_b.uid', 'field_c.tid'])
// Add Includes.
.addInclude(['field_a.id', 'field_b.uid', 'field_c.tid'])
// Add multiple sort criterion.
.addSort('id', 'DESC')
.addSort('uid')
.addSort('status');
const urlencodedQueryString = apiParams.getQueryString();
const queryString = apiParams.getQueryString({ encode: false });
Returns query string which can be used in api calls. By default the output is URI encoded. Options can be passed to control the qs.stringifying internally used.
Used to restrict items returned in a listing.
Params | Type | Description |
---|---|---|
path | string | A 'path' identifies a field on a resource |
value | string | string[] |
operator | string | (Optional) An 'operator' is a method of comparison |
group | string | (Optional) Name of the group, the filter belongs to |
Following values can be used for the operator. If none is provided, it assumes "=
" by default.
'=', '<>',
'>', '>=', '<', '<=',
'STARTS_WITH', 'CONTAINS', 'ENDS_WITH',
'IN', 'NOT IN',
'BETWEEN', 'NOT BETWEEN',
'IS NULL', 'IS NOT NULL'
NOTE: Make sure you match the value supplied based on the operators used as per the table below
Value Type | Operator | Description |
---|---|---|
string | = , <> , > , >= , < , <= , STARTS_WITH , CONTAINS , ENDS_WITH | |
string[] | IN , NOT IN | |
string[] size 2 | BETWEEN , NOT BETWEEN | The first item is used for min (start of the range), and the second item is used for max (end of the range). |
null | IS NULL , IS NOT NULL | Must use null |
Read more about filter in Drupal.org Documentation
Used to group Filters. Groups can be nested too.
Params | Type | Description |
---|---|---|
name | string | Name of the group |
conjunction | string | (Optional) All groups have conjunctions and a conjunction is either AND or OR . |
memberOf | string | (Optional) Name of the group, this group belongs to |
Used to add referenced resources inside same request. Thereby preventing additional api calls.
Params | Type | Description |
---|---|---|
fields | string[] | Array of field names |
Read more about Includes in Drupal.org Documentation
Used to return the list of items in specific order.
Params | Type | Description |
---|---|---|
path | string | A 'path' identifies a field on a resource |
direction | string | Sort direction ASC or DESC |
Read more about Sort in Drupal.org Documentation
Use to restrict max amount of items returned in the listing. Using this for pagination is tricky, and make sure you read the following document on Drupal.org to implement it correctly.
Params | Type | Description |
---|---|---|
limit | number | Number of items to limit to |
Read more about Pagination in Drupal.org Documentation
The name of this method might be miss leading. Use this to explicitely request for specific fields on an entity.
Params | Type | Description |
---|---|---|
type | string | Resource type |
fields | string[] | Array of field names in the given resource type |
Clears all query parameter constructed so far.
Get object representation of the query object generated so far.
Re-initialize with a query string/object or another instance of DrupalJsonApiParams
Re-initialize with previously stored data from getQueryObject
Re-initialize with previously stored data from getQueryString
FAQs
Drupal JSON-API params
The npm package drupal-jsonapi-params receives a total of 2,252 weekly downloads. As such, drupal-jsonapi-params popularity was classified as popular.
We found that drupal-jsonapi-params demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.