@opra/core 0.16.2 → 0.17.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/cjs/adapter/http/http-adapter.js +59 -30
- package/esm/adapter/adapter.js +17 -22
- package/esm/adapter/http/express-adapter.js +6 -11
- package/esm/adapter/http/http-adapter.js +114 -89
- package/esm/adapter/http/http-request-context.host.js +2 -6
- package/esm/adapter/http/http-request.host.js +2 -6
- package/esm/adapter/http/http-response.host.js +2 -6
- package/esm/adapter/interfaces/logger.interface.js +1 -2
- package/esm/adapter/interfaces/request-context.interface.js +1 -2
- package/esm/adapter/interfaces/request.interface.js +1 -2
- package/esm/adapter/interfaces/response.interface.js +1 -2
- package/esm/adapter/internal/metadata.resource.js +12 -15
- package/esm/adapter/request-context.host.js +2 -6
- package/esm/adapter/request.host.js +1 -5
- package/esm/adapter/response.host.js +1 -5
- package/esm/augmentation/resource.augmentation.js +9 -11
- package/esm/index.js +10 -13
- package/esm/types.js +1 -2
- package/package.json +2 -2
|
@@ -120,10 +120,11 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
120
120
|
try {
|
|
121
121
|
const url = new common_1.OpraURL();
|
|
122
122
|
url.searchParams.define({
|
|
123
|
-
'$
|
|
124
|
-
'$
|
|
125
|
-
'$
|
|
126
|
-
'$
|
|
123
|
+
'$search': { codec: 'string' },
|
|
124
|
+
'$pick': { codec: 'string', array: 'strict' },
|
|
125
|
+
'$omit': { codec: 'string', array: 'strict' },
|
|
126
|
+
'$include': { codec: 'string', array: 'strict' },
|
|
127
|
+
'$sort': { codec: 'string', array: 'strict' },
|
|
127
128
|
'$filter': { codec: 'filter' },
|
|
128
129
|
'$limit': { codec: 'number' },
|
|
129
130
|
'$skip': { codec: 'number' },
|
|
@@ -156,6 +157,9 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
156
157
|
switch (method) {
|
|
157
158
|
case 'POST': {
|
|
158
159
|
if (!p.key) {
|
|
160
|
+
const pick = params.get('$pick');
|
|
161
|
+
const omit = params.get('$omit');
|
|
162
|
+
const include = params.get('$include');
|
|
159
163
|
return new http_request_host_js_1.HttpRequestHost({
|
|
160
164
|
kind: 'CollectionCreateRequest',
|
|
161
165
|
resource,
|
|
@@ -164,9 +168,9 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
164
168
|
many: false,
|
|
165
169
|
args: {
|
|
166
170
|
data: incoming.body,
|
|
167
|
-
pick: resource.
|
|
168
|
-
omit: resource.
|
|
169
|
-
include: resource.
|
|
171
|
+
pick: pick && resource.normalizeFieldPath(pick),
|
|
172
|
+
omit: omit && resource.normalizeFieldPath(omit),
|
|
173
|
+
include: include && resource.normalizeFieldPath(include)
|
|
170
174
|
}
|
|
171
175
|
}, incoming);
|
|
172
176
|
}
|
|
@@ -185,6 +189,7 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
185
189
|
}
|
|
186
190
|
}, incoming);
|
|
187
191
|
}
|
|
192
|
+
const filter = params.get('$filter');
|
|
188
193
|
return new http_request_host_js_1.HttpRequestHost({
|
|
189
194
|
kind: 'CollectionDeleteManyRequest',
|
|
190
195
|
resource,
|
|
@@ -192,11 +197,14 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
192
197
|
crud: 'delete',
|
|
193
198
|
many: true,
|
|
194
199
|
args: {
|
|
195
|
-
filter: resource.
|
|
200
|
+
filter: filter && resource.normalizeFilter(filter)
|
|
196
201
|
}
|
|
197
202
|
}, incoming);
|
|
198
203
|
}
|
|
199
204
|
case 'GET': {
|
|
205
|
+
const pick = params.get('$pick');
|
|
206
|
+
const omit = params.get('$omit');
|
|
207
|
+
const include = params.get('$include');
|
|
200
208
|
if (p.key) {
|
|
201
209
|
return new http_request_host_js_1.HttpRequestHost({
|
|
202
210
|
kind: 'CollectionGetRequest',
|
|
@@ -206,12 +214,14 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
206
214
|
many: false,
|
|
207
215
|
args: {
|
|
208
216
|
key: resource.parseKeyValue(p.key),
|
|
209
|
-
pick: resource.
|
|
210
|
-
omit: resource.
|
|
211
|
-
include: resource.
|
|
217
|
+
pick: pick && resource.normalizeFieldPath(pick),
|
|
218
|
+
omit: omit && resource.normalizeFieldPath(omit),
|
|
219
|
+
include: include && resource.normalizeFieldPath(include)
|
|
212
220
|
}
|
|
213
221
|
}, incoming);
|
|
214
222
|
}
|
|
223
|
+
const filter = params.get('$filter');
|
|
224
|
+
const sort = params.get('$sort');
|
|
215
225
|
return new http_request_host_js_1.HttpRequestHost({
|
|
216
226
|
kind: 'CollectionFindManyRequest',
|
|
217
227
|
resource,
|
|
@@ -219,11 +229,11 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
219
229
|
crud: 'read',
|
|
220
230
|
many: true,
|
|
221
231
|
args: {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
filter: resource.
|
|
232
|
+
pick: pick && resource.normalizeFieldPath(pick),
|
|
233
|
+
omit: omit && resource.normalizeFieldPath(omit),
|
|
234
|
+
include: include && resource.normalizeFieldPath(include),
|
|
235
|
+
sort: sort && resource.normalizeSortFields(sort),
|
|
236
|
+
filter: filter && resource.normalizeFilter(filter),
|
|
227
237
|
limit: params.get('$limit'),
|
|
228
238
|
skip: params.get('$skip'),
|
|
229
239
|
distinct: params.get('$distinct'),
|
|
@@ -233,6 +243,9 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
233
243
|
}
|
|
234
244
|
case 'PATCH': {
|
|
235
245
|
if (p.key) {
|
|
246
|
+
const pick = params.get('$pick');
|
|
247
|
+
const omit = params.get('$omit');
|
|
248
|
+
const include = params.get('$include');
|
|
236
249
|
return new http_request_host_js_1.HttpRequestHost({
|
|
237
250
|
kind: 'CollectionUpdateRequest',
|
|
238
251
|
resource,
|
|
@@ -242,12 +255,13 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
242
255
|
args: {
|
|
243
256
|
key: resource.parseKeyValue(p.key),
|
|
244
257
|
data: incoming.body,
|
|
245
|
-
pick: resource.
|
|
246
|
-
omit: resource.
|
|
247
|
-
include: resource.
|
|
258
|
+
pick: pick && resource.normalizeFieldPath(pick),
|
|
259
|
+
omit: omit && resource.normalizeFieldPath(omit),
|
|
260
|
+
include: include && resource.normalizeFieldPath(include),
|
|
248
261
|
}
|
|
249
262
|
}, incoming);
|
|
250
263
|
}
|
|
264
|
+
const filter = params.get('$filter');
|
|
251
265
|
return new http_request_host_js_1.HttpRequestHost({
|
|
252
266
|
kind: 'CollectionUpdateManyRequest',
|
|
253
267
|
resource,
|
|
@@ -256,19 +270,26 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
256
270
|
many: true,
|
|
257
271
|
args: {
|
|
258
272
|
data: incoming.body,
|
|
259
|
-
filter: resource.
|
|
273
|
+
filter: filter && resource.normalizeFilter(filter),
|
|
260
274
|
}
|
|
261
275
|
}, incoming);
|
|
262
276
|
}
|
|
277
|
+
default:
|
|
278
|
+
throw new common_1.BadRequestError();
|
|
263
279
|
}
|
|
264
280
|
}
|
|
265
281
|
else
|
|
266
282
|
/*
|
|
267
283
|
* Singleton
|
|
268
284
|
*/
|
|
269
|
-
if (resource instanceof common_1.Singleton
|
|
285
|
+
if (resource instanceof common_1.Singleton) {
|
|
286
|
+
if (p.key)
|
|
287
|
+
throw new common_1.BadRequestError();
|
|
270
288
|
switch (method) {
|
|
271
289
|
case 'POST': {
|
|
290
|
+
const pick = params.get('$pick');
|
|
291
|
+
const omit = params.get('$omit');
|
|
292
|
+
const include = params.get('$include');
|
|
272
293
|
return new http_request_host_js_1.HttpRequestHost({
|
|
273
294
|
kind: 'SingletonCreateRequest',
|
|
274
295
|
resource,
|
|
@@ -277,9 +298,9 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
277
298
|
many: false,
|
|
278
299
|
args: {
|
|
279
300
|
data: incoming.body,
|
|
280
|
-
pick: resource.
|
|
281
|
-
omit: resource.
|
|
282
|
-
include: resource.
|
|
301
|
+
pick: pick && resource.normalizeFieldPath(pick),
|
|
302
|
+
omit: omit && resource.normalizeFieldPath(omit),
|
|
303
|
+
include: include && resource.normalizeFieldPath(include),
|
|
283
304
|
}
|
|
284
305
|
}, incoming);
|
|
285
306
|
}
|
|
@@ -294,6 +315,9 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
294
315
|
}, incoming);
|
|
295
316
|
}
|
|
296
317
|
case 'GET': {
|
|
318
|
+
const pick = params.get('$pick');
|
|
319
|
+
const omit = params.get('$omit');
|
|
320
|
+
const include = params.get('$include');
|
|
297
321
|
return new http_request_host_js_1.HttpRequestHost({
|
|
298
322
|
kind: 'SingletonGetRequest',
|
|
299
323
|
resource,
|
|
@@ -301,13 +325,16 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
301
325
|
crud: 'read',
|
|
302
326
|
many: false,
|
|
303
327
|
args: {
|
|
304
|
-
pick: resource.
|
|
305
|
-
omit: resource.
|
|
306
|
-
include: resource.
|
|
328
|
+
pick: pick && resource.normalizeFieldPath(pick),
|
|
329
|
+
omit: omit && resource.normalizeFieldPath(omit),
|
|
330
|
+
include: include && resource.normalizeFieldPath(include),
|
|
307
331
|
}
|
|
308
332
|
}, incoming);
|
|
309
333
|
}
|
|
310
334
|
case 'PATCH': {
|
|
335
|
+
const pick = params.get('$pick');
|
|
336
|
+
const omit = params.get('$omit');
|
|
337
|
+
const include = params.get('$include');
|
|
311
338
|
return new http_request_host_js_1.HttpRequestHost({
|
|
312
339
|
kind: 'SingletonUpdateRequest',
|
|
313
340
|
resource,
|
|
@@ -316,12 +343,14 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
316
343
|
many: false,
|
|
317
344
|
args: {
|
|
318
345
|
data: incoming.body,
|
|
319
|
-
pick: resource.
|
|
320
|
-
omit: resource.
|
|
321
|
-
include: resource.
|
|
346
|
+
pick: pick && resource.normalizeFieldPath(pick),
|
|
347
|
+
omit: omit && resource.normalizeFieldPath(omit),
|
|
348
|
+
include: include && resource.normalizeFieldPath(include),
|
|
322
349
|
}
|
|
323
350
|
}, incoming);
|
|
324
351
|
}
|
|
352
|
+
default:
|
|
353
|
+
throw new common_1.BadRequestError();
|
|
325
354
|
}
|
|
326
355
|
}
|
|
327
356
|
else
|
package/esm/adapter/adapter.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
|
-
const strict_typed_events_1 = require("strict-typed-events");
|
|
7
|
-
const common_1 = require("@opra/common");
|
|
8
|
-
const metadata_resource_js_1 = require("./internal/metadata.resource.js");
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
3
|
+
import { Collection, DocumentFactory, ForbiddenError, getStackFileName, I18n, OpraSchema, ResourceNotFoundError, Singleton, translate, } from '@opra/common';
|
|
4
|
+
import { MetadataResource } from './internal/metadata.resource.js';
|
|
9
5
|
/**
|
|
10
6
|
* @class OpraAdapter
|
|
11
7
|
*/
|
|
12
|
-
class OpraAdapter extends
|
|
8
|
+
export class OpraAdapter extends AsyncEventEmitter {
|
|
13
9
|
constructor(api) {
|
|
14
10
|
super();
|
|
15
11
|
this.api = api;
|
|
@@ -21,25 +17,25 @@ class OpraAdapter extends strict_typed_events_1.AsyncEventEmitter {
|
|
|
21
17
|
*/
|
|
22
18
|
async init(options) {
|
|
23
19
|
this.logger = options?.logger;
|
|
24
|
-
if (options?.i18n instanceof
|
|
20
|
+
if (options?.i18n instanceof I18n)
|
|
25
21
|
this.i18n = options.i18n;
|
|
26
22
|
else if (typeof options?.i18n === 'function')
|
|
27
23
|
this.i18n = await options.i18n();
|
|
28
24
|
else
|
|
29
25
|
this.i18n = await this._createI18n(options?.i18n);
|
|
30
|
-
this.i18n = this.i18n ||
|
|
26
|
+
this.i18n = this.i18n || I18n.defaultInstance;
|
|
31
27
|
if (!this.i18n.isInitialized)
|
|
32
28
|
await this.i18n.init();
|
|
33
29
|
if (options?.onRequest)
|
|
34
30
|
this.on('request', options.onRequest);
|
|
35
|
-
this._internalDoc = await
|
|
36
|
-
version:
|
|
31
|
+
this._internalDoc = await DocumentFactory.createDocument({
|
|
32
|
+
version: OpraSchema.SpecVersion,
|
|
37
33
|
info: {
|
|
38
|
-
version:
|
|
34
|
+
version: OpraSchema.SpecVersion,
|
|
39
35
|
title: 'Internal resources',
|
|
40
36
|
},
|
|
41
37
|
references: { 'api': this.api },
|
|
42
|
-
resources: [new
|
|
38
|
+
resources: [new MetadataResource(this.api)]
|
|
43
39
|
});
|
|
44
40
|
const promises = [];
|
|
45
41
|
for (const r of this.api.resources.values()) {
|
|
@@ -65,11 +61,11 @@ class OpraAdapter extends strict_typed_events_1.AsyncEventEmitter {
|
|
|
65
61
|
await this.emitAsync('request', context);
|
|
66
62
|
const { request, response } = context;
|
|
67
63
|
const { resource, operation } = request;
|
|
68
|
-
if (resource instanceof
|
|
64
|
+
if (resource instanceof Collection || resource instanceof Singleton) {
|
|
69
65
|
const endpoint = resource.operations[operation];
|
|
70
66
|
if (!endpoint?.handler)
|
|
71
|
-
throw new
|
|
72
|
-
message:
|
|
67
|
+
throw new ForbiddenError({
|
|
68
|
+
message: translate('RESOLVER_FORBIDDEN', { operation }, `The resource endpoint does not accept '{{operation}}' operations`),
|
|
73
69
|
severity: 'error',
|
|
74
70
|
code: 'RESOLVER_FORBIDDEN'
|
|
75
71
|
});
|
|
@@ -98,7 +94,7 @@ class OpraAdapter extends strict_typed_events_1.AsyncEventEmitter {
|
|
|
98
94
|
response.value = Array.isArray(response.value) ? response.value : [response.value];
|
|
99
95
|
}
|
|
100
96
|
if ((request.operation === 'get' || request.operation === 'update') && response.value == null)
|
|
101
|
-
throw new
|
|
97
|
+
throw new ResourceNotFoundError(resource.name, request.args.key);
|
|
102
98
|
}
|
|
103
99
|
}
|
|
104
100
|
async _createI18n(options) {
|
|
@@ -106,13 +102,12 @@ class OpraAdapter extends strict_typed_events_1.AsyncEventEmitter {
|
|
|
106
102
|
...options,
|
|
107
103
|
};
|
|
108
104
|
delete opts.resourceDirs;
|
|
109
|
-
const instance =
|
|
105
|
+
const instance = I18n.createInstance(opts);
|
|
110
106
|
await instance.init();
|
|
111
|
-
await instance.loadResourceDir(
|
|
107
|
+
await instance.loadResourceDir(path.resolve(getStackFileName(), '../../../i18n'));
|
|
112
108
|
if (options?.resourceDirs)
|
|
113
109
|
for (const dir of options.resourceDirs)
|
|
114
110
|
await instance.loadResourceDir(dir);
|
|
115
111
|
return instance;
|
|
116
112
|
}
|
|
117
113
|
}
|
|
118
|
-
exports.OpraAdapter = OpraAdapter;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const body_parser_1 = tslib_1.__importDefault(require("body-parser"));
|
|
6
|
-
const common_1 = require("@opra/common");
|
|
7
|
-
const http_adapter_js_1 = require("./http-adapter.js");
|
|
1
|
+
import bodyParser from 'body-parser';
|
|
2
|
+
import { normalizePath } from '@opra/common';
|
|
3
|
+
import { OpraHttpAdapter } from './http-adapter.js';
|
|
8
4
|
const noOp = () => void 0;
|
|
9
|
-
class OpraExpressAdapter extends
|
|
5
|
+
export class OpraExpressAdapter extends OpraHttpAdapter {
|
|
10
6
|
constructor() {
|
|
11
7
|
super(...arguments);
|
|
12
8
|
this.platform = 'express';
|
|
@@ -14,8 +10,8 @@ class OpraExpressAdapter extends http_adapter_js_1.OpraHttpAdapter {
|
|
|
14
10
|
static async create(app, document, options) {
|
|
15
11
|
const adapter = new OpraExpressAdapter(document);
|
|
16
12
|
await adapter.init(options);
|
|
17
|
-
const prefix = '/' +
|
|
18
|
-
app.use(prefix,
|
|
13
|
+
const prefix = '/' + normalizePath(options?.prefix, true);
|
|
14
|
+
app.use(prefix, bodyParser.json());
|
|
19
15
|
app.use(prefix, (req, res, next) => {
|
|
20
16
|
req.end = noOp;
|
|
21
17
|
req.send = noOp;
|
|
@@ -24,4 +20,3 @@ class OpraExpressAdapter extends http_adapter_js_1.OpraHttpAdapter {
|
|
|
24
20
|
return adapter;
|
|
25
21
|
}
|
|
26
22
|
}
|
|
27
|
-
exports.OpraExpressAdapter = OpraExpressAdapter;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const http_request_host_js_1 = require("./http-request.host.js");
|
|
8
|
-
const http_request_context_host_js_1 = require("./http-request-context.host.js");
|
|
9
|
-
const http_response_host_js_1 = require("./http-response.host.js");
|
|
1
|
+
import { Task } from 'power-tasks';
|
|
2
|
+
import { BadRequestError, Collection, HttpHeaderCodes, HttpStatusCodes, InternalServerError, isReadable, IssueSeverity, MethodNotAllowedError, OpraException, OpraSchema, OpraURL, Singleton, wrapException } from '@opra/common';
|
|
3
|
+
import { OpraAdapter } from '../adapter.js';
|
|
4
|
+
import { HttpRequestHost } from './http-request.host.js';
|
|
5
|
+
import { HttpRequestContextHost } from './http-request-context.host.js';
|
|
6
|
+
import { HttpResponseHost } from './http-response.host.js';
|
|
10
7
|
/**
|
|
11
8
|
*
|
|
12
9
|
* @class OpraHttpAdapter
|
|
13
10
|
*/
|
|
14
|
-
class OpraHttpAdapter extends
|
|
11
|
+
export class OpraHttpAdapter extends OpraAdapter {
|
|
15
12
|
/**
|
|
16
13
|
* Main http request handler
|
|
17
14
|
* @param incoming
|
|
@@ -22,17 +19,17 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
22
19
|
try {
|
|
23
20
|
// Batch
|
|
24
21
|
if (incoming.is('multipart/mixed')) {
|
|
25
|
-
throw new
|
|
22
|
+
throw new BadRequestError({ message: 'Not implemented yet' });
|
|
26
23
|
}
|
|
27
24
|
if (!(incoming.method === 'POST' || incoming.method === 'PATCH') || incoming.is('json')) {
|
|
28
25
|
const request = await this.parseRequest(incoming);
|
|
29
|
-
const response = new
|
|
30
|
-
const context = new
|
|
31
|
-
const task = new
|
|
26
|
+
const response = new HttpResponseHost({}, outgoing);
|
|
27
|
+
const context = new HttpRequestContextHost(this.platform, this.api, request, response);
|
|
28
|
+
const task = new Task(async () => {
|
|
32
29
|
try {
|
|
33
30
|
await this.executeRequest(context);
|
|
34
31
|
if (request.operation === 'findMany' && request.args.count && response.count != null) {
|
|
35
|
-
response.switchToHttp().header(
|
|
32
|
+
response.switchToHttp().header(HttpHeaderCodes.X_Opra_Total_Matches, String(response.count));
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
35
|
catch (error) {
|
|
@@ -50,7 +47,7 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
50
47
|
await this.emitAsync('request-finish', context);
|
|
51
48
|
return;
|
|
52
49
|
}
|
|
53
|
-
throw new
|
|
50
|
+
throw new BadRequestError({ message: 'Unsupported Content-Type' });
|
|
54
51
|
}
|
|
55
52
|
catch (error) {
|
|
56
53
|
await this.errorHandler(incoming, outgoing, [error]);
|
|
@@ -58,30 +55,30 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
58
55
|
}
|
|
59
56
|
async errorHandler(incoming, outgoing, errors) {
|
|
60
57
|
errors.forEach(e => {
|
|
61
|
-
this.log((e instanceof
|
|
58
|
+
this.log((e instanceof OpraException) ? 'error' : 'fatal', incoming, e); // todo. implement a better logger
|
|
62
59
|
});
|
|
63
|
-
errors = errors.map(
|
|
60
|
+
errors = errors.map(wrapException);
|
|
64
61
|
let status = outgoing.statusCode || 0;
|
|
65
62
|
// Sort errors from fatal to info
|
|
66
63
|
errors.sort((a, b) => {
|
|
67
|
-
const i =
|
|
64
|
+
const i = IssueSeverity.Keys.indexOf(a.issue.severity) - IssueSeverity.Keys.indexOf(b.issue.severity);
|
|
68
65
|
if (i === 0)
|
|
69
66
|
return b.status - a.status;
|
|
70
67
|
return i;
|
|
71
68
|
});
|
|
72
|
-
if (!status || status <
|
|
69
|
+
if (!status || status < HttpStatusCodes.BAD_REQUEST) {
|
|
73
70
|
status = errors[0].status;
|
|
74
|
-
if (status <
|
|
75
|
-
status =
|
|
71
|
+
if (status < HttpStatusCodes.BAD_REQUEST)
|
|
72
|
+
status = HttpStatusCodes.INTERNAL_SERVER_ERROR;
|
|
76
73
|
}
|
|
77
74
|
const body = this.i18n.deep({
|
|
78
75
|
errors: errors.map(e => e.issue)
|
|
79
76
|
});
|
|
80
|
-
outgoing.set(
|
|
81
|
-
outgoing.set(
|
|
82
|
-
outgoing.set(
|
|
83
|
-
outgoing.set(
|
|
84
|
-
outgoing.set(
|
|
77
|
+
outgoing.set(HttpHeaderCodes.Content_Type, 'application/json; charset=utf-8');
|
|
78
|
+
outgoing.set(HttpHeaderCodes.Cache_Control, 'no-cache');
|
|
79
|
+
outgoing.set(HttpHeaderCodes.Pragma, 'no-cache');
|
|
80
|
+
outgoing.set(HttpHeaderCodes.Expires, '-1');
|
|
81
|
+
outgoing.set(HttpHeaderCodes.X_Opra_Version, OpraSchema.SpecVersion);
|
|
85
82
|
outgoing.status(status);
|
|
86
83
|
outgoing.send(JSON.stringify(body));
|
|
87
84
|
outgoing.end();
|
|
@@ -100,13 +97,13 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
100
97
|
const response = context.response;
|
|
101
98
|
const { crud } = request;
|
|
102
99
|
const httpResponse = response.switchToHttp();
|
|
103
|
-
if (request.resource instanceof
|
|
104
|
-
httpResponse.set(
|
|
105
|
-
httpResponse.set(
|
|
100
|
+
if (request.resource instanceof Singleton || request.resource instanceof Collection) {
|
|
101
|
+
httpResponse.set(HttpHeaderCodes.X_Opra_Data_Type, request.resource.type.name);
|
|
102
|
+
httpResponse.set(HttpHeaderCodes.X_Opra_Operation, request.operation);
|
|
106
103
|
}
|
|
107
104
|
if (crud === 'create') {
|
|
108
105
|
if (!response.value)
|
|
109
|
-
throw new
|
|
106
|
+
throw new InternalServerError();
|
|
110
107
|
// todo validate
|
|
111
108
|
httpResponse.status(201);
|
|
112
109
|
}
|
|
@@ -118,12 +115,13 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
118
115
|
*/
|
|
119
116
|
async parseRequest(incoming) {
|
|
120
117
|
try {
|
|
121
|
-
const url = new
|
|
118
|
+
const url = new OpraURL();
|
|
122
119
|
url.searchParams.define({
|
|
123
|
-
'$
|
|
124
|
-
'$
|
|
125
|
-
'$
|
|
126
|
-
'$
|
|
120
|
+
'$search': { codec: 'string' },
|
|
121
|
+
'$pick': { codec: 'string', array: 'strict' },
|
|
122
|
+
'$omit': { codec: 'string', array: 'strict' },
|
|
123
|
+
'$include': { codec: 'string', array: 'strict' },
|
|
124
|
+
'$sort': { codec: 'string', array: 'strict' },
|
|
127
125
|
'$filter': { codec: 'filter' },
|
|
128
126
|
'$limit': { codec: 'number' },
|
|
129
127
|
'$skip': { codec: 'number' },
|
|
@@ -133,10 +131,10 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
133
131
|
url.parse(incoming.url);
|
|
134
132
|
// const {context, url, method, headers, body, contentId} = args;
|
|
135
133
|
if (!url.path.size)
|
|
136
|
-
throw new
|
|
134
|
+
throw new BadRequestError();
|
|
137
135
|
const method = incoming.method;
|
|
138
136
|
if (method !== 'GET' && url.path.size > 1)
|
|
139
|
-
throw new
|
|
137
|
+
throw new BadRequestError();
|
|
140
138
|
// const pathLen = url.path.size;
|
|
141
139
|
// let pathIndex = 0;
|
|
142
140
|
const params = url.searchParams;
|
|
@@ -152,11 +150,14 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
152
150
|
/*
|
|
153
151
|
* Collection
|
|
154
152
|
*/
|
|
155
|
-
if (resource instanceof
|
|
153
|
+
if (resource instanceof Collection) {
|
|
156
154
|
switch (method) {
|
|
157
155
|
case 'POST': {
|
|
158
156
|
if (!p.key) {
|
|
159
|
-
|
|
157
|
+
const pick = params.get('$pick');
|
|
158
|
+
const omit = params.get('$omit');
|
|
159
|
+
const include = params.get('$include');
|
|
160
|
+
return new HttpRequestHost({
|
|
160
161
|
kind: 'CollectionCreateRequest',
|
|
161
162
|
resource,
|
|
162
163
|
operation: 'create',
|
|
@@ -164,9 +165,9 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
164
165
|
many: false,
|
|
165
166
|
args: {
|
|
166
167
|
data: incoming.body,
|
|
167
|
-
pick: resource.
|
|
168
|
-
omit: resource.
|
|
169
|
-
include: resource.
|
|
168
|
+
pick: pick && resource.normalizeFieldPath(pick),
|
|
169
|
+
omit: omit && resource.normalizeFieldPath(omit),
|
|
170
|
+
include: include && resource.normalizeFieldPath(include)
|
|
170
171
|
}
|
|
171
172
|
}, incoming);
|
|
172
173
|
}
|
|
@@ -174,7 +175,7 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
174
175
|
}
|
|
175
176
|
case 'DELETE': {
|
|
176
177
|
if (p.key) {
|
|
177
|
-
return new
|
|
178
|
+
return new HttpRequestHost({
|
|
178
179
|
kind: 'CollectionDeleteRequest',
|
|
179
180
|
resource,
|
|
180
181
|
operation: 'delete',
|
|
@@ -185,20 +186,24 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
185
186
|
}
|
|
186
187
|
}, incoming);
|
|
187
188
|
}
|
|
188
|
-
|
|
189
|
+
const filter = params.get('$filter');
|
|
190
|
+
return new HttpRequestHost({
|
|
189
191
|
kind: 'CollectionDeleteManyRequest',
|
|
190
192
|
resource,
|
|
191
193
|
operation: 'deleteMany',
|
|
192
194
|
crud: 'delete',
|
|
193
195
|
many: true,
|
|
194
196
|
args: {
|
|
195
|
-
filter: resource.
|
|
197
|
+
filter: filter && resource.normalizeFilter(filter)
|
|
196
198
|
}
|
|
197
199
|
}, incoming);
|
|
198
200
|
}
|
|
199
201
|
case 'GET': {
|
|
202
|
+
const pick = params.get('$pick');
|
|
203
|
+
const omit = params.get('$omit');
|
|
204
|
+
const include = params.get('$include');
|
|
200
205
|
if (p.key) {
|
|
201
|
-
return new
|
|
206
|
+
return new HttpRequestHost({
|
|
202
207
|
kind: 'CollectionGetRequest',
|
|
203
208
|
resource,
|
|
204
209
|
operation: 'get',
|
|
@@ -206,24 +211,26 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
206
211
|
many: false,
|
|
207
212
|
args: {
|
|
208
213
|
key: resource.parseKeyValue(p.key),
|
|
209
|
-
pick: resource.
|
|
210
|
-
omit: resource.
|
|
211
|
-
include: resource.
|
|
214
|
+
pick: pick && resource.normalizeFieldPath(pick),
|
|
215
|
+
omit: omit && resource.normalizeFieldPath(omit),
|
|
216
|
+
include: include && resource.normalizeFieldPath(include)
|
|
212
217
|
}
|
|
213
218
|
}, incoming);
|
|
214
219
|
}
|
|
215
|
-
|
|
220
|
+
const filter = params.get('$filter');
|
|
221
|
+
const sort = params.get('$sort');
|
|
222
|
+
return new HttpRequestHost({
|
|
216
223
|
kind: 'CollectionFindManyRequest',
|
|
217
224
|
resource,
|
|
218
225
|
operation: 'findMany',
|
|
219
226
|
crud: 'read',
|
|
220
227
|
many: true,
|
|
221
228
|
args: {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
filter: resource.
|
|
229
|
+
pick: pick && resource.normalizeFieldPath(pick),
|
|
230
|
+
omit: omit && resource.normalizeFieldPath(omit),
|
|
231
|
+
include: include && resource.normalizeFieldPath(include),
|
|
232
|
+
sort: sort && resource.normalizeSortFields(sort),
|
|
233
|
+
filter: filter && resource.normalizeFilter(filter),
|
|
227
234
|
limit: params.get('$limit'),
|
|
228
235
|
skip: params.get('$skip'),
|
|
229
236
|
distinct: params.get('$distinct'),
|
|
@@ -233,7 +240,10 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
233
240
|
}
|
|
234
241
|
case 'PATCH': {
|
|
235
242
|
if (p.key) {
|
|
236
|
-
|
|
243
|
+
const pick = params.get('$pick');
|
|
244
|
+
const omit = params.get('$omit');
|
|
245
|
+
const include = params.get('$include');
|
|
246
|
+
return new HttpRequestHost({
|
|
237
247
|
kind: 'CollectionUpdateRequest',
|
|
238
248
|
resource,
|
|
239
249
|
operation: 'update',
|
|
@@ -242,13 +252,14 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
242
252
|
args: {
|
|
243
253
|
key: resource.parseKeyValue(p.key),
|
|
244
254
|
data: incoming.body,
|
|
245
|
-
pick: resource.
|
|
246
|
-
omit: resource.
|
|
247
|
-
include: resource.
|
|
255
|
+
pick: pick && resource.normalizeFieldPath(pick),
|
|
256
|
+
omit: omit && resource.normalizeFieldPath(omit),
|
|
257
|
+
include: include && resource.normalizeFieldPath(include),
|
|
248
258
|
}
|
|
249
259
|
}, incoming);
|
|
250
260
|
}
|
|
251
|
-
|
|
261
|
+
const filter = params.get('$filter');
|
|
262
|
+
return new HttpRequestHost({
|
|
252
263
|
kind: 'CollectionUpdateManyRequest',
|
|
253
264
|
resource,
|
|
254
265
|
operation: 'updateMany',
|
|
@@ -256,20 +267,27 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
256
267
|
many: true,
|
|
257
268
|
args: {
|
|
258
269
|
data: incoming.body,
|
|
259
|
-
filter: resource.
|
|
270
|
+
filter: filter && resource.normalizeFilter(filter),
|
|
260
271
|
}
|
|
261
272
|
}, incoming);
|
|
262
273
|
}
|
|
274
|
+
default:
|
|
275
|
+
throw new BadRequestError();
|
|
263
276
|
}
|
|
264
277
|
}
|
|
265
278
|
else
|
|
266
279
|
/*
|
|
267
280
|
* Singleton
|
|
268
281
|
*/
|
|
269
|
-
if (resource instanceof
|
|
282
|
+
if (resource instanceof Singleton) {
|
|
283
|
+
if (p.key)
|
|
284
|
+
throw new BadRequestError();
|
|
270
285
|
switch (method) {
|
|
271
286
|
case 'POST': {
|
|
272
|
-
|
|
287
|
+
const pick = params.get('$pick');
|
|
288
|
+
const omit = params.get('$omit');
|
|
289
|
+
const include = params.get('$include');
|
|
290
|
+
return new HttpRequestHost({
|
|
273
291
|
kind: 'SingletonCreateRequest',
|
|
274
292
|
resource,
|
|
275
293
|
operation: 'create',
|
|
@@ -277,14 +295,14 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
277
295
|
many: false,
|
|
278
296
|
args: {
|
|
279
297
|
data: incoming.body,
|
|
280
|
-
pick: resource.
|
|
281
|
-
omit: resource.
|
|
282
|
-
include: resource.
|
|
298
|
+
pick: pick && resource.normalizeFieldPath(pick),
|
|
299
|
+
omit: omit && resource.normalizeFieldPath(omit),
|
|
300
|
+
include: include && resource.normalizeFieldPath(include),
|
|
283
301
|
}
|
|
284
302
|
}, incoming);
|
|
285
303
|
}
|
|
286
304
|
case 'DELETE': {
|
|
287
|
-
return new
|
|
305
|
+
return new HttpRequestHost({
|
|
288
306
|
kind: 'SingletonDeleteRequest',
|
|
289
307
|
resource,
|
|
290
308
|
operation: 'delete',
|
|
@@ -294,21 +312,27 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
294
312
|
}, incoming);
|
|
295
313
|
}
|
|
296
314
|
case 'GET': {
|
|
297
|
-
|
|
315
|
+
const pick = params.get('$pick');
|
|
316
|
+
const omit = params.get('$omit');
|
|
317
|
+
const include = params.get('$include');
|
|
318
|
+
return new HttpRequestHost({
|
|
298
319
|
kind: 'SingletonGetRequest',
|
|
299
320
|
resource,
|
|
300
321
|
operation: 'get',
|
|
301
322
|
crud: 'read',
|
|
302
323
|
many: false,
|
|
303
324
|
args: {
|
|
304
|
-
pick: resource.
|
|
305
|
-
omit: resource.
|
|
306
|
-
include: resource.
|
|
325
|
+
pick: pick && resource.normalizeFieldPath(pick),
|
|
326
|
+
omit: omit && resource.normalizeFieldPath(omit),
|
|
327
|
+
include: include && resource.normalizeFieldPath(include),
|
|
307
328
|
}
|
|
308
329
|
}, incoming);
|
|
309
330
|
}
|
|
310
331
|
case 'PATCH': {
|
|
311
|
-
|
|
332
|
+
const pick = params.get('$pick');
|
|
333
|
+
const omit = params.get('$omit');
|
|
334
|
+
const include = params.get('$include');
|
|
335
|
+
return new HttpRequestHost({
|
|
312
336
|
kind: 'SingletonUpdateRequest',
|
|
313
337
|
resource,
|
|
314
338
|
operation: 'update',
|
|
@@ -316,16 +340,18 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
316
340
|
many: false,
|
|
317
341
|
args: {
|
|
318
342
|
data: incoming.body,
|
|
319
|
-
pick: resource.
|
|
320
|
-
omit: resource.
|
|
321
|
-
include: resource.
|
|
343
|
+
pick: pick && resource.normalizeFieldPath(pick),
|
|
344
|
+
omit: omit && resource.normalizeFieldPath(omit),
|
|
345
|
+
include: include && resource.normalizeFieldPath(include),
|
|
322
346
|
}
|
|
323
347
|
}, incoming);
|
|
324
348
|
}
|
|
349
|
+
default:
|
|
350
|
+
throw new BadRequestError();
|
|
325
351
|
}
|
|
326
352
|
}
|
|
327
353
|
else
|
|
328
|
-
throw new
|
|
354
|
+
throw new InternalServerError();
|
|
329
355
|
// if (query instanceof SingletonGetQuery || query instanceof CollectionGetQuery || query instanceof ElementReadQuery) {
|
|
330
356
|
// // Move through properties
|
|
331
357
|
// let parentType: DataType;
|
|
@@ -347,14 +373,14 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
347
373
|
// parent = parent.child;
|
|
348
374
|
// }
|
|
349
375
|
// }
|
|
350
|
-
throw new
|
|
376
|
+
throw new MethodNotAllowedError({
|
|
351
377
|
message: `Method "${method}" is not allowed by target endpoint`
|
|
352
378
|
});
|
|
353
379
|
}
|
|
354
380
|
catch (e) {
|
|
355
|
-
if (e instanceof
|
|
381
|
+
if (e instanceof OpraException)
|
|
356
382
|
throw e;
|
|
357
|
-
throw new
|
|
383
|
+
throw new BadRequestError(e);
|
|
358
384
|
}
|
|
359
385
|
}
|
|
360
386
|
// async parseMultiPart(
|
|
@@ -438,23 +464,23 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
438
464
|
async sendResponse(context) {
|
|
439
465
|
const { request, response } = context;
|
|
440
466
|
const outgoing = response.switchToHttp();
|
|
441
|
-
const errors = response.errors?.map(e =>
|
|
467
|
+
const errors = response.errors?.map(e => wrapException(e));
|
|
442
468
|
if (errors && errors.length) {
|
|
443
469
|
await this.errorHandler(request.switchToHttp(), outgoing, errors);
|
|
444
470
|
return;
|
|
445
471
|
}
|
|
446
|
-
outgoing.set(
|
|
447
|
-
outgoing.set(
|
|
448
|
-
outgoing.set(
|
|
449
|
-
outgoing.set(
|
|
450
|
-
outgoing.status(outgoing.statusCode ||
|
|
472
|
+
outgoing.set(HttpHeaderCodes.Cache_Control, 'no-cache');
|
|
473
|
+
outgoing.set(HttpHeaderCodes.Pragma, 'no-cache');
|
|
474
|
+
outgoing.set(HttpHeaderCodes.Expires, '-1');
|
|
475
|
+
outgoing.set(HttpHeaderCodes.X_Opra_Version, OpraSchema.SpecVersion);
|
|
476
|
+
outgoing.status(outgoing.statusCode || HttpStatusCodes.OK);
|
|
451
477
|
if (response.value) {
|
|
452
478
|
if (typeof response.value === 'object') {
|
|
453
|
-
if (
|
|
479
|
+
if (isReadable(response.value) || Buffer.isBuffer(response.value))
|
|
454
480
|
outgoing.send(response.value);
|
|
455
481
|
else {
|
|
456
482
|
const body = this.i18n.deep(response.value);
|
|
457
|
-
outgoing.set(
|
|
483
|
+
outgoing.set(HttpHeaderCodes.Content_Type, 'application/json; charset=utf-8');
|
|
458
484
|
outgoing.send(JSON.stringify(body));
|
|
459
485
|
}
|
|
460
486
|
}
|
|
@@ -464,4 +490,3 @@ class OpraHttpAdapter extends adapter_js_1.OpraAdapter {
|
|
|
464
490
|
outgoing.end();
|
|
465
491
|
}
|
|
466
492
|
}
|
|
467
|
-
exports.OpraHttpAdapter = OpraHttpAdapter;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.HttpRequestContextHost = void 0;
|
|
4
|
-
const request_context_host_js_1 = require("../request-context.host.js");
|
|
5
|
-
class HttpRequestContextHost extends request_context_host_js_1.RequestContextHost {
|
|
1
|
+
import { RequestContextHost } from '../request-context.host.js';
|
|
2
|
+
export class HttpRequestContextHost extends RequestContextHost {
|
|
6
3
|
constructor(platform, api, _request, _response) {
|
|
7
4
|
super('http', platform, api, _request, _response);
|
|
8
5
|
this.platform = platform;
|
|
@@ -25,4 +22,3 @@ class HttpRequestContextHost extends request_context_host_js_1.RequestContextHos
|
|
|
25
22
|
throw new TypeError('Not executing in an "RPC" protocol');
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
|
-
exports.HttpRequestContextHost = HttpRequestContextHost;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.HttpRequestHost = void 0;
|
|
4
|
-
const request_host_js_1 = require("../request.host.js");
|
|
5
|
-
class HttpRequestHost extends request_host_js_1.RequestHost {
|
|
1
|
+
import { RequestHost } from '../request.host.js';
|
|
2
|
+
export class HttpRequestHost extends RequestHost {
|
|
6
3
|
constructor(init, _incoming) {
|
|
7
4
|
super(init);
|
|
8
5
|
this._incoming = _incoming;
|
|
@@ -11,4 +8,3 @@ class HttpRequestHost extends request_host_js_1.RequestHost {
|
|
|
11
8
|
return this._incoming;
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
|
-
exports.HttpRequestHost = HttpRequestHost;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.HttpResponseHost = void 0;
|
|
4
|
-
const response_host_js_1 = require("../response.host.js");
|
|
5
|
-
class HttpResponseHost extends response_host_js_1.ResponseHost {
|
|
1
|
+
import { ResponseHost } from '../response.host.js';
|
|
2
|
+
export class HttpResponseHost extends ResponseHost {
|
|
6
3
|
constructor(init, _outgoing) {
|
|
7
4
|
super(init);
|
|
8
5
|
this._outgoing = _outgoing;
|
|
@@ -11,4 +8,3 @@ class HttpResponseHost extends response_host_js_1.ResponseHost {
|
|
|
11
8
|
return this._outgoing;
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
|
-
exports.HttpResponseHost = HttpResponseHost;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.MetadataResource = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@opra/common");
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { ApiDocument, cloneObject, Singleton } from '@opra/common';
|
|
6
3
|
let MetadataResource = class MetadataResource {
|
|
7
4
|
constructor(document) {
|
|
8
5
|
this.document = document;
|
|
9
6
|
this._schema = document.exportSchema();
|
|
10
7
|
}
|
|
11
8
|
get() {
|
|
12
|
-
return
|
|
9
|
+
return cloneObject(this.document.exportSchema(), true);
|
|
13
10
|
}
|
|
14
11
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
__decorate([
|
|
13
|
+
Singleton.Get(),
|
|
14
|
+
__metadata("design:type", Function),
|
|
15
|
+
__metadata("design:paramtypes", []),
|
|
16
|
+
__metadata("design:returntype", void 0)
|
|
20
17
|
], MetadataResource.prototype, "get", null);
|
|
21
|
-
MetadataResource =
|
|
22
|
-
|
|
18
|
+
MetadataResource = __decorate([
|
|
19
|
+
Singleton(Object, {
|
|
23
20
|
name: '$metadata',
|
|
24
21
|
}),
|
|
25
|
-
|
|
22
|
+
__metadata("design:paramtypes", [ApiDocument])
|
|
26
23
|
], MetadataResource);
|
|
27
|
-
|
|
24
|
+
export { MetadataResource };
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.RequestContextHost = void 0;
|
|
4
|
-
const strict_typed_events_1 = require("strict-typed-events");
|
|
5
|
-
class RequestContextHost extends strict_typed_events_1.AsyncEventEmitter {
|
|
1
|
+
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
2
|
+
export class RequestContextHost extends AsyncEventEmitter {
|
|
6
3
|
constructor(protocol, platform, api, _request, _response) {
|
|
7
4
|
super();
|
|
8
5
|
this.protocol = protocol;
|
|
@@ -27,4 +24,3 @@ class RequestContextHost extends strict_typed_events_1.AsyncEventEmitter {
|
|
|
27
24
|
throw new TypeError('Not executing in an "RPC" protocol');
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
|
-
exports.RequestContextHost = RequestContextHost;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RequestHost = void 0;
|
|
4
|
-
class RequestHost {
|
|
1
|
+
export class RequestHost {
|
|
5
2
|
constructor(init) {
|
|
6
3
|
Object.assign(this, init);
|
|
7
4
|
this.resourceKind = this.resource.kind;
|
|
@@ -16,4 +13,3 @@ class RequestHost {
|
|
|
16
13
|
throw new TypeError('Not executing in an "RPC" protocol');
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.RequestHost = RequestHost;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResponseHost = void 0;
|
|
4
|
-
class ResponseHost {
|
|
1
|
+
export class ResponseHost {
|
|
5
2
|
constructor(init) {
|
|
6
3
|
if (init)
|
|
7
4
|
Object.assign(this, init);
|
|
@@ -17,4 +14,3 @@ class ResponseHost {
|
|
|
17
14
|
throw new TypeError('Not executing in an "RPC" protocol');
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
|
-
exports.ResponseHost = ResponseHost;
|
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const common_1 = require("@opra/common");
|
|
1
|
+
import { Collection, METADATA_KEY, Resource, Singleton } from "@opra/common";
|
|
4
2
|
// @ts-ignore
|
|
5
|
-
const oldConstruct =
|
|
3
|
+
const oldConstruct = Resource.prototype._construct;
|
|
6
4
|
// @ts-ignore
|
|
7
|
-
|
|
5
|
+
Resource.prototype._construct = function (init) {
|
|
8
6
|
oldConstruct.call(this, init);
|
|
9
7
|
const _this = this;
|
|
10
8
|
_this.onInit = init.onInit;
|
|
11
9
|
_this.onShutdown = init.onShutdown;
|
|
12
10
|
};
|
|
13
|
-
|
|
11
|
+
Collection.OnInit = Singleton.OnInit = function () {
|
|
14
12
|
return (target, propertyKey) => {
|
|
15
|
-
const resourceMetadata = (Reflect.getOwnMetadata(
|
|
13
|
+
const resourceMetadata = (Reflect.getOwnMetadata(METADATA_KEY, target.constructor) || {});
|
|
16
14
|
resourceMetadata.onInit = target[propertyKey];
|
|
17
|
-
Reflect.defineMetadata(
|
|
15
|
+
Reflect.defineMetadata(METADATA_KEY, target.constructor, resourceMetadata);
|
|
18
16
|
};
|
|
19
17
|
};
|
|
20
|
-
|
|
18
|
+
Collection.OnShutdown = Singleton.OnShutdown = function () {
|
|
21
19
|
return (target, propertyKey) => {
|
|
22
|
-
const resourceMetadata = (Reflect.getOwnMetadata(
|
|
20
|
+
const resourceMetadata = (Reflect.getOwnMetadata(METADATA_KEY, target.constructor) || {});
|
|
23
21
|
resourceMetadata.onShutdown = target[propertyKey];
|
|
24
|
-
Reflect.defineMetadata(
|
|
22
|
+
Reflect.defineMetadata(METADATA_KEY, target.constructor, resourceMetadata);
|
|
25
23
|
};
|
|
26
24
|
};
|
package/esm/index.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
tslib_1.__exportStar(require("./adapter/interfaces/logger.interface.js"), exports);
|
|
12
|
-
tslib_1.__exportStar(require("./adapter/interfaces/request.interface.js"), exports);
|
|
13
|
-
tslib_1.__exportStar(require("./adapter/interfaces/response.interface.js"), exports);
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import './augmentation/resource.augmentation.js';
|
|
3
|
+
export * from './types.js';
|
|
4
|
+
export * from './adapter/adapter.js';
|
|
5
|
+
export * from './adapter/http/express-adapter.js';
|
|
6
|
+
export * from './adapter/http/http-adapter.js';
|
|
7
|
+
export * from './adapter/interfaces/request-context.interface.js';
|
|
8
|
+
export * from './adapter/interfaces/logger.interface.js';
|
|
9
|
+
export * from './adapter/interfaces/request.interface.js';
|
|
10
|
+
export * from './adapter/interfaces/response.interface.js';
|
package/esm/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"clean:cover": "rimraf ../../coverage/core"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@opra/common": "^0.
|
|
30
|
+
"@opra/common": "^0.17.0",
|
|
31
31
|
"content-type": "^1.0.5",
|
|
32
32
|
"lodash.isnil": "^4.0.0",
|
|
33
33
|
"lodash.omitby": "^4.6.0",
|