@terreno/api 0.0.1
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 +202 -0
- package/README.md +170 -0
- package/biome.jsonc +22 -0
- package/bunfig.toml +4 -0
- package/dist/api.d.ts +227 -0
- package/dist/api.js +1024 -0
- package/dist/api.test.d.ts +1 -0
- package/dist/api.test.js +2143 -0
- package/dist/auth.d.ts +50 -0
- package/dist/auth.js +512 -0
- package/dist/auth.test.d.ts +1 -0
- package/dist/auth.test.js +778 -0
- package/dist/errors.d.ts +75 -0
- package/dist/errors.js +216 -0
- package/dist/example.d.ts +1 -0
- package/dist/example.js +118 -0
- package/dist/expressServer.d.ts +35 -0
- package/dist/expressServer.js +436 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +30 -0
- package/dist/logger.d.ts +23 -0
- package/dist/logger.js +249 -0
- package/dist/middleware.d.ts +10 -0
- package/dist/middleware.js +52 -0
- package/dist/notifiers/googleChatNotifier.d.ts +5 -0
- package/dist/notifiers/googleChatNotifier.js +130 -0
- package/dist/notifiers/googleChatNotifier.test.d.ts +1 -0
- package/dist/notifiers/googleChatNotifier.test.js +260 -0
- package/dist/notifiers/index.d.ts +3 -0
- package/dist/notifiers/index.js +19 -0
- package/dist/notifiers/slackNotifier.d.ts +5 -0
- package/dist/notifiers/slackNotifier.js +130 -0
- package/dist/notifiers/slackNotifier.test.d.ts +1 -0
- package/dist/notifiers/slackNotifier.test.js +259 -0
- package/dist/notifiers/zoomNotifier.d.ts +34 -0
- package/dist/notifiers/zoomNotifier.js +181 -0
- package/dist/notifiers/zoomNotifier.test.d.ts +1 -0
- package/dist/notifiers/zoomNotifier.test.js +370 -0
- package/dist/openApi.d.ts +60 -0
- package/dist/openApi.js +441 -0
- package/dist/openApi.test.d.ts +1 -0
- package/dist/openApi.test.js +445 -0
- package/dist/openApiBuilder.d.ts +419 -0
- package/dist/openApiBuilder.js +424 -0
- package/dist/openApiBuilder.test.d.ts +1 -0
- package/dist/openApiBuilder.test.js +509 -0
- package/dist/openApiEtag.d.ts +7 -0
- package/dist/openApiEtag.js +38 -0
- package/dist/permissions.d.ts +26 -0
- package/dist/permissions.js +331 -0
- package/dist/permissions.test.d.ts +1 -0
- package/dist/permissions.test.js +413 -0
- package/dist/plugins.d.ts +67 -0
- package/dist/plugins.js +315 -0
- package/dist/plugins.test.d.ts +1 -0
- package/dist/plugins.test.js +639 -0
- package/dist/populate.d.ts +14 -0
- package/dist/populate.js +315 -0
- package/dist/populate.test.d.ts +1 -0
- package/dist/populate.test.js +133 -0
- package/dist/response.d.ts +0 -0
- package/dist/response.js +1 -0
- package/dist/tests/bunSetup.d.ts +1 -0
- package/dist/tests/bunSetup.js +297 -0
- package/dist/tests/index.d.ts +1 -0
- package/dist/tests/index.js +17 -0
- package/dist/tests.d.ts +99 -0
- package/dist/tests.js +273 -0
- package/dist/transformers.d.ts +25 -0
- package/dist/transformers.js +217 -0
- package/dist/transformers.test.d.ts +1 -0
- package/dist/transformers.test.js +370 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +143 -0
- package/dist/utils.test.d.ts +1 -0
- package/dist/utils.test.js +14 -0
- package/index.ts +1 -0
- package/package.json +88 -0
- package/src/__snapshots__/openApi.test.ts.snap +4814 -0
- package/src/__snapshots__/openApiBuilder.test.ts.snap +1485 -0
- package/src/api.test.ts +1661 -0
- package/src/api.ts +1036 -0
- package/src/auth.test.ts +550 -0
- package/src/auth.ts +408 -0
- package/src/errors.ts +225 -0
- package/src/example.ts +99 -0
- package/src/express.d.ts +5 -0
- package/src/expressServer.ts +387 -0
- package/src/index.ts +14 -0
- package/src/logger.ts +190 -0
- package/src/middleware.ts +18 -0
- package/src/notifiers/googleChatNotifier.test.ts +114 -0
- package/src/notifiers/googleChatNotifier.ts +47 -0
- package/src/notifiers/index.ts +3 -0
- package/src/notifiers/slackNotifier.test.ts +113 -0
- package/src/notifiers/slackNotifier.ts +55 -0
- package/src/notifiers/zoomNotifier.test.ts +207 -0
- package/src/notifiers/zoomNotifier.ts +111 -0
- package/src/openApi.test.ts +331 -0
- package/src/openApi.ts +494 -0
- package/src/openApiBuilder.test.ts +442 -0
- package/src/openApiBuilder.ts +636 -0
- package/src/openApiEtag.ts +40 -0
- package/src/permissions.test.ts +219 -0
- package/src/permissions.ts +228 -0
- package/src/plugins.test.ts +390 -0
- package/src/plugins.ts +289 -0
- package/src/populate.test.ts +65 -0
- package/src/populate.ts +258 -0
- package/src/response.ts +0 -0
- package/src/tests/bunSetup.ts +234 -0
- package/src/tests/index.ts +1 -0
- package/src/tests.ts +218 -0
- package/src/transformers.test.ts +202 -0
- package/src/transformers.ts +170 -0
- package/src/utils.test.ts +14 -0
- package/src/utils.ts +47 -0
- package/tsconfig.json +60 -0
- package/types.d.ts +17 -0
package/dist/openApi.js
ADDED
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
+
if (!m) return o;
|
|
16
|
+
var i = m.call(o), r, ar = [], e;
|
|
17
|
+
try {
|
|
18
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
+
}
|
|
20
|
+
catch (error) { e = { error: error }; }
|
|
21
|
+
finally {
|
|
22
|
+
try {
|
|
23
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
+
}
|
|
25
|
+
finally { if (e) throw e.error; }
|
|
26
|
+
}
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
+
if (ar || !(i in from)) {
|
|
32
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
+
ar[i] = from[i];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.defaultOpenApiErrorResponses = exports.apiErrorContent = void 0;
|
|
43
|
+
exports.getOpenApiMiddleware = getOpenApiMiddleware;
|
|
44
|
+
exports.listOpenApiMiddleware = listOpenApiMiddleware;
|
|
45
|
+
exports.createOpenApiMiddleware = createOpenApiMiddleware;
|
|
46
|
+
exports.patchOpenApiMiddleware = patchOpenApiMiddleware;
|
|
47
|
+
exports.deleteOpenApiMiddleware = deleteOpenApiMiddleware;
|
|
48
|
+
exports.readOpenApiMiddleware = readOpenApiMiddleware;
|
|
49
|
+
var flatten_1 = __importDefault(require("lodash/flatten"));
|
|
50
|
+
var merge_1 = __importDefault(require("lodash/merge"));
|
|
51
|
+
var mongoose_to_swagger_1 = __importDefault(require("mongoose-to-swagger"));
|
|
52
|
+
var logger_1 = require("./logger");
|
|
53
|
+
var populate_1 = require("./populate");
|
|
54
|
+
var noop = function (_a, _b, next) { return next(); };
|
|
55
|
+
var m2sOptions = {
|
|
56
|
+
props: ["readOnly", "required", "enum", "default"],
|
|
57
|
+
};
|
|
58
|
+
exports.apiErrorContent = {
|
|
59
|
+
"application/json": {
|
|
60
|
+
schema: { $ref: "#/components/schemas/APIError" },
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
// Default error responses
|
|
64
|
+
exports.defaultOpenApiErrorResponses = {
|
|
65
|
+
400: {
|
|
66
|
+
content: exports.apiErrorContent,
|
|
67
|
+
description: "Bad request",
|
|
68
|
+
},
|
|
69
|
+
401: {
|
|
70
|
+
description: "The user must be authenticated",
|
|
71
|
+
},
|
|
72
|
+
403: {
|
|
73
|
+
content: exports.apiErrorContent,
|
|
74
|
+
description: "The user is not allowed to perform this action on this document",
|
|
75
|
+
},
|
|
76
|
+
404: {
|
|
77
|
+
content: exports.apiErrorContent,
|
|
78
|
+
description: "Document not found",
|
|
79
|
+
},
|
|
80
|
+
405: {
|
|
81
|
+
content: exports.apiErrorContent,
|
|
82
|
+
description: "The user is not allowed to perform this action on any document",
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
// We repeat this constantly, so we make it a component so we only have to define it once.
|
|
86
|
+
function createAPIErrorComponent(openApi) {
|
|
87
|
+
// Create a schema component called APIError
|
|
88
|
+
openApi === null || openApi === void 0 ? void 0 : openApi.component("schemas", "APIError", {
|
|
89
|
+
properties: {
|
|
90
|
+
code: {
|
|
91
|
+
description: "An application-specific error code, expressed as a string value.",
|
|
92
|
+
type: "string",
|
|
93
|
+
},
|
|
94
|
+
detail: {
|
|
95
|
+
description: "A human-readable explanation specific to this occurrence of the problem. Like title, this field’s value can be localized.",
|
|
96
|
+
type: "string",
|
|
97
|
+
},
|
|
98
|
+
id: {
|
|
99
|
+
description: "A unique identifier for this particular occurrence of the problem.",
|
|
100
|
+
type: "string",
|
|
101
|
+
},
|
|
102
|
+
links: {
|
|
103
|
+
properties: {
|
|
104
|
+
about: {
|
|
105
|
+
description: "A link that leads to further details about this particular occurrence of the problem. When derefenced, this URI SHOULD return a human-readable description of the error.",
|
|
106
|
+
type: "string",
|
|
107
|
+
},
|
|
108
|
+
type: {
|
|
109
|
+
description: "A link that identifies the type of error that this particular error is an instance of. This URI SHOULD be dereferencable to a human-readable explanation of the general error.",
|
|
110
|
+
type: "string",
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
type: "object",
|
|
114
|
+
},
|
|
115
|
+
meta: {
|
|
116
|
+
description: "A meta object containing non-standard meta-information about the error.",
|
|
117
|
+
type: "object",
|
|
118
|
+
},
|
|
119
|
+
source: {
|
|
120
|
+
properties: {
|
|
121
|
+
header: {
|
|
122
|
+
description: "A string indicating the name of a single request header which caused the error.",
|
|
123
|
+
type: "string",
|
|
124
|
+
},
|
|
125
|
+
parameter: {
|
|
126
|
+
description: "A string indicating which URI query parameter caused the error.",
|
|
127
|
+
type: "string",
|
|
128
|
+
},
|
|
129
|
+
pointer: {
|
|
130
|
+
description: 'A JSON Pointer [RFC6901] to the associated entity in the request document [e.g. "/data" for a primary data object, or "/data/attributes/title" for a specific attribute].',
|
|
131
|
+
type: "string",
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
type: "object",
|
|
135
|
+
},
|
|
136
|
+
status: {
|
|
137
|
+
description: "The HTTP status code applicable to this problem, expressed as a string value.",
|
|
138
|
+
type: "number",
|
|
139
|
+
},
|
|
140
|
+
title: {
|
|
141
|
+
description: "The error message",
|
|
142
|
+
type: "string",
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
type: "object",
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function getOpenApiMiddleware(model, options) {
|
|
149
|
+
var _c, _d, _e, _f, _g;
|
|
150
|
+
createAPIErrorComponent(options.openApi);
|
|
151
|
+
if (!((_c = options.openApi) === null || _c === void 0 ? void 0 : _c.path)) {
|
|
152
|
+
// Just log this once rather than for each middleware.
|
|
153
|
+
logger_1.logger.debug("No options.openApi provided, skipping *OpenApiMiddleware");
|
|
154
|
+
return noop;
|
|
155
|
+
}
|
|
156
|
+
if (((_e = (_d = options.permissions) === null || _d === void 0 ? void 0 : _d.read) === null || _e === void 0 ? void 0 : _e.length) === 0) {
|
|
157
|
+
return noop;
|
|
158
|
+
}
|
|
159
|
+
var _h = (0, populate_1.getOpenApiSpecForModel)(model, {
|
|
160
|
+
extraModelProperties: options.openApiExtraModelProperties,
|
|
161
|
+
populatePaths: options.populatePaths,
|
|
162
|
+
}), properties = _h.properties, required = _h.required;
|
|
163
|
+
return options.openApi.path((0, merge_1.default)({
|
|
164
|
+
responses: __assign({ 200: {
|
|
165
|
+
content: {
|
|
166
|
+
"application/json": {
|
|
167
|
+
schema: {
|
|
168
|
+
properties: properties,
|
|
169
|
+
required: __spreadArray(__spreadArray([], __read(required), false), ["_id", "created", "updated"], false),
|
|
170
|
+
type: "object",
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
description: "Successful read",
|
|
175
|
+
} }, exports.defaultOpenApiErrorResponses),
|
|
176
|
+
tags: [model.collection.collectionName],
|
|
177
|
+
}, (_g = (_f = options.openApiOverwrite) === null || _f === void 0 ? void 0 : _f.get) !== null && _g !== void 0 ? _g : {}));
|
|
178
|
+
}
|
|
179
|
+
function listOpenApiMiddleware(model, options) {
|
|
180
|
+
var _c, _d, _e, _f, _g, _h;
|
|
181
|
+
if (!((_c = options.openApi) === null || _c === void 0 ? void 0 : _c.path)) {
|
|
182
|
+
return noop;
|
|
183
|
+
}
|
|
184
|
+
if (((_e = (_d = options.permissions) === null || _d === void 0 ? void 0 : _d.list) === null || _e === void 0 ? void 0 : _e.length) === 0) {
|
|
185
|
+
return noop;
|
|
186
|
+
}
|
|
187
|
+
var modelSwagger = (0, mongoose_to_swagger_1.default)(model, m2sOptions);
|
|
188
|
+
// TODO: handle permissions
|
|
189
|
+
// Convert modelRouter queryFields into OpenAPI parameters
|
|
190
|
+
var defaultQueryParams = [
|
|
191
|
+
{
|
|
192
|
+
in: "query",
|
|
193
|
+
name: "_id",
|
|
194
|
+
schema: {
|
|
195
|
+
properties: {
|
|
196
|
+
$in: {
|
|
197
|
+
items: {
|
|
198
|
+
type: "string",
|
|
199
|
+
},
|
|
200
|
+
type: "array",
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
type: "object",
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
];
|
|
207
|
+
var modelQueryParams = (0, flatten_1.default)((_f = options.queryFields) === null || _f === void 0 ? void 0 : _f.filter(function (field) { return field !== "_id"; }).map(function (field) {
|
|
208
|
+
var _c, _d, _e;
|
|
209
|
+
var params = [];
|
|
210
|
+
// Check for datetime/number to support gt/gte/lt/lte
|
|
211
|
+
if (((_c = modelSwagger.properties[field]) === null || _c === void 0 ? void 0 : _c.type) === "number" ||
|
|
212
|
+
((_d = modelSwagger.properties[field]) === null || _d === void 0 ? void 0 : _d.format) === "date-time") {
|
|
213
|
+
params.push({
|
|
214
|
+
in: "query",
|
|
215
|
+
name: field,
|
|
216
|
+
schema: {
|
|
217
|
+
oneOf: [
|
|
218
|
+
modelSwagger.properties[field],
|
|
219
|
+
{
|
|
220
|
+
properties: {
|
|
221
|
+
$gt: modelSwagger.properties[field],
|
|
222
|
+
$gte: modelSwagger.properties[field],
|
|
223
|
+
$lt: modelSwagger.properties[field],
|
|
224
|
+
$lte: modelSwagger.properties[field],
|
|
225
|
+
},
|
|
226
|
+
type: "object",
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
params.push({
|
|
234
|
+
in: "query",
|
|
235
|
+
name: field,
|
|
236
|
+
schema: {
|
|
237
|
+
oneOf: [
|
|
238
|
+
modelSwagger.properties[field],
|
|
239
|
+
{
|
|
240
|
+
properties: {
|
|
241
|
+
$in: {
|
|
242
|
+
items: {
|
|
243
|
+
type: (_e = modelSwagger.properties[field]) === null || _e === void 0 ? void 0 : _e.type,
|
|
244
|
+
},
|
|
245
|
+
type: "array",
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
type: "object",
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
return params;
|
|
255
|
+
}));
|
|
256
|
+
var _j = (0, populate_1.getOpenApiSpecForModel)(model, {
|
|
257
|
+
extraModelProperties: options.openApiExtraModelProperties,
|
|
258
|
+
populatePaths: options.populatePaths,
|
|
259
|
+
}), properties = _j.properties, required = _j.required;
|
|
260
|
+
return options.openApi.path((0, merge_1.default)({
|
|
261
|
+
parameters: __spreadArray(__spreadArray(__spreadArray([], __read(defaultQueryParams), false), __read((modelQueryParams !== null && modelQueryParams !== void 0 ? modelQueryParams : [])), false), [
|
|
262
|
+
// pagination
|
|
263
|
+
{
|
|
264
|
+
in: "query",
|
|
265
|
+
name: "page",
|
|
266
|
+
schema: {
|
|
267
|
+
type: "number",
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
in: "query",
|
|
272
|
+
name: "sort",
|
|
273
|
+
schema: {
|
|
274
|
+
type: "string",
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
in: "query",
|
|
279
|
+
name: "limit",
|
|
280
|
+
schema: {
|
|
281
|
+
type: "number",
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
], false),
|
|
285
|
+
responses: __assign({ 200: {
|
|
286
|
+
content: {
|
|
287
|
+
"application/json": {
|
|
288
|
+
schema: {
|
|
289
|
+
properties: {
|
|
290
|
+
data: {
|
|
291
|
+
items: {
|
|
292
|
+
properties: properties,
|
|
293
|
+
required: __spreadArray(__spreadArray([], __read(required), false), ["_id", "created", "updated"], false),
|
|
294
|
+
type: "object",
|
|
295
|
+
},
|
|
296
|
+
type: "array",
|
|
297
|
+
},
|
|
298
|
+
limit: {
|
|
299
|
+
type: "number",
|
|
300
|
+
},
|
|
301
|
+
more: {
|
|
302
|
+
type: "boolean",
|
|
303
|
+
},
|
|
304
|
+
page: {
|
|
305
|
+
type: "number",
|
|
306
|
+
},
|
|
307
|
+
total: {
|
|
308
|
+
type: "number",
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
type: "object",
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
description: "Successful list",
|
|
316
|
+
} }, exports.defaultOpenApiErrorResponses),
|
|
317
|
+
tags: [model.collection.collectionName],
|
|
318
|
+
}, (_h = (_g = options.openApiOverwrite) === null || _g === void 0 ? void 0 : _g.list) !== null && _h !== void 0 ? _h : {}));
|
|
319
|
+
}
|
|
320
|
+
function createOpenApiMiddleware(model, options) {
|
|
321
|
+
var _c, _d, _e, _f, _g;
|
|
322
|
+
if (!((_c = options.openApi) === null || _c === void 0 ? void 0 : _c.path)) {
|
|
323
|
+
return noop;
|
|
324
|
+
}
|
|
325
|
+
if (((_e = (_d = options.permissions) === null || _d === void 0 ? void 0 : _d.create) === null || _e === void 0 ? void 0 : _e.length) === 0) {
|
|
326
|
+
return noop;
|
|
327
|
+
}
|
|
328
|
+
var _h = (0, populate_1.getOpenApiSpecForModel)(model, {
|
|
329
|
+
extraModelProperties: options.openApiExtraModelProperties,
|
|
330
|
+
populatePaths: options.populatePaths,
|
|
331
|
+
}), properties = _h.properties, required = _h.required;
|
|
332
|
+
return options.openApi.path((0, merge_1.default)({
|
|
333
|
+
requestBody: {
|
|
334
|
+
content: {
|
|
335
|
+
"application/json": {
|
|
336
|
+
schema: {
|
|
337
|
+
properties: properties,
|
|
338
|
+
type: "object",
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
required: true,
|
|
343
|
+
},
|
|
344
|
+
responses: __assign({ 201: {
|
|
345
|
+
content: {
|
|
346
|
+
"application/json": {
|
|
347
|
+
schema: {
|
|
348
|
+
properties: properties,
|
|
349
|
+
required: __spreadArray(__spreadArray([], __read(required), false), ["_id", "created", "updated"], false),
|
|
350
|
+
type: "object",
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
description: "Successful create",
|
|
355
|
+
} }, exports.defaultOpenApiErrorResponses),
|
|
356
|
+
tags: [model.collection.collectionName],
|
|
357
|
+
}, (_g = (_f = options.openApiOverwrite) === null || _f === void 0 ? void 0 : _f.create) !== null && _g !== void 0 ? _g : {}));
|
|
358
|
+
}
|
|
359
|
+
function patchOpenApiMiddleware(model, options) {
|
|
360
|
+
var _c, _d, _e, _f, _g;
|
|
361
|
+
if (!((_c = options.openApi) === null || _c === void 0 ? void 0 : _c.path)) {
|
|
362
|
+
return noop;
|
|
363
|
+
}
|
|
364
|
+
if (((_e = (_d = options.permissions) === null || _d === void 0 ? void 0 : _d.update) === null || _e === void 0 ? void 0 : _e.length) === 0) {
|
|
365
|
+
return noop;
|
|
366
|
+
}
|
|
367
|
+
var _h = (0, populate_1.getOpenApiSpecForModel)(model, {
|
|
368
|
+
extraModelProperties: options.openApiExtraModelProperties,
|
|
369
|
+
populatePaths: options.populatePaths,
|
|
370
|
+
}), properties = _h.properties, required = _h.required;
|
|
371
|
+
return options.openApi.path((0, merge_1.default)({
|
|
372
|
+
requestBody: {
|
|
373
|
+
content: {
|
|
374
|
+
"application/json": {
|
|
375
|
+
schema: {
|
|
376
|
+
properties: properties,
|
|
377
|
+
type: "object",
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
required: true,
|
|
382
|
+
},
|
|
383
|
+
responses: __assign({ 200: {
|
|
384
|
+
content: {
|
|
385
|
+
"application/json": {
|
|
386
|
+
schema: {
|
|
387
|
+
properties: properties,
|
|
388
|
+
required: __spreadArray(__spreadArray([], __read(required), false), ["_id", "created", "updated"], false),
|
|
389
|
+
type: "object",
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
description: "Successful update",
|
|
394
|
+
} }, exports.defaultOpenApiErrorResponses),
|
|
395
|
+
tags: [model.collection.collectionName],
|
|
396
|
+
}, (_g = (_f = options.openApiOverwrite) === null || _f === void 0 ? void 0 : _f.update) !== null && _g !== void 0 ? _g : {}));
|
|
397
|
+
}
|
|
398
|
+
function deleteOpenApiMiddleware(model, options) {
|
|
399
|
+
var _c, _d, _e, _f, _g;
|
|
400
|
+
if (!((_c = options.openApi) === null || _c === void 0 ? void 0 : _c.path)) {
|
|
401
|
+
return noop;
|
|
402
|
+
}
|
|
403
|
+
if (((_e = (_d = options.permissions) === null || _d === void 0 ? void 0 : _d.delete) === null || _e === void 0 ? void 0 : _e.length) === 0) {
|
|
404
|
+
return noop;
|
|
405
|
+
}
|
|
406
|
+
return options.openApi.path((0, merge_1.default)({
|
|
407
|
+
responses: __assign({ 204: {
|
|
408
|
+
description: "Successful delete",
|
|
409
|
+
} }, exports.defaultOpenApiErrorResponses),
|
|
410
|
+
tags: [model.collection.collectionName],
|
|
411
|
+
}, (_g = (_f = options.openApiOverwrite) === null || _f === void 0 ? void 0 : _f.delete) !== null && _g !== void 0 ? _g : {}));
|
|
412
|
+
}
|
|
413
|
+
// This is a generic OpenAPI wrapper for a read that returns any object described by `properties`.
|
|
414
|
+
// Useful for endpoints that don't directly map to a model.
|
|
415
|
+
function readOpenApiMiddleware(options, properties, required, queryParameters) {
|
|
416
|
+
var _c, _d, _e, _f, _g;
|
|
417
|
+
if (!((_c = options.openApi) === null || _c === void 0 ? void 0 : _c.path)) {
|
|
418
|
+
// Just log this once rather than for each middleware.
|
|
419
|
+
logger_1.logger.debug("No options.openApi provided, skipping *OpenApiMiddleware");
|
|
420
|
+
return noop;
|
|
421
|
+
}
|
|
422
|
+
if (((_e = (_d = options.permissions) === null || _d === void 0 ? void 0 : _d.read) === null || _e === void 0 ? void 0 : _e.length) === 0) {
|
|
423
|
+
return noop;
|
|
424
|
+
}
|
|
425
|
+
return options.openApi.path((0, merge_1.default)({
|
|
426
|
+
parameters: queryParameters,
|
|
427
|
+
responses: __assign({ 200: {
|
|
428
|
+
content: {
|
|
429
|
+
"application/json": {
|
|
430
|
+
schema: {
|
|
431
|
+
properties: properties,
|
|
432
|
+
required: required,
|
|
433
|
+
type: "object",
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
description: "Successful read",
|
|
438
|
+
} }, exports.defaultOpenApiErrorResponses),
|
|
439
|
+
tags: [],
|
|
440
|
+
}, (_g = (_f = options.openApiOverwrite) === null || _f === void 0 ? void 0 : _f.get) !== null && _g !== void 0 ? _g : {}));
|
|
441
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|