@feathersjs/adapter-commons 5.0.0-pre.2 → 5.0.0-pre.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/query.js ADDED
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterQuery = exports.FILTERS = exports.OPERATORS = void 0;
4
+ const commons_1 = require("@feathersjs/commons");
5
+ const errors_1 = require("@feathersjs/errors");
6
+ const parse = (value) => typeof value !== 'undefined' ? parseInt(value, 10) : value;
7
+ const isPlainObject = (value) => commons_1._.isObject(value) && value.constructor === {}.constructor;
8
+ const validateQueryProperty = (query, operators = []) => {
9
+ if (!isPlainObject(query)) {
10
+ return query;
11
+ }
12
+ for (const key of Object.keys(query)) {
13
+ if (key.startsWith('$') && !operators.includes(key)) {
14
+ throw new errors_1.BadRequest(`Invalid query parameter ${key}`, query);
15
+ }
16
+ const value = query[key];
17
+ if (isPlainObject(value)) {
18
+ query[key] = validateQueryProperty(value, operators);
19
+ }
20
+ }
21
+ return {
22
+ ...query
23
+ };
24
+ };
25
+ const getFilters = (query, settings) => {
26
+ const filterNames = Object.keys(settings.filters);
27
+ return filterNames.reduce((current, key) => {
28
+ const queryValue = query[key];
29
+ const filter = settings.filters[key];
30
+ if (filter) {
31
+ const value = typeof filter === 'function' ? filter(queryValue, settings) : queryValue;
32
+ if (value !== undefined) {
33
+ current[key] = value;
34
+ }
35
+ }
36
+ return current;
37
+ }, {});
38
+ };
39
+ const getQuery = (query, settings) => {
40
+ const keys = Object.keys(query).concat(Object.getOwnPropertySymbols(query));
41
+ return keys.reduce((result, key) => {
42
+ if (typeof key === 'string' && key.startsWith('$')) {
43
+ if (settings.filters[key] === undefined) {
44
+ throw new errors_1.BadRequest(`Invalid filter value ${key}`);
45
+ }
46
+ }
47
+ else {
48
+ result[key] = validateQueryProperty(query[key], settings.operators);
49
+ }
50
+ return result;
51
+ }, {});
52
+ };
53
+ exports.OPERATORS = ['$in', '$nin', '$lt', '$lte', '$gt', '$gte', '$ne', '$or'];
54
+ exports.FILTERS = {
55
+ $skip: (value) => parse(value),
56
+ $sort: (sort) => {
57
+ if (typeof sort !== 'object' || Array.isArray(sort)) {
58
+ return sort;
59
+ }
60
+ return Object.keys(sort).reduce((result, key) => {
61
+ result[key] = typeof sort[key] === 'object'
62
+ ? sort[key] : parse(sort[key]);
63
+ return result;
64
+ }, {});
65
+ },
66
+ $limit: (_limit, { paginate }) => {
67
+ const limit = parse(_limit);
68
+ if (paginate && (paginate.default || paginate.max)) {
69
+ const base = paginate.default || 0;
70
+ const lower = typeof limit === 'number' && !isNaN(limit) && limit >= 0 ? limit : base;
71
+ const upper = typeof paginate.max === 'number' ? paginate.max : Number.MAX_VALUE;
72
+ return Math.min(lower, upper);
73
+ }
74
+ return limit;
75
+ },
76
+ $select: (select) => {
77
+ if (Array.isArray(select)) {
78
+ return select.map(current => `${current}`);
79
+ }
80
+ return select;
81
+ },
82
+ $or: (or, { operators }) => {
83
+ if (Array.isArray(or)) {
84
+ return or.map(current => validateQueryProperty(current, operators));
85
+ }
86
+ return or;
87
+ }
88
+ };
89
+ /**
90
+ * Converts Feathers special query parameters and pagination settings
91
+ * and returns them separately as `filters` and the rest of the query
92
+ * as `query`. `options` also gets passed the pagination settings and
93
+ * a list of additional `operators` to allow when querying properties.
94
+ *
95
+ * @param query The initial query
96
+ * @param options Options for filtering the query
97
+ * @returns An object with `query` which contains the query without `filters`
98
+ * and `filters` which contains the converted values for each filter.
99
+ */
100
+ function filterQuery(_query, options = {}) {
101
+ const query = _query || {};
102
+ const settings = {
103
+ ...options,
104
+ filters: {
105
+ ...exports.FILTERS,
106
+ ...options.filters
107
+ },
108
+ operators: exports.OPERATORS.concat(options.operators || [])
109
+ };
110
+ return {
111
+ filters: getFilters(query, settings),
112
+ query: getQuery(query, settings)
113
+ };
114
+ }
115
+ exports.filterQuery = filterQuery;
116
+ //# sourceMappingURL=query.js.map
@@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} from '@feathersjs/feathers';
2
- export interface Paginated<T> {
3
- total: number;
4
- limit: number;
5
- skip: number;
6
- data: T[];
7
- }
8
- export interface ServiceOptions {
9
- events: string[];
10
- multi: boolean | string[];
11
- id: string;
12
- paginate: {
13
- default?: number;
14
- max?: number;
15
- };
16
- whitelist: string[];
17
- filters: string[];
18
- }
1
+ import { Id, NullableId, Paginated, Query } from '@feathersjs/feathers';
2
+ import { AdapterParams, AdapterServiceOptions, InternalServiceMethods, PaginationOptions } from './declarations';
19
3
  /**
20
- * Hook-less (internal) service methods. Directly call database adapter service methods
21
- * without running any service-level hooks. This can be useful if you need the raw data
22
- * from the service and don't want to trigger any of its hooks.
23
- *
24
- * Important: These methods are only available internally on the server, not on the client
25
- * side and only for the Feathers database adapters.
26
- *
27
- * These methods do not trigger events.
28
- *
29
- * @see {@link https://docs.feathersjs.com/guides/migrating.html#hook-less-service-methods}
4
+ * An abstract base class that a database adapter can extend from to implement the
5
+ * `__find`, `__get`, `__update`, `__patch` and `__remove` methods.
30
6
  */
31
- export interface InternalServiceMethods<T = any> {
7
+ export declare abstract class AdapterBase<T = any, D = Partial<T>, P extends AdapterParams = AdapterParams, O extends AdapterServiceOptions = AdapterServiceOptions> implements InternalServiceMethods<T, D, P> {
8
+ options: O;
9
+ constructor(options: O);
10
+ get id(): string;
11
+ get events(): string[];
12
+ /**
13
+ * Check if this adapter allows multiple updates for a method.
14
+ * @param method The method name to check.
15
+ * @param params The service call params.
16
+ * @returns Wether or not multiple updates are allowed.
17
+ */
18
+ allowsMulti(method: string, params?: P): boolean;
19
+ /**
20
+ * Returns the combined options for a service call. Options will be merged
21
+ * with `this.options` and `params.adapter` for dynamic overrides.
22
+ *
23
+ * @param params The parameters for the service method call
24
+ * @returns The actual options for this call
25
+ */
26
+ getOptions(params: P): O;
32
27
  /**
33
- * Retrieve all resources from this service, skipping any service-level hooks.
28
+ * Sanitize the incoming data, e.g. removing invalid keywords etc.
29
+ *
30
+ * @param data The data to sanitize
31
+ * @param _params Service call parameters
32
+ * @returns The sanitized data
33
+ */
34
+ sanitizeData<X = Partial<D>>(data: X, _params: P): Promise<X>;
35
+ /**
36
+ * Returns a sanitized version of `params.query`, converting filter values
37
+ * (like $limit and $skip) into the expected type. Will throw an error if
38
+ * a `$` prefixed filter or operator value that is not allowed in `filters`
39
+ * or `operators` is encountered.
40
+ *
41
+ * @param params The service call parameter.
42
+ * @returns A new object containing the sanitized query.
43
+ */
44
+ sanitizeQuery(params?: P): Promise<Query>;
45
+ abstract $find(_params?: P & {
46
+ paginate?: PaginationOptions;
47
+ }): Promise<Paginated<T>>;
48
+ abstract $find(_params?: P & {
49
+ paginate: false;
50
+ }): Promise<T[]>;
51
+ abstract $find(params?: P): Promise<T[] | Paginated<T>>;
52
+ /**
53
+ * Retrieve all resources from this service, skipping any service-level hooks but sanitize the query
54
+ * with allowed filters and properties by calling `sanitizeQuery`.
34
55
  *
35
56
  * @param params - Service call parameters {@link Params}
36
57
  * @see {@link HookLessServiceMethods}
37
58
  * @see {@link https://docs.feathersjs.com/api/services.html#find-params|Feathers API Documentation: .find(params)}
38
59
  */
39
- _find(params?: Params): Promise<T | T[] | Paginated<T>>;
60
+ _find(_params?: P & {
61
+ paginate?: PaginationOptions;
62
+ }): Promise<Paginated<T>>;
63
+ _find(_params?: P & {
64
+ paginate: false;
65
+ }): Promise<T[]>;
66
+ _find(params?: P): Promise<T | T[] | Paginated<T>>;
67
+ abstract $get(id: Id, params?: P): Promise<T>;
40
68
  /**
41
- * Retrieve a single resource matching the given ID, skipping any service-level hooks.
69
+ * Retrieve a single resource matching the given ID, skipping any service-level hooks but sanitize the query
70
+ * with allowed filters and properties by calling `sanitizeQuery`.
42
71
  *
43
72
  * @param id - ID of the resource to locate
44
73
  * @param params - Service call parameters {@link Params}
45
74
  * @see {@link HookLessServiceMethods}
46
75
  * @see {@link https://docs.feathersjs.com/api/services.html#get-id-params|Feathers API Documentation: .get(id, params)}
47
76
  */
48
- _get(id: Id, params?: Params): Promise<T>;
77
+ _get(id: Id, params?: P): Promise<T>;
78
+ abstract $create(data: Partial<D>, params?: P): Promise<T>;
79
+ abstract $create(data: Partial<D>[], params?: P): Promise<T[]>;
80
+ abstract $create(data: Partial<D> | Partial<D>[], params?: P): Promise<T | T[]>;
49
81
  /**
50
- * Create a new resource for this service, skipping any service-level hooks.
82
+ * Create a new resource for this service, skipping any service-level hooks, sanitize the data
83
+ * and check if multiple updates are allowed.
51
84
  *
52
85
  * @param data - Data to insert into this service.
53
86
  * @param params - Service call parameters {@link Params}
54
87
  * @see {@link HookLessServiceMethods}
55
88
  * @see {@link https://docs.feathersjs.com/api/services.html#create-data-params|Feathers API Documentation: .create(data, params)}
56
89
  */
57
- _create(data: Partial<T> | Partial<T>[], params?: Params): Promise<T | T[]>;
90
+ _create(data: Partial<D>, params?: P): Promise<T>;
91
+ _create(data: Partial<D>[], params?: P): Promise<T[]>;
92
+ _create(data: Partial<D> | Partial<D>[], params?: P): Promise<T | T[]>;
93
+ abstract $update(id: Id, data: D, params?: P): Promise<T>;
58
94
  /**
59
95
  * Replace any resources matching the given ID with the given data, skipping any service-level hooks.
60
96
  *
@@ -64,9 +100,13 @@ export interface InternalServiceMethods<T = any> {
64
100
  * @see {@link HookLessServiceMethods}
65
101
  * @see {@link https://docs.feathersjs.com/api/services.html#update-id-data-params|Feathers API Documentation: .update(id, data, params)}
66
102
  */
67
- _update(id: Id, data: T, params?: Params): Promise<T>;
103
+ _update(id: Id, data: D, params?: P): Promise<T>;
104
+ abstract $patch(id: null, data: Partial<D>, params?: P): Promise<T[]>;
105
+ abstract $patch(id: Id, data: Partial<D>, params?: P): Promise<T>;
106
+ abstract $patch(id: NullableId, data: Partial<D>, params?: P): Promise<T | T[]>;
68
107
  /**
69
108
  * Merge any resources matching the given ID with the given data, skipping any service-level hooks.
109
+ * Sanitizes the query and data and checks it multiple updates are allowed.
70
110
  *
71
111
  * @param id - ID of the resource to be patched
72
112
  * @param data - Data to merge with the current resource.
@@ -74,38 +114,22 @@ export interface InternalServiceMethods<T = any> {
74
114
  * @see {@link HookLessServiceMethods}
75
115
  * @see {@link https://docs.feathersjs.com/api/services.html#patch-id-data-params|Feathers API Documentation: .patch(id, data, params)}
76
116
  */
77
- _patch(id: NullableId, data: Partial<T>, params?: Params): Promise<T | T[]>;
117
+ _patch(id: null, data: Partial<D>, params?: P): Promise<T[]>;
118
+ _patch(id: Id, data: Partial<D>, params?: P): Promise<T>;
119
+ _patch(id: NullableId, data: Partial<D>, params?: P): Promise<T | T[]>;
120
+ abstract $remove(id: null, params?: P): Promise<T[]>;
121
+ abstract $remove(id: Id, params?: P): Promise<T>;
122
+ abstract $remove(id: NullableId, params?: P): Promise<T | T[]>;
78
123
  /**
79
124
  * Remove resources matching the given ID from the this service, skipping any service-level hooks.
125
+ * Sanitized the query and verifies that multiple updates are allowed.
80
126
  *
81
127
  * @param id - ID of the resource to be removed
82
128
  * @param params - Service call parameters {@link Params}
83
129
  * @see {@link HookLessServiceMethods}
84
130
  * @see {@link https://docs.feathersjs.com/api/services.html#remove-id-params|Feathers API Documentation: .remove(id, params)}
85
131
  */
86
- _remove(id: NullableId, params?: Params): Promise<T | T[]>;
87
- }
88
- export declare class AdapterService<T = any> implements ServiceMethods<T | Paginated<T>> {
89
- options: ServiceOptions;
90
- constructor(options: Partial<ServiceOptions>);
91
- get id(): string;
92
- get events(): string[];
93
- filterQuery(params?: Params, opts?: any): {
94
- [key: string]: any;
95
- } & {
96
- paginate: any;
97
- };
98
- allowsMulti(method: string): boolean;
99
- find(params?: Params): Promise<T[] | Paginated<T>>;
100
- get(id: Id, params?: Params): Promise<T>;
101
- create(data: Partial<T>, params?: Params): Promise<T>;
102
- create(data: Partial<T>[], params?: Params): Promise<T[]>;
103
- update(id: Id, data: T, params?: Params): Promise<T>;
104
- patch(id: Id, data: Partial<T>, params?: Params): Promise<T>;
105
- patch(id: null, data: Partial<T>, params?: Params): Promise<T[]>;
106
- patch(id: NullableId, data: Partial<T>, params?: Params): Promise<T | T[]>;
107
- remove(id: Id, params?: Params): Promise<T>;
108
- remove(id: null, params?: Params): Promise<T[]>;
109
- remove(id: NullableId, params?: Params): Promise<T | T[]>;
110
- setup(): Promise<void>;
132
+ _remove(id: null, params?: P): Promise<T[]>;
133
+ _remove(id: Id, params?: P): Promise<T>;
134
+ _remove(id: NullableId, params?: P): Promise<T | T[]>;
111
135
  }
package/lib/service.js CHANGED
@@ -1,38 +1,28 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.AdapterService = void 0;
3
+ exports.AdapterBase = void 0;
13
4
  const errors_1 = require("@feathersjs/errors");
14
- const filter_query_1 = require("./filter-query");
15
- const callMethod = (self, name, ...args) => {
16
- if (typeof self[name] !== 'function') {
17
- return Promise.reject(new errors_1.NotImplemented(`Method ${name} not available`));
18
- }
19
- return self[name](...args);
20
- };
5
+ const query_1 = require("./query");
21
6
  const alwaysMulti = {
22
7
  find: true,
23
8
  get: false,
24
9
  update: false
25
10
  };
26
- class AdapterService {
11
+ /**
12
+ * An abstract base class that a database adapter can extend from to implement the
13
+ * `__find`, `__get`, `__update`, `__patch` and `__remove` methods.
14
+ */
15
+ class AdapterBase {
27
16
  constructor(options) {
28
- this.options = Object.assign({
17
+ this.options = {
29
18
  id: 'id',
30
19
  events: [],
31
- paginate: {},
20
+ paginate: false,
32
21
  multi: false,
33
- filters: [],
34
- whitelist: []
35
- }, options);
22
+ filters: {},
23
+ operators: [],
24
+ ...options
25
+ };
36
26
  }
37
27
  get id() {
38
28
  return this.options.id;
@@ -40,64 +30,138 @@ class AdapterService {
40
30
  get events() {
41
31
  return this.options.events;
42
32
  }
43
- filterQuery(params = {}, opts = {}) {
44
- const paginate = typeof params.paginate !== 'undefined'
45
- ? params.paginate : this.options.paginate;
46
- const { query = {} } = params;
47
- const options = Object.assign({
48
- operators: this.options.whitelist || [],
49
- filters: this.options.filters,
50
- paginate
51
- }, opts);
52
- const result = filter_query_1.filterQuery(query, options);
53
- return Object.assign(result, { paginate });
54
- }
55
- allowsMulti(method) {
33
+ /**
34
+ * Check if this adapter allows multiple updates for a method.
35
+ * @param method The method name to check.
36
+ * @param params The service call params.
37
+ * @returns Wether or not multiple updates are allowed.
38
+ */
39
+ allowsMulti(method, params = {}) {
56
40
  const always = alwaysMulti[method];
57
41
  if (typeof always !== 'undefined') {
58
42
  return always;
59
43
  }
60
- const option = this.options.multi;
61
- if (option === true || option === false) {
62
- return option;
63
- }
64
- else {
65
- return option.includes(method);
44
+ const { multi } = this.getOptions(params);
45
+ if (multi === true || multi === false) {
46
+ return multi;
66
47
  }
48
+ return multi.includes(method);
67
49
  }
68
- find(params) {
69
- return callMethod(this, '_find', params);
50
+ /**
51
+ * Returns the combined options for a service call. Options will be merged
52
+ * with `this.options` and `params.adapter` for dynamic overrides.
53
+ *
54
+ * @param params The parameters for the service method call
55
+ * @returns The actual options for this call
56
+ */
57
+ getOptions(params) {
58
+ const paginate = params.paginate !== undefined ? params.paginate : this.options.paginate;
59
+ return {
60
+ ...this.options,
61
+ paginate,
62
+ ...params.adapter
63
+ };
70
64
  }
71
- get(id, params) {
72
- return callMethod(this, '_get', id, params);
65
+ /**
66
+ * Sanitize the incoming data, e.g. removing invalid keywords etc.
67
+ *
68
+ * @param data The data to sanitize
69
+ * @param _params Service call parameters
70
+ * @returns The sanitized data
71
+ */
72
+ async sanitizeData(data, _params) {
73
+ return data;
73
74
  }
74
- create(data, params) {
75
- if (Array.isArray(data) && !this.allowsMulti('create')) {
76
- return Promise.reject(new errors_1.MethodNotAllowed('Can not create multiple entries'));
75
+ /**
76
+ * Returns a sanitized version of `params.query`, converting filter values
77
+ * (like $limit and $skip) into the expected type. Will throw an error if
78
+ * a `$` prefixed filter or operator value that is not allowed in `filters`
79
+ * or `operators` is encountered.
80
+ *
81
+ * @param params The service call parameter.
82
+ * @returns A new object containing the sanitized query.
83
+ */
84
+ async sanitizeQuery(params = {}) {
85
+ const options = this.getOptions(params);
86
+ const { query, filters } = (0, query_1.filterQuery)(params.query, options);
87
+ return {
88
+ ...filters,
89
+ ...query
90
+ };
91
+ }
92
+ async _find(params) {
93
+ const query = await this.sanitizeQuery(params);
94
+ return this.$find({
95
+ ...params,
96
+ query
97
+ });
98
+ }
99
+ /**
100
+ * Retrieve a single resource matching the given ID, skipping any service-level hooks but sanitize the query
101
+ * with allowed filters and properties by calling `sanitizeQuery`.
102
+ *
103
+ * @param id - ID of the resource to locate
104
+ * @param params - Service call parameters {@link Params}
105
+ * @see {@link HookLessServiceMethods}
106
+ * @see {@link https://docs.feathersjs.com/api/services.html#get-id-params|Feathers API Documentation: .get(id, params)}
107
+ */
108
+ async _get(id, params) {
109
+ const query = await this.sanitizeQuery(params);
110
+ return this.$get(id, {
111
+ ...params,
112
+ query
113
+ });
114
+ }
115
+ async _create(data, params) {
116
+ if (Array.isArray(data) && !this.allowsMulti('create', params)) {
117
+ throw new errors_1.MethodNotAllowed('Can not create multiple entries');
77
118
  }
78
- return callMethod(this, '_create', data, params);
119
+ const payload = Array.isArray(data)
120
+ ? (await Promise.all(data.map(current => this.sanitizeData(current, params))))
121
+ : (await this.sanitizeData(data, params));
122
+ return this.$create(payload, params);
79
123
  }
80
- update(id, data, params) {
124
+ /**
125
+ * Replace any resources matching the given ID with the given data, skipping any service-level hooks.
126
+ *
127
+ * @param id - ID of the resource to be updated
128
+ * @param data - Data to be put in place of the current resource.
129
+ * @param params - Service call parameters {@link Params}
130
+ * @see {@link HookLessServiceMethods}
131
+ * @see {@link https://docs.feathersjs.com/api/services.html#update-id-data-params|Feathers API Documentation: .update(id, data, params)}
132
+ */
133
+ async _update(id, data, params) {
81
134
  if (id === null || Array.isArray(data)) {
82
- return Promise.reject(new errors_1.BadRequest('You can not replace multiple instances. Did you mean \'patch\'?'));
135
+ throw new errors_1.BadRequest('You can not replace multiple instances. Did you mean \'patch\'?');
83
136
  }
84
- return callMethod(this, '_update', id, data, params);
137
+ const payload = await this.sanitizeData(data, params);
138
+ const query = await this.sanitizeQuery(params);
139
+ return this.$update(id, payload, {
140
+ ...params,
141
+ query
142
+ });
85
143
  }
86
- patch(id, data, params) {
87
- if (id === null && !this.allowsMulti('patch')) {
88
- return Promise.reject(new errors_1.MethodNotAllowed('Can not patch multiple entries'));
144
+ async _patch(id, data, params) {
145
+ if (id === null && !this.allowsMulti('patch', params)) {
146
+ throw new errors_1.MethodNotAllowed('Can not patch multiple entries');
89
147
  }
90
- return callMethod(this, '_patch', id, data, params);
148
+ const query = await this.sanitizeQuery(params);
149
+ const payload = await this.sanitizeData(data, params);
150
+ return this.$patch(id, payload, {
151
+ ...params,
152
+ query
153
+ });
91
154
  }
92
- remove(id, params) {
93
- if (id === null && !this.allowsMulti('remove')) {
94
- return Promise.reject(new errors_1.MethodNotAllowed('Can not remove multiple entries'));
155
+ async _remove(id, params) {
156
+ if (id === null && !this.allowsMulti('remove', params)) {
157
+ throw new errors_1.MethodNotAllowed('Can not remove multiple entries');
95
158
  }
96
- return callMethod(this, '_remove', id, params);
97
- }
98
- setup() {
99
- return __awaiter(this, void 0, void 0, function* () { });
159
+ const query = await this.sanitizeQuery(params);
160
+ return this.$remove(id, {
161
+ ...params,
162
+ query
163
+ });
100
164
  }
101
165
  }
102
- exports.AdapterService = AdapterService;
166
+ exports.AdapterBase = AdapterBase;
103
167
  //# sourceMappingURL=service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,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yBAAgB,CAAC,iCAAiC,CAAC,CAAC;SAC/D;QAED,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAE/C,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE;YACtB,GAAG,MAAM;YACT,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF;AA/PD,kCA+PC"}
package/lib/sort.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export declare function compareNSB(a: any, b: any): 1 | 0 | -1;
2
- export declare function compareArrays(a: any, b: any): any;
3
- export declare function compare(a: any, b: any, compareStrings?: any): any;
4
- export declare function sorter($sort: any): (a: any, b: any) => number;
1
+ export declare function compareNSB(a: any, b: any): 1 | -1 | 0;
2
+ export declare function compareArrays(a: any[], b: any[]): 1 | -1 | 0;
3
+ export declare function compare(a: any, b: any, compareStrings?: any): 0 | 1 | -1;
4
+ export declare function sorter($sort: {
5
+ [key: string]: -1 | 1;
6
+ }): (a: any, b: any) => number;