@opra/core 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.
Files changed (98) hide show
  1. package/cjs/adapter/adapter.js +88 -294
  2. package/cjs/adapter/http/express-adapter.js +27 -0
  3. package/cjs/adapter/http/http-adapter.js +466 -0
  4. package/cjs/adapter/http/http-request-context.host.js +28 -0
  5. package/cjs/adapter/http/http-request.host.js +14 -0
  6. package/cjs/adapter/http/http-response.host.js +14 -0
  7. package/cjs/adapter/internal/metadata.resource.js +27 -0
  8. package/cjs/adapter/request-context.host.js +30 -0
  9. package/cjs/adapter/request.host.js +19 -0
  10. package/cjs/adapter/response.host.js +20 -0
  11. package/cjs/augmentation/resource.augmentation.js +26 -0
  12. package/cjs/index.js +7 -8
  13. package/esm/adapter/adapter.d.ts +52 -28
  14. package/esm/adapter/adapter.js +88 -295
  15. package/esm/adapter/http/express-adapter.d.ts +11 -0
  16. package/esm/adapter/http/express-adapter.js +22 -0
  17. package/esm/adapter/http/http-adapter.d.ts +37 -0
  18. package/esm/adapter/http/http-adapter.js +462 -0
  19. package/esm/adapter/http/http-request-context.host.d.ts +16 -0
  20. package/esm/adapter/http/http-request-context.host.js +24 -0
  21. package/esm/adapter/http/http-request.host.d.ts +7 -0
  22. package/esm/adapter/http/http-request.host.js +10 -0
  23. package/esm/adapter/http/http-response.host.d.ts +7 -0
  24. package/esm/adapter/http/http-response.host.js +10 -0
  25. package/esm/{interfaces → adapter/interfaces}/logger.interface.d.ts +1 -0
  26. package/esm/adapter/interfaces/request-context.interface.d.ts +25 -0
  27. package/esm/adapter/interfaces/request.interface.d.ts +13 -0
  28. package/esm/adapter/interfaces/response.interface.d.ts +22 -0
  29. package/esm/adapter/internal/metadata.resource.d.ts +7 -0
  30. package/esm/adapter/internal/metadata.resource.js +24 -0
  31. package/esm/adapter/request-context.host.d.ts +19 -0
  32. package/esm/adapter/request-context.host.js +26 -0
  33. package/esm/adapter/request.host.d.ts +26 -0
  34. package/esm/adapter/request.host.js +15 -0
  35. package/esm/adapter/response.host.d.ts +20 -0
  36. package/esm/adapter/response.host.js +16 -0
  37. package/esm/augmentation/resource.augmentation.d.ts +33 -0
  38. package/esm/augmentation/resource.augmentation.js +24 -0
  39. package/esm/index.d.ts +7 -8
  40. package/esm/index.js +7 -8
  41. package/i18n/en/error.json +1 -1
  42. package/package.json +9 -7
  43. package/cjs/adapter/classes/execution-context.host.js +0 -16
  44. package/cjs/adapter/classes/express-request-wrapper.host.js +0 -36
  45. package/cjs/adapter/classes/express-response-wrapper.host.js +0 -55
  46. package/cjs/adapter/classes/http-execution-context.host.js +0 -28
  47. package/cjs/adapter/classes/metadata.resource.js +0 -22
  48. package/cjs/adapter/express-adapter.js +0 -26
  49. package/cjs/adapter/http-adapter.js +0 -443
  50. package/cjs/adapter/request-contexts/batch-request-context.js +0 -11
  51. package/cjs/adapter/request-contexts/request-context.js +0 -25
  52. package/cjs/adapter/request-contexts/single-request-context.js +0 -14
  53. package/cjs/interfaces/resource.interface.js +0 -2
  54. package/cjs/services/data-service.js +0 -9
  55. package/cjs/services/json-singleton-service.js +0 -96
  56. package/cjs/utils/create-i18n.js +0 -21
  57. package/cjs/utils/get-caller-file.util.js +0 -24
  58. package/esm/adapter/classes/execution-context.host.d.ts +0 -10
  59. package/esm/adapter/classes/execution-context.host.js +0 -12
  60. package/esm/adapter/classes/express-request-wrapper.host.d.ts +0 -19
  61. package/esm/adapter/classes/express-request-wrapper.host.js +0 -32
  62. package/esm/adapter/classes/express-response-wrapper.host.d.ts +0 -22
  63. package/esm/adapter/classes/express-response-wrapper.host.js +0 -51
  64. package/esm/adapter/classes/http-execution-context.host.d.ts +0 -13
  65. package/esm/adapter/classes/http-execution-context.host.js +0 -24
  66. package/esm/adapter/classes/metadata.resource.d.ts +0 -8
  67. package/esm/adapter/classes/metadata.resource.js +0 -19
  68. package/esm/adapter/express-adapter.d.ts +0 -11
  69. package/esm/adapter/express-adapter.js +0 -21
  70. package/esm/adapter/http-adapter.d.ts +0 -37
  71. package/esm/adapter/http-adapter.js +0 -439
  72. package/esm/adapter/request-contexts/batch-request-context.d.ts +0 -7
  73. package/esm/adapter/request-contexts/batch-request-context.js +0 -7
  74. package/esm/adapter/request-contexts/request-context.d.ts +0 -22
  75. package/esm/adapter/request-contexts/request-context.js +0 -21
  76. package/esm/adapter/request-contexts/single-request-context.d.ts +0 -10
  77. package/esm/adapter/request-contexts/single-request-context.js +0 -10
  78. package/esm/enums/issue-severity.enum.d.ts +0 -1
  79. package/esm/interfaces/execution-context.interface.d.ts +0 -47
  80. package/esm/interfaces/i18n-options.interface.d.ts +0 -28
  81. package/esm/interfaces/resource.interface.d.ts +0 -23
  82. package/esm/interfaces/resource.interface.js +0 -1
  83. package/esm/services/data-service.d.ts +0 -2
  84. package/esm/services/data-service.js +0 -5
  85. package/esm/services/json-singleton-service.d.ts +0 -39
  86. package/esm/services/json-singleton-service.js +0 -91
  87. package/esm/utils/create-i18n.d.ts +0 -3
  88. package/esm/utils/create-i18n.js +0 -16
  89. package/esm/utils/get-caller-file.util.d.ts +0 -1
  90. package/esm/utils/get-caller-file.util.js +0 -20
  91. /package/cjs/{interfaces → adapter/interfaces}/logger.interface.js +0 -0
  92. /package/cjs/{enums/issue-severity.enum.js → adapter/interfaces/request-context.interface.js} +0 -0
  93. /package/cjs/{interfaces/execution-context.interface.js → adapter/interfaces/request.interface.js} +0 -0
  94. /package/cjs/{interfaces/i18n-options.interface.js → adapter/interfaces/response.interface.js} +0 -0
  95. /package/esm/{interfaces → adapter/interfaces}/logger.interface.js +0 -0
  96. /package/esm/{enums/issue-severity.enum.js → adapter/interfaces/request-context.interface.js} +0 -0
  97. /package/esm/{interfaces/execution-context.interface.js → adapter/interfaces/request.interface.js} +0 -0
  98. /package/esm/{interfaces/i18n-options.interface.js → adapter/interfaces/response.interface.js} +0 -0
@@ -1,439 +0,0 @@
1
- import { BadRequestError, CollectionCreateQuery, CollectionDeleteManyQuery, CollectionDeleteQuery, CollectionGetQuery, CollectionResourceInfo, CollectionSearchQuery, CollectionUpdateManyQuery, CollectionUpdateQuery, ComplexType, ContainerResourceInfo, FieldGetQuery, HttpHeaderCodes, HttpStatusCodes, InternalServerError, isReadable, IssueSeverity, MethodNotAllowedError, normalizeHeaders, OpraException, OpraSchema, OpraURL, SingletonGetQuery, SingletonResourceInfo, UnionType, wrapException } from '@opra/common';
2
- import { OpraAdapter } from './adapter.js';
3
- import { SingleRequestContext } from './request-contexts/single-request-context.js';
4
- export class OpraHttpAdapter extends OpraAdapter {
5
- async parse(executionContext) {
6
- const req = executionContext.getRequest();
7
- const contentType = req.getHeader('content-type');
8
- if (!contentType || contentType === 'application/json') {
9
- const body = req.getBody();
10
- const url = new OpraURL(req.getUrl());
11
- return this.parseSingleQuery({
12
- executionContext,
13
- url,
14
- method: req.getMethod(),
15
- headers: req.getHeaders(),
16
- body
17
- });
18
- }
19
- if (typeof contentType === 'string' && contentType.startsWith('multipart/mixed')) {
20
- // const m = BOUNDARY_PATTERN.exec(contentType);
21
- // if (!m)
22
- // throw new BadRequestError({message: 'Content-Type header does not match required format'});
23
- // const url = new OpraURL(req.getUrl());
24
- // return await this.parseMultiPart(executionContext, url, req.getHeaders(), req.getStream(), m[1]);
25
- }
26
- throw new BadRequestError({ message: 'Unsupported Content-Type' });
27
- }
28
- parseSingleQuery(args) {
29
- const { executionContext, url, method, headers, body, contentId } = args;
30
- if (!url.path.size)
31
- throw new BadRequestError();
32
- if (method !== 'GET' && url.path.size > 1)
33
- throw new BadRequestError();
34
- const query = this.buildQuery(url, method, body);
35
- if (!query)
36
- throw new MethodNotAllowedError({
37
- message: `Method "${method}" is not allowed by target endpoint`
38
- });
39
- return new SingleRequestContext({
40
- service: this.document,
41
- executionContext,
42
- headers,
43
- query,
44
- params: url.searchParams,
45
- contentId,
46
- continueOnError: query.operation === 'read'
47
- });
48
- }
49
- // async parseMultiPart(
50
- // executionContext: TExecutionContext,
51
- // url: OpraURL,
52
- // headers: IncomingHttpHeaders,
53
- // input: Readable,
54
- // boundary: string
55
- // ): Promise<BatchRequestContext> {
56
- // return await new Promise((resolve, reject) => {
57
- // let _resolved = false;
58
- // const dicer = new Dicer({boundary});
59
- // const doReject = (e) => {
60
- // if (_resolved) return;
61
- // _resolved = true;
62
- // reject(e);
63
- // taskQueue.clearQueue();
64
- // dicer.destroy();
65
- // }
66
- // const taskQueue = new TaskQueue({concurrency: 1});
67
- // taskQueue.on('error', doReject);
68
- //
69
- // const queries: SingleRequestContext[] = [];
70
- // let partCounter = 0;
71
- // dicer.on('error', doReject);
72
- // dicer.on('part', part => {
73
- // const partIndex = partCounter++;
74
- // let header: any;
75
- // const chunks: Buffer[] = [];
76
- // part.on('error', doReject);
77
- // part.on('header', (_header) => header = normalizeHeaders(_header));
78
- // part.on('data', (chunk: Buffer) => chunks.push(chunk));
79
- // part.on('end', () => {
80
- // if (_resolved || !(header || chunks.length))
81
- // return;
82
- // const ct = header['content-type'];
83
- // if (ct === 'application/http') {
84
- // taskQueue.enqueue(async () => {
85
- // const data = Buffer.concat(chunks);
86
- // if (!(data && data.length))
87
- // return;
88
- // const r = HttpRequest.parse(data);
89
- // await callMiddlewares(r, [jsonBodyParser]);
90
- // const subUrl = new OpraURL(r.url);
91
- // const contentId = header && header['content-id'];
92
- // queries.push(this.parseSingleQuery({
93
- // executionContext,
94
- // url: subUrl,
95
- // method: r.method,
96
- // headers: r.headers,
97
- // body: r.body,
98
- // contentId
99
- // }));
100
- // });
101
- // } else doReject(new BadRequestError({
102
- // message: 'Unaccepted "content-type" header in multipart data',
103
- // details: {
104
- // position: `${boundary}[${partIndex}]`
105
- // }
106
- // }))
107
- // });
108
- // });
109
- // dicer.on('finish', () => {
110
- // taskQueue.enqueue(() => {
111
- // if (_resolved) return;
112
- // _resolved = true;
113
- // const batch = new BatchRequestContext({
114
- // service: this.document,
115
- // executionContext,
116
- // headers,
117
- // queries,
118
- // params: url.searchParams,
119
- // continueOnError: false
120
- // });
121
- // resolve(batch);
122
- // });
123
- // });
124
- // input.pipe(dicer);
125
- // });
126
- // }
127
- buildQuery(url, method, body) {
128
- const pathLen = url.path.size;
129
- let p = url.path.get(0);
130
- let resource = this._internalResources.get(p.resource) || this.document.getResource(p.resource);
131
- let container;
132
- let pathIndex = 0;
133
- while (resource && resource instanceof ContainerResourceInfo) {
134
- container = resource;
135
- p = url.path.get(++pathIndex);
136
- resource = container.getResource(p.resource);
137
- }
138
- try {
139
- method = method.toUpperCase();
140
- let query;
141
- if (resource instanceof SingletonResourceInfo && !p.key) {
142
- switch (method) {
143
- case 'GET': {
144
- const searchParams = url.searchParams;
145
- query = new SingletonGetQuery(resource, {
146
- pick: searchParams.get('$pick'),
147
- omit: searchParams.get('$omit'),
148
- include: searchParams.get('$include')
149
- });
150
- }
151
- }
152
- }
153
- else if (resource instanceof CollectionResourceInfo) {
154
- switch (method) {
155
- case 'GET': {
156
- if (p.key) {
157
- const searchParams = url.searchParams;
158
- query = new CollectionGetQuery(resource, p.key, {
159
- pick: searchParams.get('$pick'),
160
- omit: searchParams.get('$omit'),
161
- include: searchParams.get('$include')
162
- });
163
- }
164
- else {
165
- const searchParams = url.searchParams;
166
- query = new CollectionSearchQuery(resource, {
167
- filter: searchParams.get('$filter'),
168
- limit: searchParams.get('$limit'),
169
- skip: searchParams.get('$skip'),
170
- distinct: searchParams.get('$distinct'),
171
- count: searchParams.get('$count'),
172
- sort: searchParams.get('$sort'),
173
- pick: searchParams.get('$pick'),
174
- omit: searchParams.get('$omit'),
175
- include: searchParams.get('$include')
176
- });
177
- }
178
- break;
179
- }
180
- case 'DELETE': {
181
- const searchParams = url.searchParams;
182
- query = p.key
183
- ? new CollectionDeleteQuery(resource, p.key)
184
- : new CollectionDeleteManyQuery(resource, {
185
- filter: searchParams.get('$filter'),
186
- });
187
- break;
188
- }
189
- case 'POST': {
190
- if (!p.key) {
191
- const searchParams = url.searchParams;
192
- query = new CollectionCreateQuery(resource, body, {
193
- pick: searchParams.get('$pick'),
194
- omit: searchParams.get('$omit'),
195
- include: searchParams.get('$include')
196
- });
197
- }
198
- break;
199
- }
200
- case 'PATCH': {
201
- if (p.key) {
202
- const searchParams = url.searchParams;
203
- query = new CollectionUpdateQuery(resource, p.key, body, {
204
- pick: searchParams.get('$pick'),
205
- omit: searchParams.get('$omit'),
206
- include: searchParams.get('$include')
207
- });
208
- }
209
- else {
210
- const searchParams = url.searchParams;
211
- query = new CollectionUpdateManyQuery(resource, body, {
212
- filter: searchParams.get('$filter')
213
- });
214
- }
215
- break;
216
- }
217
- }
218
- }
219
- else
220
- throw new InternalServerError();
221
- if (query instanceof SingletonGetQuery || query instanceof CollectionGetQuery || query instanceof FieldGetQuery) {
222
- // Move through properties
223
- let parentType;
224
- const curPath = [];
225
- let parent = query;
226
- while (++pathIndex < pathLen) {
227
- p = url.path.get(pathIndex);
228
- parentType = parent.dataType;
229
- if (parent.dataType instanceof UnionType) {
230
- if (parent.dataType.name === 'any')
231
- parentType = this.document.getComplexDataType('object');
232
- else
233
- throw new TypeError(`"${resource.name}.${curPath.join()}" is a UnionType and needs type casting.`);
234
- }
235
- if (!(parentType instanceof ComplexType))
236
- throw new TypeError(`"${resource.name}.${curPath.join()}" is not a ComplexType and has no fields.`);
237
- curPath.push(p.resource);
238
- parent.child = new FieldGetQuery(parent, p.resource, { castingType: parentType });
239
- parent = parent.child;
240
- }
241
- }
242
- return query;
243
- }
244
- catch (e) {
245
- if (e instanceof OpraException)
246
- throw e;
247
- throw new BadRequestError(e);
248
- }
249
- }
250
- async sendResponse(executionContext, requestContext) {
251
- // if (requestContext instanceof BatchRequestContext)
252
- // return this.sendBatchResponse(executionContext, requestContext);
253
- if (requestContext instanceof SingleRequestContext)
254
- return this.sendSingleResponse(executionContext, requestContext);
255
- /* istanbul ignore next */
256
- throw new TypeError('Invalid request context instance');
257
- }
258
- // protected async sendBatchResponse(executionContext: TExecutionContext, requestContext: BatchRequestContext) {
259
- // const resp = executionContext.getResponse();
260
- // resp.setStatus(HttpStatus.OK);
261
- // resp.setHeader(HttpHeaderCodes.Cache_Control, 'no-cache');
262
- // resp.setHeader(HttpHeaderCodes.Pragma, 'no-cache');
263
- // resp.setHeader(HttpHeaderCodes.Expires, '-1');
264
- // if (requestContext.headers) {
265
- // for (const [k, v] of Object.entries(requestContext.headers)) {
266
- // if (v)
267
- // resp.setHeader(k, v);
268
- // }
269
- // }
270
- // const boundary = 'batch_' + uuid();
271
- // resp.setHeader(HttpHeaderCodes.Content_Type, 'multipart/mixed;boundary=' + boundary);
272
- // resp.setHeader(HttpHeaderCodes.X_Opra_Version, OpraSchema.Version);
273
- //
274
- // const bodyBuilder = new HttpMultipartData();
275
- //
276
- // const chunks: any[] = [];
277
- // let msgIdx = 0;
278
- // for (const ctx of requestContext.queries) {
279
- // msgIdx++;
280
- // const out = this.createOutput(ctx);
281
- //
282
- //
283
- // // chunks.push('--' + boundary + CRLF);
284
- // // let s = 'Content-Type: application/http' + CRLF +
285
- // // 'Content-Transfer-Encoding: binary' + CRLF +
286
- // // 'Content-ID:' + (ctx.contentId || msgIdx) + CRLF +
287
- // // CRLF +
288
- // // 'HTTP/1.1 ' + out.status + (HttpStatus[out.status] || 'Unknown') + CRLF;
289
- //
290
- // let body = out.body;
291
- // const headers = out.headers || {};
292
- // if (body) {
293
- // const contentType = String(headers['content-type'] || '').split(/\s*;\s*/);
294
- // let charset = '';
295
- // if (Highland.isStream(body)) {
296
- // const l = parseInt(String(headers['content-length']), 10);
297
- // if (isNaN(l))
298
- // throw new TypeError('"content-length" header required for streamed responses');
299
- // } else if (typeof body === 'object') {
300
- // if (typeof body.stream === 'function') { // File and Blob
301
- // contentType[0] = body.type || 'binary';
302
- // headers['content-length'] = String(body.size);
303
- // body = body.stream();
304
- // } else if (Buffer.isBuffer(body)) {
305
- // headers['content-length'] = String(body.length);
306
- // } else {
307
- // contentType[0] = contentType[0] || 'application/json';
308
- // charset = 'utf-8';
309
- // body = Buffer.from(JSON.stringify(body), 'utf-8');
310
- // headers['content-length'] = String(body.length);
311
- // }
312
- // } else {
313
- // contentType[0] = contentType[0] || 'text/plain';
314
- // charset = 'utf-8';
315
- // body = Buffer.from(String(body), 'utf-8');
316
- // headers['content-length'] = String(body.length);
317
- // }
318
- // if (contentType[0]) {
319
- // if (charset) {
320
- // const i = contentType.findIndex(x => CHARSET_PATTERN.test(String(x)));
321
- // if (i > 0) contentType[i] = 'charset=' + charset;
322
- // else contentType.join('charset=' + charset);
323
- // }
324
- // headers['content-type'] = contentType.join(';');
325
- // }
326
- // }
327
- // for (const [k, v] of Object.entries(headers))
328
- // s += k + ': ' + (Array.isArray(v) ? v.join(';') : v) + CRLF
329
- //
330
- // chunks.push(s + CRLF);
331
- //
332
- // if (body) {
333
- // if (typeof body === 'string')
334
- // chunks.push(body + CRLF + CRLF);
335
- // else {
336
- // chunks.push(body);
337
- // chunks.push(CRLF + CRLF);
338
- // }
339
- // }
340
- // }
341
- //
342
- // chunks.push('--' + boundary + '--' + CRLF);
343
- //
344
- // resp.setHeader('content-type', 'multipart/mixed;boundary=' + boundary);
345
- // resp.send(Highland(chunks).flatten());
346
- // resp.end();
347
- // }
348
- async sendSingleResponse(executionContext, requestContext) {
349
- const out = this.createOutput(requestContext);
350
- const resp = executionContext.getResponse();
351
- resp.setStatus(out.status);
352
- resp.setHeader(HttpHeaderCodes.Cache_Control, 'no-cache');
353
- resp.setHeader(HttpHeaderCodes.Pragma, 'no-cache');
354
- resp.setHeader(HttpHeaderCodes.Expires, '-1');
355
- if (out.headers) {
356
- for (const [k, v] of Object.entries(out.headers)) {
357
- if (v)
358
- resp.setHeader(k, v);
359
- }
360
- }
361
- resp.setHeader(HttpHeaderCodes.X_Opra_Version, OpraSchema.Version);
362
- if (out.body)
363
- resp.send(out.body);
364
- resp.end();
365
- }
366
- createOutput(ctx) {
367
- const { query } = ctx;
368
- let body;
369
- let status = ctx.status || 0;
370
- const errors = ctx.errors.map(e => wrapException(e));
371
- if (errors && errors.length) {
372
- // Sort errors from fatal to info
373
- errors.sort((a, b) => {
374
- const i = IssueSeverity.Keys.indexOf(a.issue.severity) - IssueSeverity.Keys.indexOf(b.issue.severity);
375
- if (i === 0)
376
- return b.status - a.status;
377
- return i;
378
- });
379
- if (!status || status < HttpStatusCodes.BAD_REQUEST) {
380
- status = errors[0].status;
381
- if (status < HttpStatusCodes.BAD_REQUEST)
382
- status = HttpStatusCodes.INTERNAL_SERVER_ERROR;
383
- }
384
- body = this.i18n.deep({
385
- operation: ctx.query.method,
386
- errors: errors.map(e => e.issue)
387
- });
388
- body = JSON.stringify(body);
389
- ctx.responseHeaders['content-type'] = 'application/json; charset=utf-8';
390
- }
391
- else {
392
- if (typeof ctx.response === 'object' && !(isReadable(ctx.response) || Buffer.isBuffer(ctx.response))) {
393
- body = this.i18n.deep(ctx.response);
394
- body = JSON.stringify(body);
395
- ctx.responseHeaders['content-type'] = 'application/json; charset=utf-8';
396
- }
397
- status = status || (query.operation === 'create' ? HttpStatusCodes.CREATED : HttpStatusCodes.OK);
398
- }
399
- return {
400
- status,
401
- headers: normalizeHeaders(ctx.responseHeaders),
402
- body
403
- };
404
- }
405
- async sendError(executionContext, error) {
406
- const resp = executionContext.getResponse();
407
- resp.setStatus(error.status || 500);
408
- resp.setHeader(HttpHeaderCodes.Content_Type, 'application/json');
409
- resp.setHeader(HttpHeaderCodes.Cache_Control, 'no-cache');
410
- resp.setHeader(HttpHeaderCodes.Pragma, 'no-cache');
411
- resp.setHeader(HttpHeaderCodes.Expires, '-1');
412
- resp.setHeader(HttpHeaderCodes.X_Opra_Version, OpraSchema.Version);
413
- const issue = this.i18n.deep(error.issue);
414
- const body = {
415
- operation: 'unknown',
416
- errors: [issue]
417
- };
418
- resp.send(JSON.stringify(body));
419
- }
420
- }
421
- // async function callMiddlewares(req: HttpRequest, middlewares: NextHandleFunction[]): Promise<void> {
422
- // return new Promise<void>((resolve, reject) => {
423
- // let i = 0;
424
- // const next = (err?: any) => {
425
- // if (err)
426
- // return reject(err);
427
- // const fn = middlewares[i++];
428
- // if (!fn)
429
- // return resolve();
430
- // try {
431
- // fn(req as any, {} as any, next);
432
- // } catch (e) {
433
- // reject(e);
434
- // }
435
- // }
436
- // next();
437
- // });
438
- //
439
- // }
@@ -1,7 +0,0 @@
1
- import { RequestContext, RequestContextArgs } from './request-context.js';
2
- import { SingleRequestContext } from './single-request-context.js';
3
- export type BatchContextArgs = RequestContextArgs & Pick<BatchRequestContext, 'queries'>;
4
- export declare class BatchRequestContext extends RequestContext {
5
- readonly queries: SingleRequestContext[];
6
- constructor(args: BatchContextArgs);
7
- }
@@ -1,7 +0,0 @@
1
- import { RequestContext } from './request-context.js';
2
- export class BatchRequestContext extends RequestContext {
3
- constructor(args) {
4
- super(args);
5
- this.queries = args.queries;
6
- }
7
- }
@@ -1,22 +0,0 @@
1
- /// <reference types="node" />
2
- import { IncomingHttpHeaders } from 'http';
3
- import { HttpStatusCodes, OpraDocument, OpraException, OpraURLSearchParams } from '@opra/common';
4
- import { ContextType, IExecutionContext, IHttpExecutionContext } from '../../interfaces/execution-context.interface.js';
5
- export type RequestContextArgs = Pick<RequestContext, 'contentId' | 'service' | 'executionContext' | 'params' | 'headers' | 'parentValue' | 'continueOnError'>;
6
- export declare class RequestContext {
7
- readonly service: OpraDocument;
8
- readonly executionContext: IExecutionContext;
9
- readonly params: OpraURLSearchParams;
10
- readonly headers: IncomingHttpHeaders;
11
- readonly contentId?: string;
12
- readonly parentValue?: any;
13
- readonly resultPath: string;
14
- readonly responseHeaders: IncomingHttpHeaders;
15
- response?: any;
16
- errors: OpraException[];
17
- status?: HttpStatusCodes;
18
- continueOnError?: boolean;
19
- constructor(args: RequestContextArgs);
20
- get type(): ContextType;
21
- switchToHttp(): IHttpExecutionContext;
22
- }
@@ -1,21 +0,0 @@
1
- import { OpraURLSearchParams } from '@opra/common';
2
- export class RequestContext {
3
- constructor(args) {
4
- this.errors = [];
5
- this.service = args.service;
6
- this.executionContext = args.executionContext;
7
- this.params = this.params || new OpraURLSearchParams();
8
- this.headers = args.headers;
9
- this.contentId = args.contentId;
10
- this.responseHeaders = {};
11
- this.resultPath = this.resultPath || '';
12
- }
13
- get type() {
14
- return this.executionContext.getType();
15
- }
16
- switchToHttp() {
17
- if (this.type !== 'http')
18
- throw new Error(`You can't access http context within an ${this.type} context`);
19
- return this.executionContext;
20
- }
21
- }
@@ -1,10 +0,0 @@
1
- import { OpraQuery } from '@opra/common';
2
- import { RequestContext, RequestContextArgs } from './request-context.js';
3
- export type QueryRequestContextArgs = RequestContextArgs & {
4
- readonly query: OpraQuery;
5
- };
6
- export declare class SingleRequestContext extends RequestContext {
7
- readonly query: OpraQuery;
8
- constructor(args: QueryRequestContextArgs);
9
- get userContext(): any;
10
- }
@@ -1,10 +0,0 @@
1
- import { RequestContext } from './request-context.js';
2
- export class SingleRequestContext extends RequestContext {
3
- constructor(args) {
4
- super(args);
5
- this.query = args.query;
6
- }
7
- get userContext() {
8
- return this.executionContext.userContext;
9
- }
10
- }
@@ -1 +0,0 @@
1
- export type IssueSeverity = 'error' | 'fatal' | 'warning' | 'info';
@@ -1,47 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
4
- import { Readable, Writable } from 'stream';
5
- export type ContextType = 'http' | 'ws' | 'rpc';
6
- export declare namespace IExecutionContext {
7
- type OnFinishArgs = {
8
- userContext: any;
9
- failed: boolean;
10
- };
11
- }
12
- export interface IExecutionContext {
13
- userContext: any;
14
- getType(): ContextType;
15
- getPlatform(): string;
16
- switchToHttp(): IHttpExecutionContext;
17
- onFinish(fn: (args: IExecutionContext.OnFinishArgs) => void | Promise<void>): any;
18
- }
19
- export interface IHttpExecutionContext extends IExecutionContext {
20
- getRequest(): IHttpRequestWrapper;
21
- getResponse(): IHttpResponseWrapper;
22
- }
23
- export interface IHttpRequestWrapper {
24
- getInstance(): any;
25
- getUrl(): string;
26
- getMethod(): string;
27
- getHeaderNames(): string[];
28
- getHeader(name: string): string | string[] | undefined;
29
- getHeaders(): IncomingHttpHeaders;
30
- getBody(): any;
31
- isCompleted(): boolean;
32
- getStream(): Readable;
33
- }
34
- export interface IHttpResponseWrapper {
35
- getInstance(): any;
36
- getHeader(name: string): number | string | string[] | undefined;
37
- getHeaders(): OutgoingHttpHeaders;
38
- getHeaderNames(): string[];
39
- hasHeader(name: string): boolean;
40
- removeHeader(name: string): void;
41
- setHeader(name: string, value: number | string | string[]): this;
42
- getStatus(): number | undefined;
43
- setStatus(value: number): this;
44
- getStream(): Writable;
45
- send(body: any): this;
46
- end(): this;
47
- }
@@ -1,28 +0,0 @@
1
- import { FallbackLng, LanguageResource } from '@opra/common';
2
- export interface I18nOptions {
3
- /**
4
- * Language to use
5
- * @default undefined
6
- */
7
- lng?: string;
8
- /**
9
- * Language to use if translations in user language are not available.
10
- * @default 'dev'
11
- */
12
- fallbackLng?: false | FallbackLng;
13
- /**
14
- * Default namespace used if not passed to translation function
15
- * @default 'translation'
16
- */
17
- defaultNS?: string;
18
- /**
19
- * Resources to initialize with
20
- * @default undefined
21
- */
22
- resources?: LanguageResource;
23
- /**
24
- * Resource directories to initialize with (if not using loading or not appending using addResourceBundle)
25
- * @default undefined
26
- */
27
- resourceDirs?: string[];
28
- }
@@ -1,23 +0,0 @@
1
- import { Maybe } from 'ts-gems';
2
- import { ResourceInfo } from '@opra/common';
3
- import { PartialOutput } from '../types.js';
4
- export interface IResource {
5
- init?(resource: ResourceInfo): void | Promise<void>;
6
- shutDown?(): void | Promise<void>;
7
- }
8
- export interface ICollectionResource<T, TOutput = PartialOutput<T>> extends IResource {
9
- create?(...args: any[]): TOutput | Promise<TOutput>;
10
- count?(...args: any[]): number | Promise<number>;
11
- delete?(...args: any[]): boolean | Promise<boolean>;
12
- deleteMany?(...args: any[]): number | Promise<number>;
13
- get?(...args: any[]): Maybe<TOutput> | Promise<Maybe<TOutput>>;
14
- search?(...args: any[]): TOutput[] | Promise<TOutput[]>;
15
- update?(...args: any[]): Maybe<TOutput> | Promise<Maybe<TOutput>>;
16
- updateMany?(...args: any[]): number | Promise<number>;
17
- }
18
- export interface ISingletonResource<T, TOutput = PartialOutput<T>> extends IResource {
19
- create?(...args: any[]): TOutput | Promise<TOutput>;
20
- delete?(...args: any[]): boolean | Promise<boolean>;
21
- get?(...args: any[]): Maybe<TOutput> | Promise<Maybe<TOutput>>;
22
- update?(...args: any[]): Maybe<TOutput> | Promise<Maybe<TOutput>>;
23
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export declare abstract class DataService<T = any> {
2
- }
@@ -1,5 +0,0 @@
1
- /* eslint-disable */
2
- // import { Type } from 'ts-gems';
3
- // import { ComplexType } from '../implementation/data-type/complex-type.js';
4
- export class DataService {
5
- }