@loopback/rest-crud 0.14.0 → 0.15.0
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/LICENSE +1 -1
- package/README.md +2 -1
- package/dist/crud-rest.api-builder.d.ts +4 -0
- package/dist/crud-rest.api-builder.js +1 -1
- package/dist/crud-rest.api-builder.js.map +1 -1
- package/dist/crud-rest.component.js +1 -1
- package/dist/crud-rest.component.js.map +1 -1
- package/dist/crud-rest.controller.d.ts +8 -4
- package/dist/crud-rest.controller.js +51 -41
- package/dist/crud-rest.controller.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
- package/src/crud-rest.api-builder.ts +5 -1
- package/src/crud-rest.component.ts +1 -1
- package/src/crud-rest.controller.ts +39 -24
- package/src/index.ts +1 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ export class TryApplication extends BootMixin(
|
|
|
43
43
|
|
|
44
44
|
Create a new file for the configuration, e.g.
|
|
45
45
|
`src/model-endpoints/product.rest-config.ts` that defines the `model`,
|
|
46
|
-
`pattern`, `dataSource`, and `
|
|
46
|
+
`pattern`, `dataSource`, `basePath`, and `readonly` properties:
|
|
47
47
|
|
|
48
48
|
```ts
|
|
49
49
|
import {ModelCrudRestApiConfig} from '@loopback/rest-crud';
|
|
@@ -54,6 +54,7 @@ module.exports = <ModelCrudRestApiConfig>{
|
|
|
54
54
|
pattern: 'CrudRest', // make sure to use this pattern
|
|
55
55
|
dataSource: 'db',
|
|
56
56
|
basePath: '/products',
|
|
57
|
+
readonly: false,
|
|
57
58
|
};
|
|
58
59
|
```
|
|
59
60
|
|
|
@@ -3,6 +3,10 @@ import { ApplicationWithRepositories } from '@loopback/repository';
|
|
|
3
3
|
import { Model } from '@loopback/rest';
|
|
4
4
|
export interface ModelCrudRestApiConfig extends ModelApiConfig {
|
|
5
5
|
basePath: string;
|
|
6
|
+
/**
|
|
7
|
+
* If true, the generated controller only has find and count APIs
|
|
8
|
+
*/
|
|
9
|
+
readonly?: boolean;
|
|
6
10
|
}
|
|
7
11
|
export declare class CrudRestApiBuilder implements ModelApiBuilder {
|
|
8
12
|
readonly pattern: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2020. All Rights Reserved.
|
|
2
|
+
// Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
|
|
3
3
|
// Node module: @loopback/rest-crud
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud-rest.api-builder.js","sourceRoot":"","sources":["../src/crud-rest.api-builder.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"crud-rest.api-builder.js","sourceRoot":"","sources":["../src/crud-rest.api-builder.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAMwB;AACxB,mEAIqC;AACrC,qDAM8B;AAE9B,0DAAiC;AACjC,wBAA2C;AAE3C,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,yBAAyB,CAAC,CAAC;AAYtD,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAA/B;QACW,YAAO,GAAW,UAAU,CAAC;IAwCxC,CAAC;IAtCC,KAAK,CACH,WAAwC,EACxC,UAA6C,EAC7C,GAAmB;QAEnB,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC;QAClC,MAAM,MAAM,GAAG,GAA6B,CAAC;QAC7C,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YACpB,MAAM,IAAI,KAAK,CACb,gEAAgE,SAAS,GAAG,CAC7E,CAAC;SACH;QAED,IAAI,CAAC,CAAC,UAAU,CAAC,SAAS,YAAY,mBAAM,CAAC,EAAE;YAC7C,MAAM,IAAI,KAAK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,CAAC;IAEF,yBAAyB,CACvB,eAAe,EACf,gBAAgB,WAAW,CAAC,IAAI,YAAY,CAC7C,CAAC;IAEF,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,yBAAyB,CAChC,IAAoB,EACpB,GAAoB;IAEpB,IAAA,aAAM,EAAC,GAAG,CAAC,CACT,IAAI,EACJ,SAAS,EAAE,qBAAqB;IAChC,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
2
|
+
// Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
|
|
3
3
|
// Node module: @loopback/rest-crud
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud-rest.component.js","sourceRoot":"","sources":["../src/crud-rest.component.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"crud-rest.component.js","sourceRoot":"","sources":["../src/crud-rest.component.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,yCAA0E;AAC1E,mEAA2D;AAE3D,MAAa,iBAAiB;IAA9B;QACE,aAAQ,GAAc,CAAC,IAAA,6BAAsB,EAAC,0CAAkB,CAAC,CAAC,CAAC;IACrE,CAAC;CAAA;AAFD,8CAEC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Entity, EntityCrudRepository } from '@loopback/repository';
|
|
1
|
+
import { Entity, EntityCrudRepository, Filter } from '@loopback/repository';
|
|
2
2
|
/**
|
|
3
3
|
* This interface describes prototype members of the controller class
|
|
4
4
|
* returned by `defineCrudRestController`.
|
|
@@ -9,10 +9,10 @@ export interface CrudRestController<T extends Entity, IdType, IdName extends key
|
|
|
9
9
|
*/
|
|
10
10
|
readonly repository: EntityCrudRepository<T, IdType>;
|
|
11
11
|
/**
|
|
12
|
-
* Implementation of the endpoint `
|
|
13
|
-
* @param
|
|
12
|
+
* Implementation of the endpoint `GET /`.
|
|
13
|
+
* @param filter Filter
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
find(filter?: Filter<T>): Promise<(T & Relations)[]>;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Constructor of the controller class returned by `defineCrudRestController`.
|
|
@@ -28,6 +28,10 @@ export interface CrudRestControllerOptions {
|
|
|
28
28
|
* The base path where to "mount" the controller.
|
|
29
29
|
*/
|
|
30
30
|
basePath: string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to generate readonly APIs
|
|
33
|
+
*/
|
|
34
|
+
readonly?: boolean;
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
33
37
|
* Create (define) a CRUD Controller class for the given model.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
2
|
+
// Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
|
|
3
3
|
// Node module: @loopback/rest-crud
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
@@ -40,16 +40,10 @@ function defineCrudRestController(modelCtor, options) {
|
|
|
40
40
|
in: 'path',
|
|
41
41
|
schema: getIdSchema(modelCtor),
|
|
42
42
|
};
|
|
43
|
-
let
|
|
43
|
+
let ReadonlyRestControllerImpl = class ReadonlyRestControllerImpl {
|
|
44
44
|
constructor(repository) {
|
|
45
45
|
this.repository = repository;
|
|
46
46
|
}
|
|
47
|
-
async create(data) {
|
|
48
|
-
return this.repository.create(
|
|
49
|
-
// FIXME(bajtos) Improve repository API to support this use case
|
|
50
|
-
// with no explicit type-casts required
|
|
51
|
-
data);
|
|
52
|
-
}
|
|
53
47
|
async find(filter) {
|
|
54
48
|
return this.repository.find(filter);
|
|
55
49
|
}
|
|
@@ -59,6 +53,54 @@ function defineCrudRestController(modelCtor, options) {
|
|
|
59
53
|
async count(where) {
|
|
60
54
|
return this.repository.count(where);
|
|
61
55
|
}
|
|
56
|
+
};
|
|
57
|
+
tslib_1.__decorate([
|
|
58
|
+
(0, rest_1.get)('/', {
|
|
59
|
+
...response.array(200, `Array of ${modelName} instances`, modelCtor, {
|
|
60
|
+
includeRelations: true,
|
|
61
|
+
}),
|
|
62
|
+
}),
|
|
63
|
+
tslib_1.__param(0, rest_1.param.filter(modelCtor)),
|
|
64
|
+
tslib_1.__metadata("design:type", Function),
|
|
65
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
66
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
67
|
+
], ReadonlyRestControllerImpl.prototype, "find", null);
|
|
68
|
+
tslib_1.__decorate([
|
|
69
|
+
(0, rest_1.get)('/{id}', {
|
|
70
|
+
...response.model(200, `${modelName} instance`, modelCtor, {
|
|
71
|
+
includeRelations: true,
|
|
72
|
+
}),
|
|
73
|
+
}),
|
|
74
|
+
tslib_1.__param(0, (0, rest_1.param)(idPathParam)),
|
|
75
|
+
tslib_1.__param(1, rest_1.param.query.object('filter', (0, rest_1.getFilterSchemaFor)(modelCtor, { exclude: 'where' }))),
|
|
76
|
+
tslib_1.__metadata("design:type", Function),
|
|
77
|
+
tslib_1.__metadata("design:paramtypes", [Object, Object]),
|
|
78
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
79
|
+
], ReadonlyRestControllerImpl.prototype, "findById", null);
|
|
80
|
+
tslib_1.__decorate([
|
|
81
|
+
(0, rest_1.get)('/count', {
|
|
82
|
+
...response(200, `${modelName} count`, { schema: repository_1.CountSchema }),
|
|
83
|
+
}),
|
|
84
|
+
tslib_1.__param(0, rest_1.param.where(modelCtor)),
|
|
85
|
+
tslib_1.__metadata("design:type", Function),
|
|
86
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
87
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
88
|
+
], ReadonlyRestControllerImpl.prototype, "count", null);
|
|
89
|
+
ReadonlyRestControllerImpl = tslib_1.__decorate([
|
|
90
|
+
(0, rest_1.api)({ basePath: options.basePath, paths: {} }),
|
|
91
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
92
|
+
], ReadonlyRestControllerImpl);
|
|
93
|
+
let CrudRestControllerImpl = class CrudRestControllerImpl extends ReadonlyRestControllerImpl {
|
|
94
|
+
constructor(repository) {
|
|
95
|
+
super(repository);
|
|
96
|
+
this.repository = repository;
|
|
97
|
+
}
|
|
98
|
+
async create(data) {
|
|
99
|
+
return this.repository.create(
|
|
100
|
+
// FIXME(bajtos) Improve repository API to support this use case
|
|
101
|
+
// with no explicit type-casts required
|
|
102
|
+
data);
|
|
103
|
+
}
|
|
62
104
|
async updateAll(data, where) {
|
|
63
105
|
return this.repository.updateAll(
|
|
64
106
|
// FIXME(bajtos) Improve repository API to support this use case
|
|
@@ -90,38 +132,6 @@ function defineCrudRestController(modelCtor, options) {
|
|
|
90
132
|
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
91
133
|
tslib_1.__metadata("design:returntype", Promise)
|
|
92
134
|
], CrudRestControllerImpl.prototype, "create", null);
|
|
93
|
-
tslib_1.__decorate([
|
|
94
|
-
(0, rest_1.get)('/', {
|
|
95
|
-
...response.array(200, `Array of ${modelName} instances`, modelCtor, {
|
|
96
|
-
includeRelations: true,
|
|
97
|
-
}),
|
|
98
|
-
}),
|
|
99
|
-
tslib_1.__param(0, rest_1.param.filter(modelCtor)),
|
|
100
|
-
tslib_1.__metadata("design:type", Function),
|
|
101
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
102
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
103
|
-
], CrudRestControllerImpl.prototype, "find", null);
|
|
104
|
-
tslib_1.__decorate([
|
|
105
|
-
(0, rest_1.get)('/{id}', {
|
|
106
|
-
...response.model(200, `${modelName} instance`, modelCtor, {
|
|
107
|
-
includeRelations: true,
|
|
108
|
-
}),
|
|
109
|
-
}),
|
|
110
|
-
tslib_1.__param(0, (0, rest_1.param)(idPathParam)),
|
|
111
|
-
tslib_1.__param(1, rest_1.param.query.object('filter', (0, rest_1.getFilterSchemaFor)(modelCtor, { exclude: 'where' }))),
|
|
112
|
-
tslib_1.__metadata("design:type", Function),
|
|
113
|
-
tslib_1.__metadata("design:paramtypes", [Object, Object]),
|
|
114
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
115
|
-
], CrudRestControllerImpl.prototype, "findById", null);
|
|
116
|
-
tslib_1.__decorate([
|
|
117
|
-
(0, rest_1.get)('/count', {
|
|
118
|
-
...response(200, `${modelName} count`, { schema: repository_1.CountSchema }),
|
|
119
|
-
}),
|
|
120
|
-
tslib_1.__param(0, rest_1.param.where(modelCtor)),
|
|
121
|
-
tslib_1.__metadata("design:type", Function),
|
|
122
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
123
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
124
|
-
], CrudRestControllerImpl.prototype, "count", null);
|
|
125
135
|
tslib_1.__decorate([
|
|
126
136
|
(0, rest_1.patch)('/', {
|
|
127
137
|
...response(200, `Count of ${modelName} models updated`, {
|
|
@@ -175,7 +185,7 @@ function defineCrudRestController(modelCtor, options) {
|
|
|
175
185
|
], CrudRestControllerImpl);
|
|
176
186
|
const controllerName = modelName + 'Controller';
|
|
177
187
|
const defineNamedController = new Function('controllerClass', `return class ${controllerName} extends controllerClass {}`);
|
|
178
|
-
const controller = defineNamedController(CrudRestControllerImpl);
|
|
188
|
+
const controller = defineNamedController(options.readonly ? ReadonlyRestControllerImpl : CrudRestControllerImpl);
|
|
179
189
|
assert_1.default.equal(controller.name, controllerName);
|
|
180
190
|
return controller;
|
|
181
191
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud-rest.controller.js","sourceRoot":"","sources":["../src/crud-rest.controller.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"crud-rest.controller.js","sourceRoot":"","sources":["../src/crud-rest.controller.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,qDAS8B;AAC9B,yCAkBwB;AACxB,4DAA4B;AA2E5B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,wBAAwB,CAMtC,SAAqE,EACrE,OAAkC;IAElC,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC;IACjC,MAAM,WAAW,GAAoB;QACnC,IAAI,EAAE,IAAI;QACV,EAAE,EAAE,MAAM;QACV,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC;KAC/B,CAAC;IAGF,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;QAG9B,YACkB,UAAsD;YAAtD,eAAU,GAAV,UAAU,CAA4C;QACrE,CAAC;QAOJ,KAAK,CAAC,IAAI,CAER,MAAkB;YAElB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC;QAOD,KAAK,CAAC,QAAQ,CACQ,EAAU,EAK9B,MAAgC;YAEhC,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAC9C,CAAC;QAKD,KAAK,CAAC,KAAK,CAET,KAAgB;YAEhB,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;KACF,CAAA;IAhCC;QALC,IAAA,UAAG,EAAC,GAAG,EAAE;YACR,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,YAAY,SAAS,YAAY,EAAE,SAAS,EAAE;gBACnE,gBAAgB,EAAE,IAAI;aACvB,CAAC;SACH,CAAC;QAEC,mBAAA,YAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;;;;0DAIzB;IAOD;QAL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
1
|
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
2
|
+
// Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
|
|
3
3
|
// Node module: @loopback/rest-crud
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
package/dist/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,gFAAgF;AAChF,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE;;;;;;;;GAQG;AAEH,mEAAmE;AACnE,mDAA+D;AAAvD,uHAAA,yBAAyB,OAAA;AACjC,kEAAwC;AACxC,gEAAsC;AACtC,iEAAuC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopback/rest-crud",
|
|
3
3
|
"description": "REST API controller implementing default CRUD semantics",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.15.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
-
"author": "IBM Corp.",
|
|
9
|
-
"copyright.owner": "IBM Corp.",
|
|
8
|
+
"author": "IBM Corp. and LoopBack contributors",
|
|
9
|
+
"copyright.owner": "IBM Corp. and LoopBack contributors",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/loopbackio/loopback-next.git",
|
|
@@ -32,23 +32,23 @@
|
|
|
32
32
|
"!*/__tests__"
|
|
33
33
|
],
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@loopback/core": "^4.0.
|
|
36
|
-
"@loopback/repository": "^5.0.
|
|
37
|
-
"@loopback/rest": "^12.0.
|
|
35
|
+
"@loopback/core": "^4.0.1",
|
|
36
|
+
"@loopback/repository": "^5.0.1",
|
|
37
|
+
"@loopback/rest": "^12.0.1"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@loopback/model-api-builder": "^4.0.
|
|
40
|
+
"@loopback/model-api-builder": "^4.0.1",
|
|
41
41
|
"debug": "^4.3.4",
|
|
42
42
|
"tslib": "^2.4.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@loopback/build": "^9.0.
|
|
46
|
-
"@loopback/core": "^4.0.
|
|
47
|
-
"@loopback/repository": "^5.0.
|
|
48
|
-
"@loopback/rest": "^12.0.
|
|
49
|
-
"@loopback/testlab": "^5.0.
|
|
45
|
+
"@loopback/build": "^9.0.1",
|
|
46
|
+
"@loopback/core": "^4.0.1",
|
|
47
|
+
"@loopback/repository": "^5.0.1",
|
|
48
|
+
"@loopback/rest": "^12.0.1",
|
|
49
|
+
"@loopback/testlab": "^5.0.1",
|
|
50
50
|
"@types/debug": "^4.1.7",
|
|
51
|
-
"@types/node": "^
|
|
51
|
+
"@types/node": "^14.18.21"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "ccf7863d0639de966d6c6129b4aa94ba1dce2c33"
|
|
54
54
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright IBM Corp. 2020. All Rights Reserved.
|
|
1
|
+
// Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
|
|
2
2
|
// Node module: @loopback/rest-crud
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
@@ -31,6 +31,10 @@ const debug = debugFactory('loopback:boot:crud-rest');
|
|
|
31
31
|
export interface ModelCrudRestApiConfig extends ModelApiConfig {
|
|
32
32
|
// E.g. '/products'
|
|
33
33
|
basePath: string;
|
|
34
|
+
/**
|
|
35
|
+
* If true, the generated controller only has find and count APIs
|
|
36
|
+
*/
|
|
37
|
+
readonly?: boolean;
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
@injectable(asModelApiBuilder)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
1
|
+
// Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
|
|
2
2
|
// Node module: @loopback/rest-crud
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
1
|
+
// Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
|
|
2
2
|
// Node module: @loopback/rest-crud
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
@@ -63,8 +63,8 @@ import assert from 'assert';
|
|
|
63
63
|
export interface CrudRestController<
|
|
64
64
|
T extends Entity,
|
|
65
65
|
IdType,
|
|
66
|
-
IdName extends keyof T,
|
|
67
66
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
67
|
+
IdName extends keyof T,
|
|
68
68
|
Relations extends object = {},
|
|
69
69
|
> {
|
|
70
70
|
/**
|
|
@@ -73,10 +73,10 @@ export interface CrudRestController<
|
|
|
73
73
|
readonly repository: EntityCrudRepository<T, IdType>;
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* Implementation of the endpoint `
|
|
77
|
-
* @param
|
|
76
|
+
* Implementation of the endpoint `GET /`.
|
|
77
|
+
* @param filter Filter
|
|
78
78
|
*/
|
|
79
|
-
|
|
79
|
+
find(filter?: Filter<T>): Promise<(T & Relations)[]>;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
@@ -101,6 +101,10 @@ export interface CrudRestControllerOptions {
|
|
|
101
101
|
* The base path where to "mount" the controller.
|
|
102
102
|
*/
|
|
103
103
|
basePath: string;
|
|
104
|
+
/**
|
|
105
|
+
* Whether to generate readonly APIs
|
|
106
|
+
*/
|
|
107
|
+
readonly?: boolean;
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
/**
|
|
@@ -144,30 +148,13 @@ export function defineCrudRestController<
|
|
|
144
148
|
};
|
|
145
149
|
|
|
146
150
|
@api({basePath: options.basePath, paths: {}})
|
|
147
|
-
class
|
|
151
|
+
class ReadonlyRestControllerImpl
|
|
148
152
|
implements CrudRestController<T, IdType, IdName>
|
|
149
153
|
{
|
|
150
154
|
constructor(
|
|
151
155
|
public readonly repository: EntityCrudRepository<T, IdType, Relations>,
|
|
152
156
|
) {}
|
|
153
157
|
|
|
154
|
-
@post('/', {
|
|
155
|
-
...response.model(200, `${modelName} instance created`, modelCtor),
|
|
156
|
-
})
|
|
157
|
-
async create(
|
|
158
|
-
@body(modelCtor, {
|
|
159
|
-
title: `New${modelName}`,
|
|
160
|
-
exclude: modelCtor.getIdProperties() as (keyof T)[],
|
|
161
|
-
})
|
|
162
|
-
data: Omit<T, IdName>,
|
|
163
|
-
): Promise<T> {
|
|
164
|
-
return this.repository.create(
|
|
165
|
-
// FIXME(bajtos) Improve repository API to support this use case
|
|
166
|
-
// with no explicit type-casts required
|
|
167
|
-
data as DataObject<T>,
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
158
|
@get('/', {
|
|
172
159
|
...response.array(200, `Array of ${modelName} instances`, modelCtor, {
|
|
173
160
|
includeRelations: true,
|
|
@@ -205,6 +192,32 @@ export function defineCrudRestController<
|
|
|
205
192
|
): Promise<Count> {
|
|
206
193
|
return this.repository.count(where);
|
|
207
194
|
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@api({basePath: options.basePath, paths: {}})
|
|
198
|
+
class CrudRestControllerImpl extends ReadonlyRestControllerImpl {
|
|
199
|
+
constructor(
|
|
200
|
+
public readonly repository: EntityCrudRepository<T, IdType, Relations>,
|
|
201
|
+
) {
|
|
202
|
+
super(repository);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
@post('/', {
|
|
206
|
+
...response.model(200, `${modelName} instance created`, modelCtor),
|
|
207
|
+
})
|
|
208
|
+
async create(
|
|
209
|
+
@body(modelCtor, {
|
|
210
|
+
title: `New${modelName}`,
|
|
211
|
+
exclude: modelCtor.getIdProperties() as (keyof T)[],
|
|
212
|
+
})
|
|
213
|
+
data: Omit<T, IdName>,
|
|
214
|
+
): Promise<T> {
|
|
215
|
+
return this.repository.create(
|
|
216
|
+
// FIXME(bajtos) Improve repository API to support this use case
|
|
217
|
+
// with no explicit type-casts required
|
|
218
|
+
data as DataObject<T>,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
208
221
|
|
|
209
222
|
@patch('/', {
|
|
210
223
|
...response(200, `Count of ${modelName} models updated`, {
|
|
@@ -268,7 +281,9 @@ export function defineCrudRestController<
|
|
|
268
281
|
'controllerClass',
|
|
269
282
|
`return class ${controllerName} extends controllerClass {}`,
|
|
270
283
|
);
|
|
271
|
-
const controller = defineNamedController(
|
|
284
|
+
const controller = defineNamedController(
|
|
285
|
+
options.readonly ? ReadonlyRestControllerImpl : CrudRestControllerImpl,
|
|
286
|
+
);
|
|
272
287
|
assert.equal(controller.name, controllerName);
|
|
273
288
|
return controller;
|
|
274
289
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
1
|
+
// Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
|
|
2
2
|
// Node module: @loopback/rest-crud
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|