@feathersjs/memory 5.0.0-pre.18 → 5.0.0-pre.19

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/CHANGELOG.md CHANGED
@@ -3,6 +3,29 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [5.0.0-pre.19](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.18...v5.0.0-pre.19) (2022-05-01)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **adapter-commons:** Clarify adapter query filtering ([#2607](https://github.com/feathersjs/feathers/issues/2607)) ([2dac771](https://github.com/feathersjs/feathers/commit/2dac771b0a3298d6dd25994d05186701b0617718))
12
+
13
+
14
+ ### Features
15
+
16
+ * **mongodb:** Add feathers-mongodb adapter as @feathersjs/mongodb ([#2610](https://github.com/feathersjs/feathers/issues/2610)) ([6d43734](https://github.com/feathersjs/feathers/commit/6d43734a53db02c435cafc52a22dca414e5d0940))
17
+ * **typescript:** Improve adapter typings ([#2605](https://github.com/feathersjs/feathers/issues/2605)) ([3b2ca0a](https://github.com/feathersjs/feathers/commit/3b2ca0a6a8e03e8390272c4d7e930b4bffdaacf5))
18
+ * **typescript:** Improve params and query typeability ([#2600](https://github.com/feathersjs/feathers/issues/2600)) ([df28b76](https://github.com/feathersjs/feathers/commit/df28b7619161f1df5e700326f52cca1a92dc5d28))
19
+
20
+
21
+ ### BREAKING CHANGES
22
+
23
+ * **adapter-commons:** Changes the common adapter base class to use `sanitizeQuery` and `sanitizeData`
24
+
25
+
26
+
27
+
28
+
6
29
  # [5.0.0-pre.18](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.17...v5.0.0-pre.18) (2022-04-11)
7
30
 
8
31
 
package/lib/index.d.ts CHANGED
@@ -1,30 +1,64 @@
1
- import { AdapterService, ServiceOptions, InternalServiceMethods, AdapterParams } from '@feathersjs/adapter-commons';
2
- import { NullableId, Id } from '@feathersjs/feathers';
1
+ import { AdapterBase, AdapterServiceOptions, PaginationOptions, AdapterParams } from '@feathersjs/adapter-commons';
2
+ import { NullableId, Id, Params, ServiceMethods, Paginated } from '@feathersjs/feathers';
3
3
  export interface MemoryServiceStore<T> {
4
4
  [key: string]: T;
5
5
  }
6
- export interface MemoryServiceOptions<T = any> extends ServiceOptions {
7
- store: MemoryServiceStore<T>;
8
- startId: number;
6
+ export interface MemoryServiceOptions<T = any> extends AdapterServiceOptions {
7
+ store?: MemoryServiceStore<T>;
8
+ startId?: number;
9
9
  matcher?: (query: any) => any;
10
10
  sorter?: (sort: any) => any;
11
11
  }
12
- export declare class Service<T = any, D = Partial<T>> extends AdapterService<T, D> implements InternalServiceMethods<T> {
13
- options: MemoryServiceOptions;
12
+ export declare class MemoryAdapter<T = any, D = Partial<T>, P extends Params = Params> extends AdapterBase<T, D, P, MemoryServiceOptions<T>> {
14
13
  store: MemoryServiceStore<T>;
15
14
  _uId: number;
16
- constructor(options?: Partial<MemoryServiceOptions<T>>);
17
- getEntries(params?: {}): Promise<T[]>;
18
- _find(params?: AdapterParams): Promise<any[] | {
19
- total: number;
20
- limit: any;
21
- skip: any;
22
- data: any[];
23
- }>;
24
- _get(id: Id, params?: AdapterParams): Promise<any>;
25
- _create(data: Partial<T> | Partial<T>[], params?: AdapterParams): Promise<T | T[]>;
26
- _update(id: NullableId, data: T, params?: AdapterParams): Promise<any>;
27
- _patch(id: NullableId, data: Partial<T>, params?: AdapterParams): Promise<any>;
28
- _remove(id: NullableId, params?: AdapterParams): Promise<T | T[]>;
15
+ constructor(options?: MemoryServiceOptions<T>);
16
+ getEntries(_params?: P): Promise<T[]>;
17
+ getQuery(params: P): {
18
+ query: {
19
+ [key: string]: any;
20
+ };
21
+ filters: {
22
+ $skip: any;
23
+ $sort: any;
24
+ $limit: any;
25
+ $select: any;
26
+ };
27
+ };
28
+ $find(_params?: P & {
29
+ paginate?: PaginationOptions;
30
+ }): Promise<Paginated<T>>;
31
+ $find(_params?: P & {
32
+ paginate: false;
33
+ }): Promise<T[]>;
34
+ $find(_params?: P): Promise<Paginated<T> | T[]>;
35
+ $get(id: Id, params?: P): Promise<T>;
36
+ $create(data: Partial<D>, params?: P): Promise<T>;
37
+ $create(data: Partial<D>[], params?: P): Promise<T[]>;
38
+ $create(data: Partial<D> | Partial<D>[], _params?: P): Promise<T | T[]>;
39
+ $update(id: Id, data: D, params?: P): Promise<T>;
40
+ $patch(id: null, data: Partial<D>, params?: P): Promise<T[]>;
41
+ $patch(id: Id, data: Partial<D>, params?: P): Promise<T>;
42
+ $patch(id: NullableId, data: Partial<D>, _params?: P): Promise<T | T[]>;
43
+ $remove(id: null, params?: P): Promise<T[]>;
44
+ $remove(id: Id, params?: P): Promise<T>;
45
+ $remove(id: NullableId, _params?: P): Promise<T | T[]>;
46
+ }
47
+ export declare class MemoryService<T = any, D = Partial<T>, P extends AdapterParams = AdapterParams> extends MemoryAdapter<T, D, P> implements ServiceMethods<T | Paginated<T>, D, P> {
48
+ find(params?: P & {
49
+ paginate?: PaginationOptions;
50
+ }): Promise<Paginated<T>>;
51
+ find(params?: P & {
52
+ paginate: false;
53
+ }): Promise<T[]>;
54
+ find(params?: P): Promise<Paginated<T> | T[]>;
55
+ get(id: Id, params?: P): Promise<T>;
56
+ create(data: Partial<D>, params?: P): Promise<T>;
57
+ create(data: Partial<D>[], params?: P): Promise<T[]>;
58
+ update(id: Id, data: D, params?: P): Promise<T>;
59
+ patch(id: Id, data: Partial<D>, params?: P): Promise<T>;
60
+ patch(id: null, data: Partial<D>, params?: P): Promise<T[]>;
61
+ remove(id: Id, params?: P): Promise<T>;
62
+ remove(id: null, params?: P): Promise<T[]>;
29
63
  }
30
- export declare function memory(options?: Partial<MemoryServiceOptions>): Service<any, Partial<any>>;
64
+ export declare function memory<T = any, D = Partial<T>, P extends Params = Params>(options?: Partial<MemoryServiceOptions<T>>): MemoryService<T, D, P>;
package/lib/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.memory = exports.Service = void 0;
6
+ exports.memory = exports.MemoryService = exports.MemoryAdapter = void 0;
7
7
  const errors_1 = require("@feathersjs/errors");
8
8
  const commons_1 = require("@feathersjs/commons");
9
9
  const adapter_commons_1 = require("@feathersjs/adapter-commons");
@@ -12,25 +12,36 @@ const _select = (data, params, ...args) => {
12
12
  const base = (0, adapter_commons_1.select)(params, ...args);
13
13
  return base(JSON.parse(JSON.stringify(data)));
14
14
  };
15
- class Service extends adapter_commons_1.AdapterService {
15
+ class MemoryAdapter extends adapter_commons_1.AdapterBase {
16
16
  constructor(options = {}) {
17
- super(commons_1._.extend({
17
+ super({
18
18
  id: 'id',
19
19
  matcher: sift_1.default,
20
- sorter: adapter_commons_1.sorter
21
- }, options));
22
- this._uId = options.startId || 0;
23
- this.store = options.store || {};
20
+ sorter: adapter_commons_1.sorter,
21
+ store: {},
22
+ startId: 0,
23
+ ...options
24
+ });
25
+ this._uId = this.options.startId;
26
+ this.store = { ...this.options.store };
24
27
  }
25
- async getEntries(params = {}) {
26
- const { query } = this.filterQuery(params);
27
- return this._find(Object.assign({}, params, {
28
- paginate: false,
29
- query
30
- }));
28
+ async getEntries(_params) {
29
+ const params = _params || {};
30
+ return this.$find({
31
+ ...params,
32
+ paginate: false
33
+ });
31
34
  }
32
- async _find(params = {}) {
33
- const { query, filters, paginate } = this.filterQuery(params);
35
+ getQuery(params) {
36
+ const { $skip, $sort, $limit, $select, ...query } = params.query || {};
37
+ return {
38
+ query,
39
+ filters: { $skip, $sort, $limit, $select }
40
+ };
41
+ }
42
+ async $find(params = {}) {
43
+ const { paginate } = this.getOptions(params);
44
+ const { query, filters } = this.getQuery(params);
34
45
  let values = commons_1._.values(this.store).filter(this.options.matcher(query));
35
46
  const total = values.length;
36
47
  if (filters.$sort !== undefined) {
@@ -48,14 +59,14 @@ class Service extends adapter_commons_1.AdapterService {
48
59
  skip: filters.$skip || 0,
49
60
  data: values.map(value => _select(value, params))
50
61
  };
51
- if (!(paginate && (paginate).default)) {
62
+ if (!paginate) {
52
63
  return result.data;
53
64
  }
54
65
  return result;
55
66
  }
56
- async _get(id, params = {}) {
67
+ async $get(id, params = {}) {
68
+ const { query } = this.getQuery(params);
57
69
  if (id in this.store) {
58
- const { query } = this.filterQuery(params);
59
70
  const value = this.store[id];
60
71
  if (this.options.matcher(query)(value)) {
61
72
  return _select(value, params, this.id);
@@ -63,51 +74,78 @@ class Service extends adapter_commons_1.AdapterService {
63
74
  }
64
75
  throw new errors_1.NotFound(`No record found for id '${id}'`);
65
76
  }
66
- // Create without hooks and mixins that can be used internally
67
- async _create(data, params = {}) {
77
+ async $create(data, params = {}) {
68
78
  if (Array.isArray(data)) {
69
- return Promise.all(data.map(current => this._create(current, params)));
79
+ return Promise.all(data.map(current => this.$create(current, params)));
70
80
  }
71
81
  const id = data[this.id] || this._uId++;
72
82
  const current = commons_1._.extend({}, data, { [this.id]: id });
73
83
  const result = (this.store[id] = current);
74
84
  return _select(result, params, this.id);
75
85
  }
76
- async _update(id, data, params = {}) {
77
- const oldEntry = await this._get(id);
86
+ async $update(id, data, params = {}) {
87
+ const oldEntry = await this.$get(id);
78
88
  // We don't want our id to change type if it can be coerced
79
89
  const oldId = oldEntry[this.id];
80
90
  // eslint-disable-next-line eqeqeq
81
91
  id = oldId == id ? oldId : id;
82
92
  this.store[id] = commons_1._.extend({}, data, { [this.id]: id });
83
- return this._get(id, params);
93
+ return this.$get(id, params);
84
94
  }
85
- async _patch(id, data, params = {}) {
95
+ async $patch(id, data, params = {}) {
96
+ const { query } = this.getQuery(params);
86
97
  const patchEntry = (entry) => {
87
98
  const currentId = entry[this.id];
88
99
  this.store[currentId] = commons_1._.extend(this.store[currentId], commons_1._.omit(data, this.id));
89
100
  return _select(this.store[currentId], params, this.id);
90
101
  };
91
102
  if (id === null) {
92
- const entries = await this.getEntries(params);
103
+ const entries = await this.getEntries({
104
+ ...params,
105
+ query
106
+ });
93
107
  return entries.map(patchEntry);
94
108
  }
95
- return patchEntry(await this._get(id, params)); // Will throw an error if not found
109
+ return patchEntry(await this.$get(id, params)); // Will throw an error if not found
96
110
  }
97
- // Remove without hooks and mixins that can be used internally
98
- async _remove(id, params = {}) {
111
+ async $remove(id, params = {}) {
112
+ const { query } = this.getQuery(params);
99
113
  if (id === null) {
100
- const entries = await this.getEntries(params);
101
- return Promise.all(entries.map(current => this._remove(current[this.id], params)));
114
+ const entries = await this.getEntries({
115
+ ...params,
116
+ query
117
+ });
118
+ return Promise.all(entries.map((current) => this.$remove(current[this.id], params)));
102
119
  }
103
- const entry = await this._get(id, params);
120
+ const entry = await this.$get(id, params);
104
121
  delete this.store[id];
105
122
  return entry;
106
123
  }
107
124
  }
108
- exports.Service = Service;
125
+ exports.MemoryAdapter = MemoryAdapter;
126
+ class MemoryService extends MemoryAdapter {
127
+ async find(params) {
128
+ return this._find(params);
129
+ }
130
+ async get(id, params) {
131
+ return this._get(id, params);
132
+ }
133
+ async create(data, params) {
134
+ return this._create(data, params);
135
+ }
136
+ async update(id, data, params) {
137
+ return this._update(id, data, params);
138
+ }
139
+ async patch(id, data, params) {
140
+ return this._patch(id, data, params);
141
+ }
142
+ async remove(id, params) {
143
+ return this._remove(id, params);
144
+ }
145
+ }
146
+ exports.MemoryService = MemoryService;
109
147
  function memory(options = {}) {
110
- return new Service(options);
148
+ return new MemoryService(options);
111
149
  }
112
150
  exports.memory = memory;
113
151
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,+CAA8C;AAC9C,iDAAwC;AACxC,iEAAoI;AACpI,gDAAwB;AAcxB,MAAM,OAAO,GAAG,CAAC,IAAS,EAAE,MAAW,EAAE,GAAG,IAAW,EAAE,EAAE;IACzD,MAA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AC;IACnC,CAAC;IAED,KAAK,CAAC,GAAG,CAAE,EAAM,EAAE,MAAU;QAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAC/B,CAAC;IAID,KAAK,CAAC,MAAM,CAAE,IAA6B,EAAE,MAAU;QACrD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,MAAM,CAAE,EAAM,EAAE,IAAO,EAAE,MAAU;QACvC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;IAID,KAAK,CAAC,KAAK,CAAE,EAAc,EAAE,IAAgB,EAAE,MAAU;QACvD,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAID,KAAK,CAAC,MAAM,CAAE,EAAc,EAAE,MAAU;QACtC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAClC,CAAC;CACF;AAlCD,sCAkCC;AAED,SAAgB,MAAM,CACpB,UAA4C,EAAE;IAE9C,OAAO,IAAI,aAAa,CAAU,OAAO,CAAC,CAAA;AAC5C,CAAC;AAJD,wBAIC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@feathersjs/memory",
3
3
  "description": "An in memory service store",
4
- "version": "5.0.0-pre.18",
4
+ "version": "5.0.0-pre.19",
5
5
  "homepage": "https://github.com/feathersjs/feathers",
6
6
  "main": "lib/",
7
7
  "types": "lib/",
@@ -47,20 +47,20 @@
47
47
  "lib": "lib"
48
48
  },
49
49
  "dependencies": {
50
- "@feathersjs/adapter-commons": "^5.0.0-pre.18",
51
- "@feathersjs/commons": "^5.0.0-pre.18",
52
- "@feathersjs/errors": "^5.0.0-pre.18",
50
+ "@feathersjs/adapter-commons": "^5.0.0-pre.19",
51
+ "@feathersjs/commons": "^5.0.0-pre.19",
52
+ "@feathersjs/errors": "^5.0.0-pre.19",
53
53
  "sift": "^16.0.0"
54
54
  },
55
55
  "devDependencies": {
56
- "@feathersjs/adapter-tests": "^5.0.0-pre.18",
57
- "@feathersjs/feathers": "^5.0.0-pre.18",
58
- "@types/mocha": "^9.1.0",
59
- "@types/node": "^17.0.23",
60
- "mocha": "^9.2.2",
56
+ "@feathersjs/adapter-tests": "^5.0.0-pre.19",
57
+ "@feathersjs/feathers": "^5.0.0-pre.19",
58
+ "@types/mocha": "^9.1.1",
59
+ "@types/node": "^17.0.31",
60
+ "mocha": "^10.0.0",
61
61
  "shx": "^0.3.4",
62
62
  "ts-node": "^10.7.0",
63
- "typescript": "^4.6.3"
63
+ "typescript": "^4.6.4"
64
64
  },
65
- "gitHead": "c0b7b67d872dcd6b6d94e4587f21332c8a519b50"
65
+ "gitHead": "57f3e18bb62735e1869ffafee90286498738fdfa"
66
66
  }
package/src/index.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import { NotFound } from '@feathersjs/errors';
2
2
  import { _ } from '@feathersjs/commons';
3
- import { sorter, select, AdapterService, ServiceOptions, InternalServiceMethods, AdapterParams } from '@feathersjs/adapter-commons';
3
+ import { sorter, select, AdapterBase, AdapterServiceOptions, PaginationOptions, AdapterParams } from '@feathersjs/adapter-commons';
4
4
  import sift from 'sift';
5
- import { NullableId, Id } from '@feathersjs/feathers';
5
+ import { NullableId, Id, Params, ServiceMethods, Paginated } from '@feathersjs/feathers';
6
6
 
7
7
  export interface MemoryServiceStore<T> {
8
8
  [key: string]: T;
9
9
  }
10
10
 
11
- export interface MemoryServiceOptions<T = any> extends ServiceOptions {
12
- store: MemoryServiceStore<T>;
13
- startId: number;
11
+ export interface MemoryServiceOptions<T = any> extends AdapterServiceOptions {
12
+ store?: MemoryServiceStore<T>;
13
+ startId?: number;
14
14
  matcher?: (query: any) => any;
15
15
  sorter?: (sort: any) => any;
16
16
  }
@@ -21,32 +21,48 @@ const _select = (data: any, params: any, ...args: any[]) => {
21
21
  return base(JSON.parse(JSON.stringify(data)));
22
22
  };
23
23
 
24
- export class Service<T = any, D = Partial<T>> extends AdapterService<T, D> implements InternalServiceMethods<T> {
25
- options: MemoryServiceOptions;
24
+ export class MemoryAdapter<T = any, D = Partial<T>, P extends Params = Params> extends AdapterBase<T, D, P, MemoryServiceOptions<T>> {
26
25
  store: MemoryServiceStore<T>;
27
26
  _uId: number;
28
27
 
29
- constructor (options: Partial<MemoryServiceOptions<T>> = {}) {
30
- super(_.extend({
28
+ constructor (options: MemoryServiceOptions<T> = {}) {
29
+ super({
31
30
  id: 'id',
32
31
  matcher: sift,
33
- sorter
34
- }, options));
35
- this._uId = options.startId || 0;
36
- this.store = options.store || {};
32
+ sorter,
33
+ store: {},
34
+ startId: 0,
35
+ ...options
36
+ });
37
+ this._uId = this.options.startId;
38
+ this.store = { ...this.options.store };
39
+ }
40
+
41
+ async getEntries (_params?: P) {
42
+ const params = _params || {} as P;
43
+
44
+ return this.$find({
45
+ ...params,
46
+ paginate: false
47
+ });
37
48
  }
38
49
 
39
- async getEntries (params = {}) {
40
- const { query } = this.filterQuery(params);
50
+ getQuery (params: P) {
51
+ const { $skip, $sort, $limit, $select, ...query } = params.query || {};
41
52
 
42
- return this._find(Object.assign({}, params, {
43
- paginate: false,
44
- query
45
- }) as any) as Promise<T[]>;
53
+ return {
54
+ query,
55
+ filters: { $skip, $sort, $limit, $select }
56
+ }
46
57
  }
47
58
 
48
- async _find (params: AdapterParams = {}) {
49
- const { query, filters, paginate } = this.filterQuery(params);
59
+ async $find (_params?: P & { paginate?: PaginationOptions }): Promise<Paginated<T>>;
60
+ async $find (_params?: P & { paginate: false }): Promise<T[]>;
61
+ async $find (_params?: P): Promise<Paginated<T>|T[]>;
62
+ async $find (params: P = {} as P): Promise<Paginated<T>|T[]> {
63
+ const { paginate } = this.getOptions(params);
64
+ const { query, filters } = this.getQuery(params);
65
+
50
66
  let values = _.values(this.store).filter(this.options.matcher(query));
51
67
  const total = values.length;
52
68
 
@@ -62,23 +78,24 @@ export class Service<T = any, D = Partial<T>> extends AdapterService<T, D> imple
62
78
  values = values.slice(0, filters.$limit);
63
79
  }
64
80
 
65
- const result = {
81
+ const result: Paginated<T> = {
66
82
  total,
67
83
  limit: filters.$limit,
68
84
  skip: filters.$skip || 0,
69
85
  data: values.map(value => _select(value, params))
70
86
  };
71
87
 
72
- if (!(paginate && (paginate ).default)) {
88
+ if (!paginate) {
73
89
  return result.data;
74
90
  }
75
91
 
76
92
  return result;
77
93
  }
78
94
 
79
- async _get (id: Id, params: AdapterParams = {}) {
95
+ async $get (id: Id, params: P = {} as P): Promise<T> {
96
+ const { query } = this.getQuery(params);
97
+
80
98
  if (id in this.store) {
81
- const { query } = this.filterQuery(params);
82
99
  const value = this.store[id];
83
100
 
84
101
  if (this.options.matcher(query)(value)) {
@@ -89,33 +106,39 @@ export class Service<T = any, D = Partial<T>> extends AdapterService<T, D> imple
89
106
  throw new NotFound(`No record found for id '${id}'`);
90
107
  }
91
108
 
92
- // Create without hooks and mixins that can be used internally
93
- async _create (data: Partial<T> | Partial<T>[], params: AdapterParams = {}): Promise<T | T[]> {
109
+ async $create (data: Partial<D>, params?: P): Promise<T>;
110
+ async $create (data: Partial<D>[], params?: P): Promise<T[]>;
111
+ async $create (data: Partial<D>|Partial<D>[], _params?: P): Promise<T|T[]>;
112
+ async $create (data: Partial<D>|Partial<D>[], params: P = {} as P): Promise<T|T[]> {
94
113
  if (Array.isArray(data)) {
95
- return Promise.all(data.map(current => this._create(current, params) as Promise<T>));
114
+ return Promise.all(data.map(current => this.$create(current, params)));
96
115
  }
97
116
 
98
117
  const id = (data as any)[this.id] || this._uId++;
99
118
  const current = _.extend({}, data, { [this.id]: id });
100
119
  const result = (this.store[id] = current);
101
120
 
102
- return _select(result, params, this.id);
121
+ return _select(result, params, this.id) as T;
103
122
  }
104
123
 
105
- async _update (id: NullableId, data: T, params: AdapterParams = {}) {
106
- const oldEntry = await this._get(id);
124
+ async $update (id: Id, data: D, params: P = {} as P): Promise<T> {
125
+ const oldEntry = await this.$get(id);
107
126
  // We don't want our id to change type if it can be coerced
108
- const oldId = oldEntry[this.id];
127
+ const oldId = (oldEntry as any)[this.id];
109
128
 
110
129
  // eslint-disable-next-line eqeqeq
111
130
  id = oldId == id ? oldId : id;
112
131
 
113
132
  this.store[id] = _.extend({}, data, { [this.id]: id });
114
133
 
115
- return this._get(id, params);
134
+ return this.$get(id, params);
116
135
  }
117
136
 
118
- async _patch (id: NullableId, data: Partial<T>, params: AdapterParams = {}) {
137
+ async $patch (id: null, data: Partial<D>, params?: P): Promise<T[]>;
138
+ async $patch (id: Id, data: Partial<D>, params?: P): Promise<T>;
139
+ async $patch (id: NullableId, data: Partial<D>, _params?: P): Promise<T|T[]>;
140
+ async $patch (id: NullableId, data: Partial<D>, params: P = {} as P): Promise<T|T[]> {
141
+ const { query } = this.getQuery(params);
119
142
  const patchEntry = (entry: T) => {
120
143
  const currentId = (entry as any)[this.id];
121
144
 
@@ -125,25 +148,35 @@ export class Service<T = any, D = Partial<T>> extends AdapterService<T, D> imple
125
148
  };
126
149
 
127
150
  if (id === null) {
128
- const entries = await this.getEntries(params);
151
+ const entries = await this.getEntries({
152
+ ...params,
153
+ query
154
+ });
129
155
 
130
156
  return entries.map(patchEntry);
131
157
  }
132
158
 
133
- return patchEntry(await this._get(id, params)); // Will throw an error if not found
159
+ return patchEntry(await this.$get(id, params)); // Will throw an error if not found
134
160
  }
135
161
 
136
- // Remove without hooks and mixins that can be used internally
137
- async _remove (id: NullableId, params: AdapterParams = {}): Promise<T|T[]> {
162
+ async $remove (id: null, params?: P): Promise<T[]>;
163
+ async $remove (id: Id, params?: P): Promise<T>;
164
+ async $remove (id: NullableId, _params?: P): Promise<T|T[]>;
165
+ async $remove (id: NullableId, params: P = {} as P): Promise<T|T[]> {
166
+ const { query } = this.getQuery(params);
167
+
138
168
  if (id === null) {
139
- const entries = await this.getEntries(params);
169
+ const entries = await this.getEntries({
170
+ ...params,
171
+ query
172
+ });
140
173
 
141
- return Promise.all(entries.map(current =>
142
- this._remove((current as any)[this.id], params) as Promise<T>
174
+ return Promise.all(entries.map((current: any) =>
175
+ this.$remove(current[this.id] as Id, params)
143
176
  ));
144
177
  }
145
178
 
146
- const entry = await this._get(id, params);
179
+ const entry = await this.$get(id, params);
147
180
 
148
181
  delete this.store[id];
149
182
 
@@ -151,6 +184,44 @@ export class Service<T = any, D = Partial<T>> extends AdapterService<T, D> imple
151
184
  }
152
185
  }
153
186
 
154
- export function memory (options: Partial<MemoryServiceOptions> = {}) {
155
- return new Service(options);
187
+ export class MemoryService<T = any, D = Partial<T>, P extends AdapterParams = AdapterParams>
188
+ extends MemoryAdapter<T, D, P> implements ServiceMethods<T|Paginated<T>, D, P> {
189
+ async find (params?: P & { paginate?: PaginationOptions }): Promise<Paginated<T>>;
190
+ async find (params?: P & { paginate: false }): Promise<T[]>;
191
+ async find (params?: P): Promise<Paginated<T>|T[]>;
192
+ async find (params?: P): Promise<Paginated<T>|T[]> {
193
+ return this._find(params) as any;
194
+ }
195
+
196
+ async get (id: Id, params?: P): Promise<T> {
197
+ return this._get(id, params);
198
+ }
199
+
200
+ async create (data: Partial<D>, params?: P): Promise<T>;
201
+ async create (data: Partial<D>[], params?: P): Promise<T[]>;
202
+ async create (data: Partial<D>|Partial<D>[], params?: P): Promise<T|T[]> {
203
+ return this._create(data, params);
204
+ }
205
+
206
+ async update (id: Id, data: D, params?: P): Promise<T> {
207
+ return this._update(id, data, params);
208
+ }
209
+
210
+ async patch (id: Id, data: Partial<D>, params?: P): Promise<T>;
211
+ async patch (id: null, data: Partial<D>, params?: P): Promise<T[]>;
212
+ async patch (id: NullableId, data: Partial<D>, params?: P): Promise<T | T[]> {
213
+ return this._patch(id, data, params);
214
+ }
215
+
216
+ async remove (id: Id, params?: P): Promise<T>;
217
+ async remove (id: null, params?: P): Promise<T[]>;
218
+ async remove (id: NullableId, params?: P): Promise<T | T[]> {
219
+ return this._remove(id, params);
220
+ }
221
+ }
222
+
223
+ export function memory<T = any, D = Partial<T>, P extends Params = Params> (
224
+ options: Partial<MemoryServiceOptions<T>> = {}
225
+ ) {
226
+ return new MemoryService<T, D, P>(options)
156
227
  }