feathers-ottoman
Version:
A Feathers service adapter for the Ottoman ODM
103 lines (102 loc) • 3.65 kB
TypeScript
import { AdapterService, InternalServiceMethods } from '@feathersjs/adapter-commons';
import { Id, NullableId, Paginated, Params, Query } from '@feathersjs/feathers';
import { ModelTypes } from 'ottoman';
import { OttomanServiceOptions, Filters, Methods } from './types';
declare class OttomanService<T = any> extends AdapterService<T> implements InternalServiceMethods<T> {
_options: OttomanServiceOptions;
constructor(config: OttomanServiceOptions);
get Model(): ModelTypes;
/**
* In Couchbase, an id can be number but internally, it is still stored as string
* Hence, the query by Id still needs to pass in as String rather than Number
*
* @param id Id
* @returns id in string
*/
_getId(id: Id): string;
/**
* Maps $select to select
*
* Append `id` field to $select if not defined by caller
* Without doing so, the result to caller would be without `id` field
*
* @param filters filters
* @returns select filters
*/
_getSelectQuery(filters: Filters): Query;
/**
* Maps $sort to sort
* - 1 to ASC
* - -1 to DESC
*
* @param filters filters
* @returns sort filters
*/
_getSortQuery(filters: Filters): Query;
/**
* Maps $limit to limit
* - 1 to ASC
* - -1 to DESC
*
* @param filters filters
* @returns limit filters
*/
_getLimitQuery(filters: Filters): Query;
/**
* Maps $skip to skip
*
* @param filters filters
* @returns skip filters
*/
_getSkipQuery(filters: Filters): Query;
/**
* Maps $ignoreCase to ignoreCase
*
* @param filters filters
* @returns ignoreCase filters
*/
_getIgnoreCaseQuery(filters: Filters): Query;
/**
* We need to map some of the operator between Common API and Ottoman
*
* Maps (Common API : Ottoman):
* - $ne : $neq
* - $nin: $notIn
*
* After mapping, the correct query construct can then be passed into
* Ottoman API options so that it can process correctly
*
* Since `Ottoman.beta.3`, it simplify some of the operator query such as `$in, $notIn, etc`
* See {@link https://github.com/bwgjoseph/mongoose-vs-ottoman/issues/87 simplify operator usage}
*
* @param query query
* @returns Query
*/
_mapQueryOperator(query: Query): Query;
/**
* Workaround to support '.get/remove/update/patch + id + query *' syntax
* as Ottoman does not allow to pass in additional query with `*ById` method
*
* @param id Id
* @param params Params
* @returns reconstructed query
*/
_getQuery(id: string, params: Params): Query;
/**
* Construct the filters to pass into Ottoman API options
*
* @param filters filters
* @param method find | default
* @returns Ottoman options
*/
_getOptions(filters: Filters, method?: Methods): Query;
_find(params?: Params): Promise<T | T[] | Paginated<T>>;
_get(id: Id, params?: Params): Promise<T>;
_create(data: Partial<T> | Partial<T>[], params?: Params): Promise<T | T[]>;
_update(id: Id, data: T, params?: Params): Promise<T>;
_patch(id: NullableId, data: Partial<T>, params?: Params): Promise<T | T[]>;
_remove(id: NullableId, params?: Params): Promise<T | T[]>;
}
declare const InternalOttomanService: (options: OttomanServiceOptions) => OttomanService;
export default InternalOttomanService;
export { OttomanServiceOptions, OttomanService as Service, };