Socket
Socket
Sign inDemoInstall

@feathersjs/adapter-commons

Package Overview
Dependencies
Maintainers
3
Versions
111
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@feathersjs/adapter-commons - npm Package Compare versions

Comparing version 5.0.0-pre.33 to 5.0.0-pre.34

10

CHANGELOG.md

@@ -6,2 +6,12 @@ # Change Log

# [5.0.0-pre.34](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.33...v5.0.0-pre.34) (2022-12-14)
### Bug Fixes
- **adapter-commons:** multiple type definition issues ([#2876](https://github.com/feathersjs/feathers/issues/2876)) ([4ff1ed0](https://github.com/feathersjs/feathers/commit/4ff1ed084eb2b2cb687de27a28c96a0dad4530b7))
### Features
- **adapter:** Add patch data type to adapters and refactor AdapterBase usage ([#2906](https://github.com/feathersjs/feathers/issues/2906)) ([9ddc2e6](https://github.com/feathersjs/feathers/commit/9ddc2e6b028f026f939d6af68125847e5c6734b4))
# [5.0.0-pre.33](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.32...v5.0.0-pre.33) (2022-11-08)

@@ -8,0 +18,0 @@

50

lib/declarations.d.ts

@@ -1,3 +0,3 @@

import { Query, Params, Paginated, Id, NullableId } from '@feathersjs/feathers';
export declare type FilterQueryOptions = {
import { Query, Params, Paginated, Id } from '@feathersjs/feathers';
export type FilterQueryOptions = {
filters?: FilterSettings;

@@ -7,4 +7,4 @@ operators?: string[];

};
export declare type QueryFilter = (value: any, options: FilterQueryOptions) => any;
export declare type FilterSettings = {
export type QueryFilter = (value: any, options: FilterQueryOptions) => any;
export type FilterSettings = {
[key: string]: QueryFilter | true;

@@ -16,3 +16,3 @@ };

}
export declare type PaginationParams = false | PaginationOptions;
export type PaginationParams = false | PaginationOptions;
export interface AdapterServiceOptions {

@@ -33,2 +33,4 @@ /**

* A list of additional property query operators to allow in a query
*
* @deprecated No longer needed when a query schema is used
*/

@@ -39,2 +41,4 @@ operators?: string[];

* Can also be a converter function like `{ $ignoreCase: (value) => value === 'true' ? true : false }`
*
* @deprecated No longer needed when a query schema is used
*/

@@ -47,3 +51,3 @@ filters?: FilterSettings;

/**
* @deprecated renamed to `operators`.
* @deprecated No longer needed when a query schema is used
*/

@@ -79,3 +83,3 @@ whitelist?: string[];

*/
export interface InternalServiceMethods<T = any, D = Partial<T>, P extends AdapterParams = AdapterParams> {
export interface InternalServiceMethods<Result = any, Data = Result, PatchData = Partial<Data>, Params extends AdapterParams = AdapterParams, IdType = Id> {
/**

@@ -87,9 +91,9 @@ * Retrieve all resources from this service.

*/
$find(_params?: P & {
_find(_params?: Params & {
paginate?: PaginationOptions;
}): Promise<Paginated<T>>;
$find(_params?: P & {
}): Promise<Paginated<Result>>;
_find(_params?: Params & {
paginate: false;
}): Promise<T[]>;
$find(params?: P): Promise<T[] | Paginated<T>>;
}): Promise<Result[]>;
_find(params?: Params): Promise<Result[] | Paginated<Result>>;
/**

@@ -104,3 +108,3 @@ * Retrieve a single resource matching the given ID, skipping any service-level hooks.

*/
$get(id: Id, params?: P): Promise<T>;
_get(id: IdType, params?: Params): Promise<Result>;
/**

@@ -115,5 +119,5 @@ * Create a new resource for this service, skipping any service-level hooks.

*/
$create(data: Partial<D>, params?: P): Promise<T>;
$create(data: Partial<D>[], params?: P): Promise<T[]>;
$create(data: Partial<D> | Partial<D>[], params?: P): Promise<T | T[]>;
_create(data: Data, params?: Params): Promise<Result>;
_create(data: Data[], params?: Params): Promise<Result[]>;
_create(data: Data | Data[], params?: Params): Promise<Result | Result[]>;
/**

@@ -129,3 +133,3 @@ * Completely replace the resource identified by id, skipping any service-level hooks.

*/
$update(id: Id, data: D, params?: P): Promise<T>;
_update(id: IdType, data: Data, params?: Params): Promise<Result>;
/**

@@ -141,5 +145,5 @@ * Merge any resources matching the given ID with the given data, skipping any service-level hooks.

*/
$patch(id: null, data: Partial<D>, params?: P): Promise<T[]>;
$patch(id: Id, data: Partial<D>, params?: P): Promise<T>;
$patch(id: NullableId, data: Partial<D>, params?: P): Promise<T | T[]>;
_patch(id: null, data: PatchData, params?: Params): Promise<Result[]>;
_patch(id: IdType, data: PatchData, params?: Params): Promise<Result>;
_patch(id: IdType | null, data: PatchData, params?: Params): Promise<Result | Result[]>;
/**

@@ -154,5 +158,5 @@ * Remove resources matching the given ID from the this service, skipping any service-level hooks.

*/
$remove(id: null, params?: P): Promise<T[]>;
$remove(id: Id, params?: P): Promise<T>;
$remove(id: NullableId, params?: P): Promise<T | T[]>;
_remove(id: null, params?: Params): Promise<Result[]>;
_remove(id: IdType, params?: Params): Promise<Result>;
_remove(id: IdType | null, params?: Params): Promise<Result | Result[]>;
}

@@ -1,3 +0,4 @@

import { Id, NullableId, Paginated, Query } from '@feathersjs/feathers';
import { Id, Paginated, Query } from '@feathersjs/feathers';
import { AdapterParams, AdapterServiceOptions, InternalServiceMethods, PaginationOptions } from './declarations';
export declare const VALIDATED: unique symbol;
/**

@@ -7,5 +8,5 @@ * An abstract base class that a database adapter can extend from to implement the

*/
export declare abstract class AdapterBase<T = any, D = Partial<T>, P extends AdapterParams = AdapterParams, O extends AdapterServiceOptions = AdapterServiceOptions> implements InternalServiceMethods<T, D, P> {
options: O;
constructor(options: O);
export declare abstract class AdapterBase<Result = any, Data = Result, PatchData = Partial<Data>, ServiceParams extends AdapterParams = AdapterParams, Options extends AdapterServiceOptions = AdapterServiceOptions, IdType = Id> implements InternalServiceMethods<Result, Data, PatchData, ServiceParams, IdType> {
options: Options;
constructor(options: Options);
get id(): string;

@@ -19,3 +20,3 @@ get events(): string[];

*/
allowsMulti(method: string, params?: P): boolean;
allowsMulti(method: string, params?: ServiceParams): boolean | string[];
/**

@@ -28,12 +29,4 @@ * Returns the combined options for a service call. Options will be merged

*/
getOptions(params: P): O;
getOptions(params: ServiceParams): Options;
/**
* Sanitize the incoming data, e.g. removing invalid keywords etc.
*
* @param data The data to sanitize
* @param _params Service call parameters
* @returns The sanitized data
*/
sanitizeData<X = Partial<D>>(data: X, _params: P): Promise<X>;
/**
* Returns a sanitized version of `params.query`, converting filter values

@@ -47,93 +40,74 @@ * (like $limit and $skip) into the expected type. Will throw an error if

*/
sanitizeQuery(params?: P): Promise<Query>;
abstract $find(_params?: P & {
paginate?: PaginationOptions;
}): Promise<Paginated<T>>;
abstract $find(_params?: P & {
paginate: false;
}): Promise<T[]>;
abstract $find(params?: P): Promise<T[] | Paginated<T>>;
sanitizeQuery(params?: ServiceParams): Promise<Query>;
/**
* Retrieve all resources from this service, skipping any service-level hooks but sanitize the query
* with allowed filters and properties by calling `sanitizeQuery`.
* Retrieve all resources from this service.
* Does not sanitize the query and should only be used on the server.
*
* @param params - Service call parameters {@link Params}
* @see {@link HookLessServiceMethods}
* @see {@link https://docs.feathersjs.com/api/services.html#find-params|Feathers API Documentation: .find(params)}
* @param _params - Service call parameters {@link ServiceParams}
*/
_find(_params?: P & {
abstract _find(_params?: ServiceParams & {
paginate?: PaginationOptions;
}): Promise<Paginated<T>>;
_find(_params?: P & {
}): Promise<Paginated<Result>>;
abstract _find(_params?: ServiceParams & {
paginate: false;
}): Promise<T[]>;
_find(params?: P): Promise<T | T[] | Paginated<T>>;
abstract $get(id: Id, params?: P): Promise<T>;
}): Promise<Result[]>;
abstract _find(params?: ServiceParams): Promise<Result[] | Paginated<Result>>;
/**
* Retrieve a single resource matching the given ID, skipping any service-level hooks but sanitize the query
* with allowed filters and properties by calling `sanitizeQuery`.
* Retrieve a single resource matching the given ID, skipping any service-level hooks.
* Does not sanitize the query and should only be used on the server.
*
* @param id - ID of the resource to locate
* @param params - Service call parameters {@link Params}
* @param params - Service call parameters {@link ServiceParams}
* @see {@link HookLessServiceMethods}
* @see {@link https://docs.feathersjs.com/api/services.html#get-id-params|Feathers API Documentation: .get(id, params)}
*/
_get(id: Id, params?: P): Promise<T>;
abstract $create(data: Partial<D>, params?: P): Promise<T>;
abstract $create(data: Partial<D>[], params?: P): Promise<T[]>;
abstract $create(data: Partial<D> | Partial<D>[], params?: P): Promise<T | T[]>;
abstract _get(id: IdType, params?: ServiceParams): Promise<Result>;
/**
* Create a new resource for this service, skipping any service-level hooks, sanitize the data
* and check if multiple updates are allowed.
* Create a new resource for this service, skipping any service-level hooks.
* Does not check if multiple updates are allowed and should only be used on the server.
*
* @param data - Data to insert into this service.
* @param params - Service call parameters {@link Params}
* @param params - Service call parameters {@link ServiceParams}
* @see {@link HookLessServiceMethods}
* @see {@link https://docs.feathersjs.com/api/services.html#create-data-params|Feathers API Documentation: .create(data, params)}
*/
_create(data: Partial<D>, params?: P): Promise<T>;
_create(data: Partial<D>[], params?: P): Promise<T[]>;
_create(data: Partial<D> | Partial<D>[], params?: P): Promise<T | T[]>;
abstract $update(id: Id, data: D, params?: P): Promise<T>;
abstract _create(data: Data, params?: ServiceParams): Promise<Result>;
abstract _create(data: Data[], params?: ServiceParams): Promise<Result[]>;
abstract _create(data: Data | Data[], params?: ServiceParams): Promise<Result | Result[]>;
/**
* Replace any resources matching the given ID with the given data, skipping any service-level hooks.
* Completely replace the resource identified by id, skipping any service-level hooks.
* Does not sanitize the query and should only be used on the server.
*
* @param id - ID of the resource to be updated
* @param data - Data to be put in place of the current resource.
* @param params - Service call parameters {@link Params}
* @param params - Service call parameters {@link ServiceParams}
* @see {@link HookLessServiceMethods}
* @see {@link https://docs.feathersjs.com/api/services.html#update-id-data-params|Feathers API Documentation: .update(id, data, params)}
*/
_update(id: Id, data: D, params?: P): Promise<T>;
abstract $patch(id: null, data: Partial<D>, params?: P): Promise<T[]>;
abstract $patch(id: Id, data: Partial<D>, params?: P): Promise<T>;
abstract $patch(id: NullableId, data: Partial<D>, params?: P): Promise<T | T[]>;
abstract _update(id: IdType, data: Data, params?: ServiceParams): Promise<Result>;
/**
* Merge any resources matching the given ID with the given data, skipping any service-level hooks.
* Sanitizes the query and data and checks it multiple updates are allowed.
* Does not sanitize the query and should only be used on the server.
*
* @param id - ID of the resource to be patched
* @param data - Data to merge with the current resource.
* @param params - Service call parameters {@link Params}
* @param params - Service call parameters {@link ServiceParams}
* @see {@link HookLessServiceMethods}
* @see {@link https://docs.feathersjs.com/api/services.html#patch-id-data-params|Feathers API Documentation: .patch(id, data, params)}
*/
_patch(id: null, data: Partial<D>, params?: P): Promise<T[]>;
_patch(id: Id, data: Partial<D>, params?: P): Promise<T>;
_patch(id: NullableId, data: Partial<D>, params?: P): Promise<T | T[]>;
abstract $remove(id: null, params?: P): Promise<T[]>;
abstract $remove(id: Id, params?: P): Promise<T>;
abstract $remove(id: NullableId, params?: P): Promise<T | T[]>;
abstract _patch(id: null, data: PatchData, params?: ServiceParams): Promise<Result[]>;
abstract _patch(id: IdType, data: PatchData, params?: ServiceParams): Promise<Result>;
abstract _patch(id: IdType | null, data: PatchData, params?: ServiceParams): Promise<Result | Result[]>;
/**
* Remove resources matching the given ID from the this service, skipping any service-level hooks.
* Sanitized the query and verifies that multiple updates are allowed.
* Does not sanitize query and should only be used on the server.
*
* @param id - ID of the resource to be removed
* @param params - Service call parameters {@link Params}
* @param params - Service call parameters {@link ServiceParams}
* @see {@link HookLessServiceMethods}
* @see {@link https://docs.feathersjs.com/api/services.html#remove-id-params|Feathers API Documentation: .remove(id, params)}
*/
_remove(id: null, params?: P): Promise<T[]>;
_remove(id: Id, params?: P): Promise<T>;
_remove(id: NullableId, params?: P): Promise<T | T[]>;
abstract _remove(id: null, params?: ServiceParams): Promise<Result[]>;
abstract _remove(id: IdType, params?: ServiceParams): Promise<Result>;
abstract _remove(id: IdType | null, params?: ServiceParams): Promise<Result | Result[]>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdapterBase = void 0;
const errors_1 = require("@feathersjs/errors");
exports.AdapterBase = exports.VALIDATED = void 0;
const query_1 = require("./query");
exports.VALIDATED = Symbol('@feathersjs/adapter/sanitized');
const alwaysMulti = {

@@ -45,3 +45,3 @@ find: true,

const { multi } = this.getOptions(params);
if (multi === true || multi === false) {
if (multi === true || !multi) {
return multi;

@@ -67,12 +67,2 @@ }

/**
* Sanitize the incoming data, e.g. removing invalid keywords etc.
*
* @param data The data to sanitize
* @param _params Service call parameters
* @returns The sanitized data
*/
async sanitizeData(data, _params) {
return data;
}
/**
* Returns a sanitized version of `params.query`, converting filter values

@@ -87,2 +77,6 @@ * (like $limit and $skip) into the expected type. Will throw an error if

async sanitizeQuery(params = {}) {
// We don't need legacy query sanitisation if the query has been validated by a schema already
if (params.query && params.query[exports.VALIDATED]) {
return params.query || {};
}
const options = this.getOptions(params);

@@ -95,77 +89,4 @@ const { query, filters } = (0, query_1.filterQuery)(params.query, options);

}
async _find(params) {
const query = await this.sanitizeQuery(params);
return this.$find({
...params,
query
});
}
/**
* Retrieve a single resource matching the given ID, skipping any service-level hooks but sanitize the query
* with allowed filters and properties by calling `sanitizeQuery`.
*
* @param id - ID of the resource to locate
* @param params - Service call parameters {@link Params}
* @see {@link HookLessServiceMethods}
* @see {@link https://docs.feathersjs.com/api/services.html#get-id-params|Feathers API Documentation: .get(id, params)}
*/
async _get(id, params) {
const query = await this.sanitizeQuery(params);
return this.$get(id, {
...params,
query
});
}
async _create(data, params) {
if (Array.isArray(data) && !this.allowsMulti('create', params)) {
throw new errors_1.MethodNotAllowed('Can not create multiple entries');
}
const payload = Array.isArray(data)
? await Promise.all(data.map((current) => this.sanitizeData(current, params)))
: await this.sanitizeData(data, params);
return this.$create(payload, params);
}
/**
* Replace any resources matching the given ID with the given data, skipping any service-level hooks.
*
* @param id - ID of the resource to be updated
* @param data - Data to be put in place of the current resource.
* @param params - Service call parameters {@link Params}
* @see {@link HookLessServiceMethods}
* @see {@link https://docs.feathersjs.com/api/services.html#update-id-data-params|Feathers API Documentation: .update(id, data, params)}
*/
async _update(id, data, params) {
if (id === null || Array.isArray(data)) {
throw new errors_1.BadRequest("You can not replace multiple instances. Did you mean 'patch'?");
}
const payload = await this.sanitizeData(data, params);
const query = await this.sanitizeQuery(params);
return this.$update(id, payload, {
...params,
query
});
}
async _patch(id, data, params) {
if (id === null && !this.allowsMulti('patch', params)) {
throw new errors_1.MethodNotAllowed('Can not patch multiple entries');
}
const { $limit, ...query } = await this.sanitizeQuery(params);
const payload = await this.sanitizeData(data, params);
return this.$patch(id, payload, {
...params,
query
});
}
async _remove(id, params) {
if (id === null && !this.allowsMulti('remove', params)) {
throw new errors_1.MethodNotAllowed('Can not remove multiple entries');
}
const { $limit, ...query } = await this.sanitizeQuery(params);
return this.$remove(id, {
...params,
query
});
}
}
exports.AdapterBase = AdapterBase;
//# sourceMappingURL=service.js.map
{
"name": "@feathersjs/adapter-commons",
"version": "5.0.0-pre.33",
"version": "5.0.0-pre.34",
"description": "Shared database adapter utility functions",

@@ -53,17 +53,17 @@ "homepage": "https://feathersjs.com",

"dependencies": {
"@feathersjs/commons": "^5.0.0-pre.33",
"@feathersjs/errors": "^5.0.0-pre.33",
"@feathersjs/feathers": "^5.0.0-pre.33"
"@feathersjs/commons": "^5.0.0-pre.34",
"@feathersjs/errors": "^5.0.0-pre.34",
"@feathersjs/feathers": "^5.0.0-pre.34"
},
"devDependencies": {
"@types/mocha": "^10.0.0",
"@types/mocha": "^10.0.1",
"@types/mongodb": "^4.0.6",
"@types/node": "^18.11.9",
"@types/node": "^18.11.10",
"mocha": "^10.1.0",
"mongodb": "^4.11.0",
"mongodb": "^4.12.1",
"shx": "^0.3.4",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
"typescript": "^4.9.3"
},
"gitHead": "89f516bcb1457e23a02c6212e9cd8bacc4d267d4"
"gitHead": "42cca600d00f0b3b9d89fa79be30fcd46bc50132"
}

@@ -1,2 +0,2 @@

import { Query, Params, Paginated, Id, NullableId } from '@feathersjs/feathers'
import { Query, Params, Paginated, Id } from '@feathersjs/feathers'

@@ -37,2 +37,4 @@ export type FilterQueryOptions = {

* A list of additional property query operators to allow in a query
*
* @deprecated No longer needed when a query schema is used
*/

@@ -43,2 +45,4 @@ operators?: string[]

* Can also be a converter function like `{ $ignoreCase: (value) => value === 'true' ? true : false }`
*
* @deprecated No longer needed when a query schema is used
*/

@@ -51,3 +55,3 @@ filters?: FilterSettings

/**
* @deprecated renamed to `operators`.
* @deprecated No longer needed when a query schema is used
*/

@@ -86,3 +90,9 @@ whitelist?: string[]

*/
export interface InternalServiceMethods<T = any, D = Partial<T>, P extends AdapterParams = AdapterParams> {
export interface InternalServiceMethods<
Result = any,
Data = Result,
PatchData = Partial<Data>,
Params extends AdapterParams = AdapterParams,
IdType = Id
> {
/**

@@ -94,5 +104,5 @@ * Retrieve all resources from this service.

*/
$find(_params?: P & { paginate?: PaginationOptions }): Promise<Paginated<T>>
$find(_params?: P & { paginate: false }): Promise<T[]>
$find(params?: P): Promise<T[] | Paginated<T>>
_find(_params?: Params & { paginate?: PaginationOptions }): Promise<Paginated<Result>>
_find(_params?: Params & { paginate: false }): Promise<Result[]>
_find(params?: Params): Promise<Result[] | Paginated<Result>>

@@ -108,3 +118,3 @@ /**

*/
$get(id: Id, params?: P): Promise<T>
_get(id: IdType, params?: Params): Promise<Result>

@@ -120,5 +130,5 @@ /**

*/
$create(data: Partial<D>, params?: P): Promise<T>
$create(data: Partial<D>[], params?: P): Promise<T[]>
$create(data: Partial<D> | Partial<D>[], params?: P): Promise<T | T[]>
_create(data: Data, params?: Params): Promise<Result>
_create(data: Data[], params?: Params): Promise<Result[]>
_create(data: Data | Data[], params?: Params): Promise<Result | Result[]>

@@ -135,3 +145,3 @@ /**

*/
$update(id: Id, data: D, params?: P): Promise<T>
_update(id: IdType, data: Data, params?: Params): Promise<Result>

@@ -148,5 +158,5 @@ /**

*/
$patch(id: null, data: Partial<D>, params?: P): Promise<T[]>
$patch(id: Id, data: Partial<D>, params?: P): Promise<T>
$patch(id: NullableId, data: Partial<D>, params?: P): Promise<T | T[]>
_patch(id: null, data: PatchData, params?: Params): Promise<Result[]>
_patch(id: IdType, data: PatchData, params?: Params): Promise<Result>
_patch(id: IdType | null, data: PatchData, params?: Params): Promise<Result | Result[]>

@@ -162,5 +172,5 @@ /**

*/
$remove(id: null, params?: P): Promise<T[]>
$remove(id: Id, params?: P): Promise<T>
$remove(id: NullableId, params?: P): Promise<T | T[]>
_remove(id: null, params?: Params): Promise<Result[]>
_remove(id: IdType, params?: Params): Promise<Result>
_remove(id: IdType | null, params?: Params): Promise<Result | Result[]>
}

@@ -1,3 +0,2 @@

import { BadRequest, MethodNotAllowed } from '@feathersjs/errors'
import { Id, NullableId, Paginated, Query } from '@feathersjs/feathers'
import { Id, Paginated, Query } from '@feathersjs/feathers'
import {

@@ -11,2 +10,4 @@ AdapterParams,

export const VALIDATED = Symbol('@feathersjs/adapter/sanitized')
const alwaysMulti: { [key: string]: boolean } = {

@@ -23,11 +24,13 @@ find: true,

export abstract class AdapterBase<
T = any,
D = Partial<T>,
P extends AdapterParams = AdapterParams,
O extends AdapterServiceOptions = AdapterServiceOptions
> implements InternalServiceMethods<T, D, P>
Result = any,
Data = Result,
PatchData = Partial<Data>,
ServiceParams extends AdapterParams = AdapterParams,
Options extends AdapterServiceOptions = AdapterServiceOptions,
IdType = Id
> implements InternalServiceMethods<Result, Data, PatchData, ServiceParams, IdType>
{
options: O
options: Options
constructor(options: O) {
constructor(options: Options) {
this.options = {

@@ -58,3 +61,3 @@ id: 'id',

*/
allowsMulti(method: string, params: P = {} as P) {
allowsMulti(method: string, params: ServiceParams = {} as ServiceParams) {
const always = alwaysMulti[method]

@@ -68,3 +71,3 @@

if (multi === true || multi === false) {
if (multi === true || !multi) {
return multi

@@ -83,3 +86,3 @@ }

*/
getOptions(params: P): O {
getOptions(params: ServiceParams): Options {
const paginate = params.paginate !== undefined ? params.paginate : this.options.paginate

@@ -95,13 +98,2 @@

/**
* Sanitize the incoming data, e.g. removing invalid keywords etc.
*
* @param data The data to sanitize
* @param _params Service call parameters
* @returns The sanitized data
*/
async sanitizeData<X = Partial<D>>(data: X, _params: P) {
return data
}
/**
* Returns a sanitized version of `params.query`, converting filter values

@@ -115,3 +107,8 @@ * (like $limit and $skip) into the expected type. Will throw an error if

*/
async sanitizeQuery(params: P = {} as P): Promise<Query> {
async sanitizeQuery(params: ServiceParams = {} as ServiceParams): Promise<Query> {
// We don't need legacy query sanitisation if the query has been validated by a schema already
if (params.query && (params.query as any)[VALIDATED]) {
return params.query || {}
}
const options = this.getOptions(params)

@@ -126,158 +123,74 @@ const { query, filters } = filterQuery(params.query, options)

abstract $find(_params?: P & { paginate?: PaginationOptions }): Promise<Paginated<T>>
abstract $find(_params?: P & { paginate: false }): Promise<T[]>
abstract $find(params?: P): Promise<T[] | Paginated<T>>
/**
* Retrieve all resources from this service, skipping any service-level hooks but sanitize the query
* with allowed filters and properties by calling `sanitizeQuery`.
* Retrieve all resources from this service.
* Does not sanitize the query and should only be used on the server.
*
* @param params - Service call parameters {@link Params}
* @see {@link HookLessServiceMethods}
* @see {@link https://docs.feathersjs.com/api/services.html#find-params|Feathers API Documentation: .find(params)}
* @param _params - Service call parameters {@link ServiceParams}
*/
async _find(_params?: P & { paginate?: PaginationOptions }): Promise<Paginated<T>>
async _find(_params?: P & { paginate: false }): Promise<T[]>
async _find(params?: P): Promise<T | T[] | Paginated<T>>
async _find(params?: P): Promise<T | T[] | Paginated<T>> {
const query = await this.sanitizeQuery(params)
abstract _find(_params?: ServiceParams & { paginate?: PaginationOptions }): Promise<Paginated<Result>>
abstract _find(_params?: ServiceParams & { paginate: false }): Promise<Result[]>
abstract _find(params?: ServiceParams): Promise<Result[] | Paginated<Result>>
return this.$find({
...params,
query
})
}
abstract $get(id: Id, params?: P): Promise<T>
/**
* Retrieve a single resource matching the given ID, skipping any service-level hooks but sanitize the query
* with allowed filters and properties by calling `sanitizeQuery`.
* Retrieve a single resource matching the given ID, skipping any service-level hooks.
* Does not sanitize the query and should only be used on the server.
*
* @param id - ID of the resource to locate
* @param params - Service call parameters {@link Params}
* @param params - Service call parameters {@link ServiceParams}
* @see {@link HookLessServiceMethods}
* @see {@link https://docs.feathersjs.com/api/services.html#get-id-params|Feathers API Documentation: .get(id, params)}
*/
async _get(id: Id, params?: P): Promise<T> {
const query = await this.sanitizeQuery(params)
abstract _get(id: IdType, params?: ServiceParams): Promise<Result>
return this.$get(id, {
...params,
query
})
}
abstract $create(data: Partial<D>, params?: P): Promise<T>
abstract $create(data: Partial<D>[], params?: P): Promise<T[]>
abstract $create(data: Partial<D> | Partial<D>[], params?: P): Promise<T | T[]>
/**
* Create a new resource for this service, skipping any service-level hooks, sanitize the data
* and check if multiple updates are allowed.
* Create a new resource for this service, skipping any service-level hooks.
* Does not check if multiple updates are allowed and should only be used on the server.
*
* @param data - Data to insert into this service.
* @param params - Service call parameters {@link Params}
* @param params - Service call parameters {@link ServiceParams}
* @see {@link HookLessServiceMethods}
* @see {@link https://docs.feathersjs.com/api/services.html#create-data-params|Feathers API Documentation: .create(data, params)}
*/
async _create(data: Partial<D>, params?: P): Promise<T>
async _create(data: Partial<D>[], params?: P): Promise<T[]>
async _create(data: Partial<D> | Partial<D>[], params?: P): Promise<T | T[]>
async _create(data: Partial<D> | Partial<D>[], params?: P): Promise<T | T[]> {
if (Array.isArray(data) && !this.allowsMulti('create', params)) {
throw new MethodNotAllowed('Can not create multiple entries')
}
abstract _create(data: Data, params?: ServiceParams): Promise<Result>
abstract _create(data: Data[], params?: ServiceParams): Promise<Result[]>
abstract _create(data: Data | Data[], params?: ServiceParams): Promise<Result | Result[]>
const payload = Array.isArray(data)
? await Promise.all(data.map((current) => this.sanitizeData(current, params)))
: await this.sanitizeData(data, params)
return this.$create(payload, params)
}
abstract $update(id: Id, data: D, params?: P): Promise<T>
/**
* Replace any resources matching the given ID with the given data, skipping any service-level hooks.
* Completely replace the resource identified by id, skipping any service-level hooks.
* Does not sanitize the query and should only be used on the server.
*
* @param id - ID of the resource to be updated
* @param data - Data to be put in place of the current resource.
* @param params - Service call parameters {@link Params}
* @param params - Service call parameters {@link ServiceParams}
* @see {@link HookLessServiceMethods}
* @see {@link https://docs.feathersjs.com/api/services.html#update-id-data-params|Feathers API Documentation: .update(id, data, params)}
*/
async _update(id: Id, data: D, params?: P): Promise<T> {
if (id === null || Array.isArray(data)) {
throw new BadRequest("You can not replace multiple instances. Did you mean 'patch'?")
}
abstract _update(id: IdType, data: Data, params?: ServiceParams): Promise<Result>
const payload = await this.sanitizeData(data, params)
const query = await this.sanitizeQuery(params)
return this.$update(id, payload, {
...params,
query
})
}
abstract $patch(id: null, data: Partial<D>, params?: P): Promise<T[]>
abstract $patch(id: Id, data: Partial<D>, params?: P): Promise<T>
abstract $patch(id: NullableId, data: Partial<D>, params?: P): Promise<T | T[]>
/**
* Merge any resources matching the given ID with the given data, skipping any service-level hooks.
* Sanitizes the query and data and checks it multiple updates are allowed.
* Does not sanitize the query and should only be used on the server.
*
* @param id - ID of the resource to be patched
* @param data - Data to merge with the current resource.
* @param params - Service call parameters {@link Params}
* @param params - Service call parameters {@link ServiceParams}
* @see {@link HookLessServiceMethods}
* @see {@link https://docs.feathersjs.com/api/services.html#patch-id-data-params|Feathers API Documentation: .patch(id, data, params)}
*/
async _patch(id: null, data: Partial<D>, params?: P): Promise<T[]>
async _patch(id: Id, data: Partial<D>, params?: P): Promise<T>
async _patch(id: NullableId, data: Partial<D>, params?: P): Promise<T | T[]>
async _patch(id: NullableId, data: Partial<D>, params?: P): Promise<T | T[]> {
if (id === null && !this.allowsMulti('patch', params)) {
throw new MethodNotAllowed('Can not patch multiple entries')
}
abstract _patch(id: null, data: PatchData, params?: ServiceParams): Promise<Result[]>
abstract _patch(id: IdType, data: PatchData, params?: ServiceParams): Promise<Result>
abstract _patch(id: IdType | null, data: PatchData, params?: ServiceParams): Promise<Result | Result[]>
const { $limit, ...query } = await this.sanitizeQuery(params)
const payload = await this.sanitizeData(data, params)
return this.$patch(id, payload, {
...params,
query
})
}
abstract $remove(id: null, params?: P): Promise<T[]>
abstract $remove(id: Id, params?: P): Promise<T>
abstract $remove(id: NullableId, params?: P): Promise<T | T[]>
/**
* Remove resources matching the given ID from the this service, skipping any service-level hooks.
* Sanitized the query and verifies that multiple updates are allowed.
* Does not sanitize query and should only be used on the server.
*
* @param id - ID of the resource to be removed
* @param params - Service call parameters {@link Params}
* @param params - Service call parameters {@link ServiceParams}
* @see {@link HookLessServiceMethods}
* @see {@link https://docs.feathersjs.com/api/services.html#remove-id-params|Feathers API Documentation: .remove(id, params)}
*/
async _remove(id: null, params?: P): Promise<T[]>
async _remove(id: Id, params?: P): Promise<T>
async _remove(id: NullableId, params?: P): Promise<T | T[]>
async _remove(id: NullableId, params?: P): Promise<T | T[]> {
if (id === null && !this.allowsMulti('remove', params)) {
throw new MethodNotAllowed('Can not remove multiple entries')
}
const { $limit, ...query } = await this.sanitizeQuery(params)
return this.$remove(id, {
...params,
query
})
}
abstract _remove(id: null, params?: ServiceParams): Promise<Result[]>
abstract _remove(id: IdType, params?: ServiceParams): Promise<Result>
abstract _remove(id: IdType | null, params?: ServiceParams): Promise<Result | Result[]>
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc