@feathersjs/memory 5.0.0-pre.33 → 5.0.0-pre.35
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 +12 -0
- package/lib/index.d.ts +37 -37
- package/lib/index.js +47 -18
- package/lib/index.js.map +1 -1
- package/package.json +12 -12
- package/src/index.ts +109 -65
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
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.35](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.34...v5.0.0-pre.35) (2023-01-12)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **generators:** Move core code generators to shared generators package ([#2982](https://github.com/feathersjs/feathers/issues/2982)) ([0328d22](https://github.com/feathersjs/feathers/commit/0328d2292153870bc43958f73d2c6f288a8cec17))
|
|
11
|
+
|
|
12
|
+
# [5.0.0-pre.34](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.33...v5.0.0-pre.34) (2022-12-14)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- **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))
|
|
17
|
+
|
|
6
18
|
# [5.0.0-pre.33](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.32...v5.0.0-pre.33) (2022-11-08)
|
|
7
19
|
|
|
8
20
|
### Bug Fixes
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AdapterBase, AdapterServiceOptions, PaginationOptions, AdapterParams } from '@feathersjs/adapter-commons';
|
|
2
|
-
import { NullableId, Id, Params,
|
|
2
|
+
import { NullableId, Id, Params, Paginated } from '@feathersjs/feathers';
|
|
3
3
|
export interface MemoryServiceStore<T> {
|
|
4
4
|
[key: string]: T;
|
|
5
5
|
}
|
|
@@ -9,12 +9,12 @@ export interface MemoryServiceOptions<T = any> extends AdapterServiceOptions {
|
|
|
9
9
|
matcher?: (query: any) => any;
|
|
10
10
|
sorter?: (sort: any) => any;
|
|
11
11
|
}
|
|
12
|
-
export declare class MemoryAdapter<
|
|
13
|
-
store: MemoryServiceStore<
|
|
12
|
+
export declare class MemoryAdapter<Result = any, Data = Partial<Result>, ServiceParams extends Params = Params, PatchData = Partial<Data>> extends AdapterBase<Result, Data, PatchData, ServiceParams, MemoryServiceOptions<Result>> {
|
|
13
|
+
store: MemoryServiceStore<Result>;
|
|
14
14
|
_uId: number;
|
|
15
|
-
constructor(options?: MemoryServiceOptions<
|
|
16
|
-
getEntries(_params?:
|
|
17
|
-
getQuery(params:
|
|
15
|
+
constructor(options?: MemoryServiceOptions<Result>);
|
|
16
|
+
getEntries(_params?: ServiceParams): Promise<Result[]>;
|
|
17
|
+
getQuery(params: ServiceParams): {
|
|
18
18
|
query: {
|
|
19
19
|
[key: string]: any;
|
|
20
20
|
};
|
|
@@ -25,40 +25,40 @@ export declare class MemoryAdapter<T = any, D = Partial<T>, P extends Params = P
|
|
|
25
25
|
$select: any;
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
-
|
|
28
|
+
_find(_params?: ServiceParams & {
|
|
29
29
|
paginate?: PaginationOptions;
|
|
30
|
-
}): Promise<Paginated<
|
|
31
|
-
|
|
30
|
+
}): Promise<Paginated<Result>>;
|
|
31
|
+
_find(_params?: ServiceParams & {
|
|
32
32
|
paginate: false;
|
|
33
|
-
}): Promise<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
}): Promise<Result[]>;
|
|
34
|
+
_find(_params?: ServiceParams): Promise<Paginated<Result> | Result[]>;
|
|
35
|
+
_get(id: Id, params?: ServiceParams): Promise<Result>;
|
|
36
|
+
_create(data: Partial<Data>, params?: ServiceParams): Promise<Result>;
|
|
37
|
+
_create(data: Partial<Data>[], params?: ServiceParams): Promise<Result[]>;
|
|
38
|
+
_create(data: Partial<Data> | Partial<Data>[], _params?: ServiceParams): Promise<Result | Result[]>;
|
|
39
|
+
_update(id: Id, data: Data, params?: ServiceParams): Promise<Result>;
|
|
40
|
+
_patch(id: null, data: PatchData, params?: ServiceParams): Promise<Result[]>;
|
|
41
|
+
_patch(id: Id, data: PatchData, params?: ServiceParams): Promise<Result>;
|
|
42
|
+
_patch(id: NullableId, data: PatchData, _params?: ServiceParams): Promise<Result | Result[]>;
|
|
43
|
+
_remove(id: null, params?: ServiceParams): Promise<Result[]>;
|
|
44
|
+
_remove(id: Id, params?: ServiceParams): Promise<Result>;
|
|
45
|
+
_remove(id: NullableId, _params?: ServiceParams): Promise<Result | Result[]>;
|
|
46
46
|
}
|
|
47
|
-
export declare class MemoryService<
|
|
48
|
-
find(params?:
|
|
47
|
+
export declare class MemoryService<Result = any, Data = Partial<Result>, ServiceParams extends AdapterParams = AdapterParams, PatchData = Partial<Data>> extends MemoryAdapter<Result, Data, ServiceParams, PatchData> {
|
|
48
|
+
find(params?: ServiceParams & {
|
|
49
49
|
paginate?: PaginationOptions;
|
|
50
|
-
}): Promise<Paginated<
|
|
51
|
-
find(params?:
|
|
50
|
+
}): Promise<Paginated<Result>>;
|
|
51
|
+
find(params?: ServiceParams & {
|
|
52
52
|
paginate: false;
|
|
53
|
-
}): Promise<
|
|
54
|
-
find(params?:
|
|
55
|
-
get(id: Id, params?:
|
|
56
|
-
create(data:
|
|
57
|
-
create(data:
|
|
58
|
-
update(id: Id, data:
|
|
59
|
-
patch(id: Id, data:
|
|
60
|
-
patch(id: null, data:
|
|
61
|
-
remove(id: Id, params?:
|
|
62
|
-
remove(id: null, params?:
|
|
53
|
+
}): Promise<Result[]>;
|
|
54
|
+
find(params?: ServiceParams): Promise<Paginated<Result> | Result[]>;
|
|
55
|
+
get(id: Id, params?: ServiceParams): Promise<Result>;
|
|
56
|
+
create(data: Data, params?: ServiceParams): Promise<Result>;
|
|
57
|
+
create(data: Data[], params?: ServiceParams): Promise<Result[]>;
|
|
58
|
+
update(id: Id, data: Data, params?: ServiceParams): Promise<Result>;
|
|
59
|
+
patch(id: Id, data: PatchData, params?: ServiceParams): Promise<Result>;
|
|
60
|
+
patch(id: null, data: PatchData, params?: ServiceParams): Promise<Result[]>;
|
|
61
|
+
remove(id: Id, params?: ServiceParams): Promise<Result>;
|
|
62
|
+
remove(id: null, params?: ServiceParams): Promise<Result[]>;
|
|
63
63
|
}
|
|
64
|
-
export declare function memory<T = any, D = Partial<T>, P extends Params = Params>(options?: Partial<MemoryServiceOptions<T>>): MemoryService<T, D, P
|
|
64
|
+
export declare function memory<T = any, D = Partial<T>, P extends Params = Params>(options?: Partial<MemoryServiceOptions<T>>): MemoryService<T, D, P, Partial<D>>;
|
package/lib/index.js
CHANGED
|
@@ -27,7 +27,7 @@ class MemoryAdapter extends adapter_commons_1.AdapterBase {
|
|
|
27
27
|
}
|
|
28
28
|
async getEntries(_params) {
|
|
29
29
|
const params = _params || {};
|
|
30
|
-
return this
|
|
30
|
+
return this._find({
|
|
31
31
|
...params,
|
|
32
32
|
paginate: false
|
|
33
33
|
});
|
|
@@ -39,7 +39,7 @@ class MemoryAdapter extends adapter_commons_1.AdapterBase {
|
|
|
39
39
|
filters: { $skip, $sort, $limit, $select }
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
async
|
|
42
|
+
async _find(params = {}) {
|
|
43
43
|
const { paginate } = this.getOptions(params);
|
|
44
44
|
const { query, filters } = this.getQuery(params);
|
|
45
45
|
let values = commons_1._.values(this.store);
|
|
@@ -82,7 +82,7 @@ class MemoryAdapter extends adapter_commons_1.AdapterBase {
|
|
|
82
82
|
}
|
|
83
83
|
return result;
|
|
84
84
|
}
|
|
85
|
-
async
|
|
85
|
+
async _get(id, params = {}) {
|
|
86
86
|
const { query } = this.getQuery(params);
|
|
87
87
|
if (id in this.store) {
|
|
88
88
|
const value = this.store[id];
|
|
@@ -92,25 +92,31 @@ class MemoryAdapter extends adapter_commons_1.AdapterBase {
|
|
|
92
92
|
}
|
|
93
93
|
throw new errors_1.NotFound(`No record found for id '${id}'`);
|
|
94
94
|
}
|
|
95
|
-
async
|
|
95
|
+
async _create(data, params = {}) {
|
|
96
96
|
if (Array.isArray(data)) {
|
|
97
|
-
return Promise.all(data.map((current) => this
|
|
97
|
+
return Promise.all(data.map((current) => this._create(current, params)));
|
|
98
98
|
}
|
|
99
99
|
const id = data[this.id] || this._uId++;
|
|
100
100
|
const current = commons_1._.extend({}, data, { [this.id]: id });
|
|
101
101
|
const result = (this.store[id] = current);
|
|
102
102
|
return _select(result, params, this.id);
|
|
103
103
|
}
|
|
104
|
-
async
|
|
105
|
-
|
|
104
|
+
async _update(id, data, params = {}) {
|
|
105
|
+
if (id === null || Array.isArray(data)) {
|
|
106
|
+
throw new errors_1.BadRequest("You can not replace multiple instances. Did you mean 'patch'?");
|
|
107
|
+
}
|
|
108
|
+
const oldEntry = await this._get(id);
|
|
106
109
|
// We don't want our id to change type if it can be coerced
|
|
107
110
|
const oldId = oldEntry[this.id];
|
|
108
111
|
// eslint-disable-next-line eqeqeq
|
|
109
112
|
id = oldId == id ? oldId : id;
|
|
110
113
|
this.store[id] = commons_1._.extend({}, data, { [this.id]: id });
|
|
111
|
-
return this
|
|
114
|
+
return this._get(id, params);
|
|
112
115
|
}
|
|
113
|
-
async
|
|
116
|
+
async _patch(id, data, params = {}) {
|
|
117
|
+
if (id === null && !this.allowsMulti('patch', params)) {
|
|
118
|
+
throw new errors_1.MethodNotAllowed('Can not patch multiple entries');
|
|
119
|
+
}
|
|
114
120
|
const { query } = this.getQuery(params);
|
|
115
121
|
const patchEntry = (entry) => {
|
|
116
122
|
const currentId = entry[this.id];
|
|
@@ -124,18 +130,21 @@ class MemoryAdapter extends adapter_commons_1.AdapterBase {
|
|
|
124
130
|
});
|
|
125
131
|
return entries.map(patchEntry);
|
|
126
132
|
}
|
|
127
|
-
return patchEntry(await this
|
|
133
|
+
return patchEntry(await this._get(id, params)); // Will throw an error if not found
|
|
128
134
|
}
|
|
129
|
-
async
|
|
135
|
+
async _remove(id, params = {}) {
|
|
136
|
+
if (id === null && !this.allowsMulti('remove', params)) {
|
|
137
|
+
throw new errors_1.MethodNotAllowed('Can not remove multiple entries');
|
|
138
|
+
}
|
|
130
139
|
const { query } = this.getQuery(params);
|
|
131
140
|
if (id === null) {
|
|
132
141
|
const entries = await this.getEntries({
|
|
133
142
|
...params,
|
|
134
143
|
query
|
|
135
144
|
});
|
|
136
|
-
return Promise.all(entries.map((current) => this
|
|
145
|
+
return Promise.all(entries.map((current) => this._remove(current[this.id], params)));
|
|
137
146
|
}
|
|
138
|
-
const entry = await this
|
|
147
|
+
const entry = await this._get(id, params);
|
|
139
148
|
delete this.store[id];
|
|
140
149
|
return entry;
|
|
141
150
|
}
|
|
@@ -143,22 +152,42 @@ class MemoryAdapter extends adapter_commons_1.AdapterBase {
|
|
|
143
152
|
exports.MemoryAdapter = MemoryAdapter;
|
|
144
153
|
class MemoryService extends MemoryAdapter {
|
|
145
154
|
async find(params) {
|
|
146
|
-
return this._find(
|
|
155
|
+
return this._find({
|
|
156
|
+
...params,
|
|
157
|
+
query: await this.sanitizeQuery(params)
|
|
158
|
+
});
|
|
147
159
|
}
|
|
148
160
|
async get(id, params) {
|
|
149
|
-
return this._get(id,
|
|
161
|
+
return this._get(id, {
|
|
162
|
+
...params,
|
|
163
|
+
query: await this.sanitizeQuery(params)
|
|
164
|
+
});
|
|
150
165
|
}
|
|
151
166
|
async create(data, params) {
|
|
167
|
+
if (Array.isArray(data) && !this.allowsMulti('create', params)) {
|
|
168
|
+
throw new errors_1.MethodNotAllowed('Can not create multiple entries');
|
|
169
|
+
}
|
|
152
170
|
return this._create(data, params);
|
|
153
171
|
}
|
|
154
172
|
async update(id, data, params) {
|
|
155
|
-
return this._update(id, data,
|
|
173
|
+
return this._update(id, data, {
|
|
174
|
+
...params,
|
|
175
|
+
query: await this.sanitizeQuery(params)
|
|
176
|
+
});
|
|
156
177
|
}
|
|
157
178
|
async patch(id, data, params) {
|
|
158
|
-
|
|
179
|
+
const { $limit, ...query } = await this.sanitizeQuery(params);
|
|
180
|
+
return this._patch(id, data, {
|
|
181
|
+
...params,
|
|
182
|
+
query
|
|
183
|
+
});
|
|
159
184
|
}
|
|
160
185
|
async remove(id, params) {
|
|
161
|
-
|
|
186
|
+
const { $limit, ...query } = await this.sanitizeQuery(params);
|
|
187
|
+
return this._remove(id, {
|
|
188
|
+
...params,
|
|
189
|
+
query
|
|
190
|
+
});
|
|
162
191
|
}
|
|
163
192
|
}
|
|
164
193
|
exports.MemoryService = MemoryService;
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,+CAA2E;AAC3E,iDAAuC;AACvC,iEAOoC;AACpC,gDAAuB;AAcvB,MAAM,OAAO,GAAG,CAAC,IAAS,EAAE,MAAW,EAAE,GAAG,IAAW,EAAE,EAAE;IACzD,MAAM,IAAI,GAAG,IAAA,wBAAM,EAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;IAEpC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAC/C,CAAC,CAAA;AAED,MAAa,aAKX,SAAQ,6BAAiF;IAIzF,YAAY,UAAwC,EAAE;QACpD,KAAK,CAAC;YACJ,EAAE,EAAE,IAAI;YACR,OAA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xC,CAAC,CAAA;IACJ,CAAC;IAID,KAAK,CAAC,KAAK,CAAC,EAAc,EAAE,IAAe,EAAE,MAAsB;QACjE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAE7D,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE;YAC3B,GAAG,MAAM;YACT,KAAK;SACN,CAAC,CAAA;IACJ,CAAC;IAID,KAAK,CAAC,MAAM,CAAC,EAAc,EAAE,MAAsB;QACjD,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAE7D,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE;YACtB,GAAG,MAAM;YACT,KAAK;SACN,CAAC,CAAA;IACJ,CAAC;CACF;AA7DD,sCA6DC;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.
|
|
4
|
+
"version": "5.0.0-pre.35",
|
|
5
5
|
"homepage": "https://github.com/feathersjs/feathers",
|
|
6
6
|
"main": "lib/",
|
|
7
7
|
"types": "lib/",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
],
|
|
39
39
|
"scripts": {
|
|
40
40
|
"prepublish": "npm run compile",
|
|
41
|
-
"pack": "npm pack --pack-destination ../
|
|
41
|
+
"pack": "npm pack --pack-destination ../generators/test/build",
|
|
42
42
|
"compile": "shx rm -rf lib/ && tsc && npm run pack",
|
|
43
43
|
"test": "mocha --config ../../.mocharc.json --recursive test/**/*.test.ts"
|
|
44
44
|
},
|
|
@@ -49,20 +49,20 @@
|
|
|
49
49
|
"lib": "lib"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@feathersjs/adapter-commons": "^5.0.0-pre.
|
|
53
|
-
"@feathersjs/commons": "^5.0.0-pre.
|
|
54
|
-
"@feathersjs/errors": "^5.0.0-pre.
|
|
52
|
+
"@feathersjs/adapter-commons": "^5.0.0-pre.35",
|
|
53
|
+
"@feathersjs/commons": "^5.0.0-pre.35",
|
|
54
|
+
"@feathersjs/errors": "^5.0.0-pre.35",
|
|
55
55
|
"sift": "^16.0.1"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@feathersjs/adapter-tests": "^5.0.0-pre.
|
|
59
|
-
"@feathersjs/feathers": "^5.0.0-pre.
|
|
60
|
-
"@types/mocha": "^10.0.
|
|
61
|
-
"@types/node": "^18.11.
|
|
62
|
-
"mocha": "^10.
|
|
58
|
+
"@feathersjs/adapter-tests": "^5.0.0-pre.35",
|
|
59
|
+
"@feathersjs/feathers": "^5.0.0-pre.35",
|
|
60
|
+
"@types/mocha": "^10.0.1",
|
|
61
|
+
"@types/node": "^18.11.18",
|
|
62
|
+
"mocha": "^10.2.0",
|
|
63
63
|
"shx": "^0.3.4",
|
|
64
64
|
"ts-node": "^10.9.1",
|
|
65
|
-
"typescript": "^4.
|
|
65
|
+
"typescript": "^4.9.4"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "c641598d9a4de3ceda10f56cf2af288a4236b15e"
|
|
68
68
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NotFound } from '@feathersjs/errors'
|
|
1
|
+
import { BadRequest, MethodNotAllowed, NotFound } from '@feathersjs/errors'
|
|
2
2
|
import { _ } from '@feathersjs/commons'
|
|
3
3
|
import {
|
|
4
4
|
sorter,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
AdapterParams
|
|
10
10
|
} from '@feathersjs/adapter-commons'
|
|
11
11
|
import sift from 'sift'
|
|
12
|
-
import { NullableId, Id, Params,
|
|
12
|
+
import { NullableId, Id, Params, Paginated } from '@feathersjs/feathers'
|
|
13
13
|
|
|
14
14
|
export interface MemoryServiceStore<T> {
|
|
15
15
|
[key: string]: T
|
|
@@ -28,16 +28,16 @@ const _select = (data: any, params: any, ...args: any[]) => {
|
|
|
28
28
|
return base(JSON.parse(JSON.stringify(data)))
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export class MemoryAdapter<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
> {
|
|
37
|
-
store: MemoryServiceStore<
|
|
31
|
+
export class MemoryAdapter<
|
|
32
|
+
Result = any,
|
|
33
|
+
Data = Partial<Result>,
|
|
34
|
+
ServiceParams extends Params = Params,
|
|
35
|
+
PatchData = Partial<Data>
|
|
36
|
+
> extends AdapterBase<Result, Data, PatchData, ServiceParams, MemoryServiceOptions<Result>> {
|
|
37
|
+
store: MemoryServiceStore<Result>
|
|
38
38
|
_uId: number
|
|
39
39
|
|
|
40
|
-
constructor(options: MemoryServiceOptions<
|
|
40
|
+
constructor(options: MemoryServiceOptions<Result> = {}) {
|
|
41
41
|
super({
|
|
42
42
|
id: 'id',
|
|
43
43
|
matcher: sift,
|
|
@@ -50,16 +50,16 @@ export class MemoryAdapter<T = any, D = Partial<T>, P extends Params = Params> e
|
|
|
50
50
|
this.store = { ...this.options.store }
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
async getEntries(_params?:
|
|
54
|
-
const params = _params || ({} as
|
|
53
|
+
async getEntries(_params?: ServiceParams) {
|
|
54
|
+
const params = _params || ({} as ServiceParams)
|
|
55
55
|
|
|
56
|
-
return this
|
|
56
|
+
return this._find({
|
|
57
57
|
...params,
|
|
58
58
|
paginate: false
|
|
59
59
|
})
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
getQuery(params:
|
|
62
|
+
getQuery(params: ServiceParams) {
|
|
63
63
|
const { $skip, $sort, $limit, $select, ...query } = params.query || {}
|
|
64
64
|
|
|
65
65
|
return {
|
|
@@ -68,10 +68,10 @@ export class MemoryAdapter<T = any, D = Partial<T>, P extends Params = Params> e
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
async
|
|
72
|
-
async
|
|
73
|
-
async
|
|
74
|
-
async
|
|
71
|
+
async _find(_params?: ServiceParams & { paginate?: PaginationOptions }): Promise<Paginated<Result>>
|
|
72
|
+
async _find(_params?: ServiceParams & { paginate: false }): Promise<Result[]>
|
|
73
|
+
async _find(_params?: ServiceParams): Promise<Paginated<Result> | Result[]>
|
|
74
|
+
async _find(params: ServiceParams = {} as ServiceParams): Promise<Paginated<Result> | Result[]> {
|
|
75
75
|
const { paginate } = this.getOptions(params)
|
|
76
76
|
const { query, filters } = this.getQuery(params)
|
|
77
77
|
|
|
@@ -113,7 +113,7 @@ export class MemoryAdapter<T = any, D = Partial<T>, P extends Params = Params> e
|
|
|
113
113
|
values = matched
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
const result: Paginated<
|
|
116
|
+
const result: Paginated<Result> = {
|
|
117
117
|
total: hasQuery ? values.length : total,
|
|
118
118
|
limit: filters.$limit,
|
|
119
119
|
skip: filters.$skip || 0,
|
|
@@ -127,7 +127,7 @@ export class MemoryAdapter<T = any, D = Partial<T>, P extends Params = Params> e
|
|
|
127
127
|
return result
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
async
|
|
130
|
+
async _get(id: Id, params: ServiceParams = {} as ServiceParams): Promise<Result> {
|
|
131
131
|
const { query } = this.getQuery(params)
|
|
132
132
|
|
|
133
133
|
if (id in this.store) {
|
|
@@ -141,23 +141,30 @@ export class MemoryAdapter<T = any, D = Partial<T>, P extends Params = Params> e
|
|
|
141
141
|
throw new NotFound(`No record found for id '${id}'`)
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
async
|
|
145
|
-
async
|
|
146
|
-
async
|
|
147
|
-
async
|
|
144
|
+
async _create(data: Partial<Data>, params?: ServiceParams): Promise<Result>
|
|
145
|
+
async _create(data: Partial<Data>[], params?: ServiceParams): Promise<Result[]>
|
|
146
|
+
async _create(data: Partial<Data> | Partial<Data>[], _params?: ServiceParams): Promise<Result | Result[]>
|
|
147
|
+
async _create(
|
|
148
|
+
data: Partial<Data> | Partial<Data>[],
|
|
149
|
+
params: ServiceParams = {} as ServiceParams
|
|
150
|
+
): Promise<Result | Result[]> {
|
|
148
151
|
if (Array.isArray(data)) {
|
|
149
|
-
return Promise.all(data.map((current) => this
|
|
152
|
+
return Promise.all(data.map((current) => this._create(current, params)))
|
|
150
153
|
}
|
|
151
154
|
|
|
152
155
|
const id = (data as any)[this.id] || this._uId++
|
|
153
156
|
const current = _.extend({}, data, { [this.id]: id })
|
|
154
157
|
const result = (this.store[id] = current)
|
|
155
158
|
|
|
156
|
-
return _select(result, params, this.id) as
|
|
159
|
+
return _select(result, params, this.id) as Result
|
|
157
160
|
}
|
|
158
161
|
|
|
159
|
-
async
|
|
160
|
-
|
|
162
|
+
async _update(id: Id, data: Data, params: ServiceParams = {} as ServiceParams): Promise<Result> {
|
|
163
|
+
if (id === null || Array.isArray(data)) {
|
|
164
|
+
throw new BadRequest("You can not replace multiple instances. Did you mean 'patch'?")
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const oldEntry = await this._get(id)
|
|
161
168
|
// We don't want our id to change type if it can be coerced
|
|
162
169
|
const oldId = (oldEntry as any)[this.id]
|
|
163
170
|
|
|
@@ -166,15 +173,23 @@ export class MemoryAdapter<T = any, D = Partial<T>, P extends Params = Params> e
|
|
|
166
173
|
|
|
167
174
|
this.store[id] = _.extend({}, data, { [this.id]: id })
|
|
168
175
|
|
|
169
|
-
return this
|
|
176
|
+
return this._get(id, params)
|
|
170
177
|
}
|
|
171
178
|
|
|
172
|
-
async
|
|
173
|
-
async
|
|
174
|
-
async
|
|
175
|
-
async
|
|
179
|
+
async _patch(id: null, data: PatchData, params?: ServiceParams): Promise<Result[]>
|
|
180
|
+
async _patch(id: Id, data: PatchData, params?: ServiceParams): Promise<Result>
|
|
181
|
+
async _patch(id: NullableId, data: PatchData, _params?: ServiceParams): Promise<Result | Result[]>
|
|
182
|
+
async _patch(
|
|
183
|
+
id: NullableId,
|
|
184
|
+
data: PatchData,
|
|
185
|
+
params: ServiceParams = {} as ServiceParams
|
|
186
|
+
): Promise<Result | Result[]> {
|
|
187
|
+
if (id === null && !this.allowsMulti('patch', params)) {
|
|
188
|
+
throw new MethodNotAllowed('Can not patch multiple entries')
|
|
189
|
+
}
|
|
190
|
+
|
|
176
191
|
const { query } = this.getQuery(params)
|
|
177
|
-
const patchEntry = (entry:
|
|
192
|
+
const patchEntry = (entry: Result) => {
|
|
178
193
|
const currentId = (entry as any)[this.id]
|
|
179
194
|
|
|
180
195
|
this.store[currentId] = _.extend(this.store[currentId], _.omit(data, this.id))
|
|
@@ -191,13 +206,17 @@ export class MemoryAdapter<T = any, D = Partial<T>, P extends Params = Params> e
|
|
|
191
206
|
return entries.map(patchEntry)
|
|
192
207
|
}
|
|
193
208
|
|
|
194
|
-
return patchEntry(await this
|
|
209
|
+
return patchEntry(await this._get(id, params)) // Will throw an error if not found
|
|
195
210
|
}
|
|
196
211
|
|
|
197
|
-
async
|
|
198
|
-
async
|
|
199
|
-
async
|
|
200
|
-
async
|
|
212
|
+
async _remove(id: null, params?: ServiceParams): Promise<Result[]>
|
|
213
|
+
async _remove(id: Id, params?: ServiceParams): Promise<Result>
|
|
214
|
+
async _remove(id: NullableId, _params?: ServiceParams): Promise<Result | Result[]>
|
|
215
|
+
async _remove(id: NullableId, params: ServiceParams = {} as ServiceParams): Promise<Result | Result[]> {
|
|
216
|
+
if (id === null && !this.allowsMulti('remove', params)) {
|
|
217
|
+
throw new MethodNotAllowed('Can not remove multiple entries')
|
|
218
|
+
}
|
|
219
|
+
|
|
201
220
|
const { query } = this.getQuery(params)
|
|
202
221
|
|
|
203
222
|
if (id === null) {
|
|
@@ -206,10 +225,10 @@ export class MemoryAdapter<T = any, D = Partial<T>, P extends Params = Params> e
|
|
|
206
225
|
query
|
|
207
226
|
})
|
|
208
227
|
|
|
209
|
-
return Promise.all(entries.map((current: any) => this
|
|
228
|
+
return Promise.all(entries.map((current: any) => this._remove(current[this.id] as Id, params)))
|
|
210
229
|
}
|
|
211
230
|
|
|
212
|
-
const entry = await this
|
|
231
|
+
const entry = await this._get(id, params)
|
|
213
232
|
|
|
214
233
|
delete this.store[id]
|
|
215
234
|
|
|
@@ -217,41 +236,66 @@ export class MemoryAdapter<T = any, D = Partial<T>, P extends Params = Params> e
|
|
|
217
236
|
}
|
|
218
237
|
}
|
|
219
238
|
|
|
220
|
-
export class MemoryService<
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
async find(params?:
|
|
227
|
-
async find(params?:
|
|
228
|
-
|
|
239
|
+
export class MemoryService<
|
|
240
|
+
Result = any,
|
|
241
|
+
Data = Partial<Result>,
|
|
242
|
+
ServiceParams extends AdapterParams = AdapterParams,
|
|
243
|
+
PatchData = Partial<Data>
|
|
244
|
+
> extends MemoryAdapter<Result, Data, ServiceParams, PatchData> {
|
|
245
|
+
async find(params?: ServiceParams & { paginate?: PaginationOptions }): Promise<Paginated<Result>>
|
|
246
|
+
async find(params?: ServiceParams & { paginate: false }): Promise<Result[]>
|
|
247
|
+
async find(params?: ServiceParams): Promise<Paginated<Result> | Result[]>
|
|
248
|
+
async find(params?: ServiceParams): Promise<Paginated<Result> | Result[]> {
|
|
249
|
+
return this._find({
|
|
250
|
+
...params,
|
|
251
|
+
query: await this.sanitizeQuery(params)
|
|
252
|
+
})
|
|
229
253
|
}
|
|
230
254
|
|
|
231
|
-
async get(id: Id, params?:
|
|
232
|
-
return this._get(id,
|
|
255
|
+
async get(id: Id, params?: ServiceParams): Promise<Result> {
|
|
256
|
+
return this._get(id, {
|
|
257
|
+
...params,
|
|
258
|
+
query: await this.sanitizeQuery(params)
|
|
259
|
+
})
|
|
233
260
|
}
|
|
234
261
|
|
|
235
|
-
async create(data:
|
|
236
|
-
async create(data:
|
|
237
|
-
async create(data:
|
|
262
|
+
async create(data: Data, params?: ServiceParams): Promise<Result>
|
|
263
|
+
async create(data: Data[], params?: ServiceParams): Promise<Result[]>
|
|
264
|
+
async create(data: Data | Data[], params?: ServiceParams): Promise<Result | Result[]> {
|
|
265
|
+
if (Array.isArray(data) && !this.allowsMulti('create', params)) {
|
|
266
|
+
throw new MethodNotAllowed('Can not create multiple entries')
|
|
267
|
+
}
|
|
268
|
+
|
|
238
269
|
return this._create(data, params)
|
|
239
270
|
}
|
|
240
271
|
|
|
241
|
-
async update(id: Id, data:
|
|
242
|
-
return this._update(id, data,
|
|
272
|
+
async update(id: Id, data: Data, params?: ServiceParams): Promise<Result> {
|
|
273
|
+
return this._update(id, data, {
|
|
274
|
+
...params,
|
|
275
|
+
query: await this.sanitizeQuery(params)
|
|
276
|
+
})
|
|
243
277
|
}
|
|
244
278
|
|
|
245
|
-
async patch(id: Id, data:
|
|
246
|
-
async patch(id: null, data:
|
|
247
|
-
async patch(id: NullableId, data:
|
|
248
|
-
|
|
279
|
+
async patch(id: Id, data: PatchData, params?: ServiceParams): Promise<Result>
|
|
280
|
+
async patch(id: null, data: PatchData, params?: ServiceParams): Promise<Result[]>
|
|
281
|
+
async patch(id: NullableId, data: PatchData, params?: ServiceParams): Promise<Result | Result[]> {
|
|
282
|
+
const { $limit, ...query } = await this.sanitizeQuery(params)
|
|
283
|
+
|
|
284
|
+
return this._patch(id, data, {
|
|
285
|
+
...params,
|
|
286
|
+
query
|
|
287
|
+
})
|
|
249
288
|
}
|
|
250
289
|
|
|
251
|
-
async remove(id: Id, params?:
|
|
252
|
-
async remove(id: null, params?:
|
|
253
|
-
async remove(id: NullableId, params?:
|
|
254
|
-
|
|
290
|
+
async remove(id: Id, params?: ServiceParams): Promise<Result>
|
|
291
|
+
async remove(id: null, params?: ServiceParams): Promise<Result[]>
|
|
292
|
+
async remove(id: NullableId, params?: ServiceParams): Promise<Result | Result[]> {
|
|
293
|
+
const { $limit, ...query } = await this.sanitizeQuery(params)
|
|
294
|
+
|
|
295
|
+
return this._remove(id, {
|
|
296
|
+
...params,
|
|
297
|
+
query
|
|
298
|
+
})
|
|
255
299
|
}
|
|
256
300
|
}
|
|
257
301
|
|