@opra/core 0.5.0 → 0.6.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/adapter.js +103 -122
- package/cjs/adapter/classes/execution-context.host.js +17 -0
- package/cjs/adapter/classes/express-request-wrapper.host.js +37 -0
- package/cjs/adapter/classes/express-response-wrapper.host.js +56 -0
- package/cjs/adapter/classes/http-execution-context.host.js +31 -0
- package/cjs/adapter/{metadata-resource.js → classes/metadata.resource.js} +3 -3
- package/cjs/adapter/express-adapter.js +6 -104
- package/cjs/adapter/http-adapter.js +270 -68
- package/cjs/adapter/request-contexts/batch-request-context.js +12 -0
- package/cjs/adapter/{query-context.js → request-contexts/request-context.js} +8 -12
- package/cjs/adapter/request-contexts/single-request-context.js +15 -0
- package/cjs/index.js +2 -1
- package/cjs/interfaces/i18n-options.interface.js +2 -0
- package/cjs/services/json-collection-service.js +36 -39
- package/cjs/services/json-singleton-service.js +9 -10
- package/cjs/utils/create-i18n.js +2 -2
- package/esm/adapter/adapter.d.ts +13 -44
- package/esm/adapter/adapter.js +89 -108
- package/esm/adapter/classes/execution-context.host.d.ts +10 -0
- package/esm/adapter/classes/execution-context.host.js +13 -0
- package/esm/adapter/classes/express-request-wrapper.host.d.ts +19 -0
- package/esm/adapter/classes/express-request-wrapper.host.js +33 -0
- package/esm/adapter/classes/express-response-wrapper.host.d.ts +22 -0
- package/esm/adapter/classes/express-response-wrapper.host.js +52 -0
- package/esm/adapter/classes/http-execution-context.host.d.ts +13 -0
- package/esm/adapter/classes/http-execution-context.host.js +27 -0
- package/esm/adapter/classes/metadata.resource.d.ts +8 -0
- package/esm/adapter/{metadata-resource.js → classes/metadata.resource.js} +2 -2
- package/esm/adapter/express-adapter.d.ts +1 -1
- package/esm/adapter/express-adapter.js +5 -103
- package/esm/adapter/http-adapter.d.ts +23 -12
- package/esm/adapter/http-adapter.js +248 -46
- package/esm/adapter/request-contexts/batch-request-context.d.ts +7 -0
- package/esm/adapter/request-contexts/batch-request-context.js +8 -0
- package/esm/adapter/request-contexts/request-context.d.ts +22 -0
- package/esm/adapter/{query-context.js → request-contexts/request-context.js} +6 -10
- package/esm/adapter/request-contexts/single-request-context.d.ts +10 -0
- package/esm/adapter/request-contexts/single-request-context.js +11 -0
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/interfaces/execution-context.interface.d.ts +19 -11
- package/esm/interfaces/i18n-options.interface.d.ts +28 -0
- package/esm/interfaces/i18n-options.interface.js +1 -0
- package/esm/interfaces/resource.interface.d.ts +1 -1
- package/esm/services/json-collection-service.d.ts +3 -4
- package/esm/services/json-collection-service.js +17 -20
- package/esm/services/json-singleton-service.d.ts +3 -3
- package/esm/services/json-singleton-service.js +8 -8
- package/esm/utils/create-i18n.d.ts +3 -3
- package/esm/utils/create-i18n.js +1 -1
- package/package.json +7 -8
- package/cjs/utils/path-to-tree.js +0 -28
- package/esm/adapter/metadata-resource.d.ts +0 -8
- package/esm/adapter/query-context.d.ts +0 -24
- package/esm/utils/path-to-tree.d.ts +0 -4
- package/esm/utils/path-to-tree.js +0 -24
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isNil, omitBy } from 'lodash';
|
|
2
2
|
import merge from 'putil-merge';
|
|
3
3
|
import { nSQL } from "@nano-sql/core";
|
|
4
|
-
import { BadRequestError, MethodNotAllowedError, ResourceConflictError } from '@opra/
|
|
5
|
-
import { CollectionResourceInfo, ComplexType } from '@opra/schema';
|
|
6
|
-
import { $parse, ArrayExpression, BooleanLiteral, ComparisonExpression, DateLiteral, Expression, LogicalExpression, NullLiteral, NumberLiteral, ParenthesesExpression, QualifiedIdentifier, StringLiteral, TimeLiteral } from '@opra/url';
|
|
7
|
-
import { pathToTree } from '../utils/path-to-tree.js';
|
|
4
|
+
import { ArrayExpression, BadRequestError, BooleanLiteral, CollectionResourceInfo, ComparisonExpression, ComplexType, DateLiteral, Expression, LogicalExpression, MethodNotAllowedError, NullLiteral, NumberLiteral, ParenthesesExpression, parseFilter, pathToTree, QualifiedIdentifier, ResourceConflictError, StringLiteral, TimeLiteral } from '@opra/common';
|
|
8
5
|
let dbId = 1;
|
|
9
6
|
const indexingTypes = ['int', 'float', 'number', 'date', 'string'];
|
|
10
7
|
export class JsonCollectionService {
|
|
@@ -248,9 +245,9 @@ export class JsonCollectionService {
|
|
|
248
245
|
}
|
|
249
246
|
switch (query.method) {
|
|
250
247
|
case 'count': {
|
|
251
|
-
const options =
|
|
248
|
+
const options = omitBy({
|
|
252
249
|
filter: this._convertFilter(query.filter)
|
|
253
|
-
},
|
|
250
|
+
}, isNil);
|
|
254
251
|
return {
|
|
255
252
|
method: query.method,
|
|
256
253
|
options,
|
|
@@ -258,11 +255,11 @@ export class JsonCollectionService {
|
|
|
258
255
|
};
|
|
259
256
|
}
|
|
260
257
|
case 'create': {
|
|
261
|
-
const options =
|
|
258
|
+
const options = omitBy({
|
|
262
259
|
pick: query.pick,
|
|
263
260
|
omit: query.omit,
|
|
264
261
|
include: query.include
|
|
265
|
-
},
|
|
262
|
+
}, isNil);
|
|
266
263
|
const { data } = query;
|
|
267
264
|
return {
|
|
268
265
|
method: query.method,
|
|
@@ -273,11 +270,11 @@ export class JsonCollectionService {
|
|
|
273
270
|
}
|
|
274
271
|
case 'get': {
|
|
275
272
|
if (query.kind === 'CollectionGetQuery') {
|
|
276
|
-
const options =
|
|
273
|
+
const options = omitBy({
|
|
277
274
|
pick: query.pick,
|
|
278
275
|
omit: query.omit,
|
|
279
276
|
include: query.include
|
|
280
|
-
},
|
|
277
|
+
}, isNil);
|
|
281
278
|
const keyValue = query.keyValue;
|
|
282
279
|
return {
|
|
283
280
|
method: query.method,
|
|
@@ -296,7 +293,7 @@ export class JsonCollectionService {
|
|
|
296
293
|
throw new MethodNotAllowedError({
|
|
297
294
|
message: '$distinct parameter is not supported by JsonDataService'
|
|
298
295
|
});
|
|
299
|
-
const options =
|
|
296
|
+
const options = omitBy({
|
|
300
297
|
pick: query.pick,
|
|
301
298
|
omit: query.omit,
|
|
302
299
|
include: query.include,
|
|
@@ -306,7 +303,7 @@ export class JsonCollectionService {
|
|
|
306
303
|
limit: query.limit,
|
|
307
304
|
offset: query.skip,
|
|
308
305
|
count: query.count,
|
|
309
|
-
},
|
|
306
|
+
}, isNil);
|
|
310
307
|
return {
|
|
311
308
|
method: query.method,
|
|
312
309
|
options,
|
|
@@ -314,11 +311,11 @@ export class JsonCollectionService {
|
|
|
314
311
|
};
|
|
315
312
|
}
|
|
316
313
|
case 'update': {
|
|
317
|
-
const options =
|
|
314
|
+
const options = omitBy({
|
|
318
315
|
pick: query.pick,
|
|
319
316
|
omit: query.omit,
|
|
320
317
|
include: query.include
|
|
321
|
-
},
|
|
318
|
+
}, isNil);
|
|
322
319
|
const { data } = query;
|
|
323
320
|
const keyValue = query.keyValue;
|
|
324
321
|
return {
|
|
@@ -330,9 +327,9 @@ export class JsonCollectionService {
|
|
|
330
327
|
};
|
|
331
328
|
}
|
|
332
329
|
case 'updateMany': {
|
|
333
|
-
const options =
|
|
330
|
+
const options = omitBy({
|
|
334
331
|
filter: this._convertFilter(query.filter)
|
|
335
|
-
},
|
|
332
|
+
}, isNil);
|
|
336
333
|
const { data } = query;
|
|
337
334
|
return {
|
|
338
335
|
method: query.method,
|
|
@@ -351,9 +348,9 @@ export class JsonCollectionService {
|
|
|
351
348
|
};
|
|
352
349
|
}
|
|
353
350
|
case 'deleteMany': {
|
|
354
|
-
const options =
|
|
351
|
+
const options = omitBy({
|
|
355
352
|
filter: this._convertFilter(query.filter)
|
|
356
|
-
},
|
|
353
|
+
}, isNil);
|
|
357
354
|
return {
|
|
358
355
|
method: query.method,
|
|
359
356
|
options,
|
|
@@ -388,7 +385,7 @@ export class JsonCollectionService {
|
|
|
388
385
|
}
|
|
389
386
|
_convertFilter(str) {
|
|
390
387
|
const ast = typeof str === 'string'
|
|
391
|
-
?
|
|
388
|
+
? parseFilter(str)
|
|
392
389
|
: str;
|
|
393
390
|
if (!ast || !(ast instanceof Expression))
|
|
394
391
|
return ast;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DataType, OpraQuery, OpraSchema } from '@opra/
|
|
2
|
-
import {
|
|
1
|
+
import { DataType, OpraQuery, OpraSchema } from '@opra/common';
|
|
2
|
+
import { SingleRequestContext } from '../adapter/request-contexts/single-request-context.js';
|
|
3
3
|
import { PartialOutput } from '../types.js';
|
|
4
4
|
export interface JsonSingletonServiceOptions<T> {
|
|
5
5
|
data: T;
|
|
@@ -9,7 +9,7 @@ export declare class JsonSingletonService<T, TOutput = PartialOutput<T>> {
|
|
|
9
9
|
readonly dataType: DataType;
|
|
10
10
|
protected _data?: T;
|
|
11
11
|
constructor(dataType: DataType, options?: JsonSingletonServiceOptions<T>);
|
|
12
|
-
processRequest(ctx:
|
|
12
|
+
processRequest(ctx: SingleRequestContext): Promise<any>;
|
|
13
13
|
get(options?: JsonSingletonService.GetOptions): TOutput | undefined;
|
|
14
14
|
protected _prepare(query: OpraQuery): {
|
|
15
15
|
method: OpraSchema.SingletonMethod;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { SingletonResourceInfo } from '@opra/
|
|
1
|
+
import { isNil, omitBy } from 'lodash';
|
|
2
|
+
import { SingletonResourceInfo } from '@opra/common';
|
|
3
3
|
export class JsonSingletonService {
|
|
4
4
|
dataType;
|
|
5
5
|
_data;
|
|
@@ -27,11 +27,11 @@ export class JsonSingletonService {
|
|
|
27
27
|
}
|
|
28
28
|
switch (query.method) {
|
|
29
29
|
case 'create': {
|
|
30
|
-
const options =
|
|
30
|
+
const options = omitBy({
|
|
31
31
|
pick: query.pick,
|
|
32
32
|
omit: query.omit,
|
|
33
33
|
include: query.include
|
|
34
|
-
},
|
|
34
|
+
}, isNil);
|
|
35
35
|
const { data } = query;
|
|
36
36
|
return {
|
|
37
37
|
method: query.method,
|
|
@@ -42,11 +42,11 @@ export class JsonSingletonService {
|
|
|
42
42
|
}
|
|
43
43
|
case 'get': {
|
|
44
44
|
if (query.kind === 'CollectionGetQuery') {
|
|
45
|
-
const options =
|
|
45
|
+
const options = omitBy({
|
|
46
46
|
pick: query.pick,
|
|
47
47
|
omit: query.omit,
|
|
48
48
|
include: query.include
|
|
49
|
-
},
|
|
49
|
+
}, isNil);
|
|
50
50
|
const keyValue = query.keyValue;
|
|
51
51
|
return {
|
|
52
52
|
method: query.method,
|
|
@@ -61,11 +61,11 @@ export class JsonSingletonService {
|
|
|
61
61
|
break;
|
|
62
62
|
}
|
|
63
63
|
case 'update': {
|
|
64
|
-
const options =
|
|
64
|
+
const options = omitBy({
|
|
65
65
|
pick: query.pick,
|
|
66
66
|
omit: query.omit,
|
|
67
67
|
include: query.include
|
|
68
|
-
},
|
|
68
|
+
}, isNil);
|
|
69
69
|
const { data } = query;
|
|
70
70
|
const keyValue = query.keyValue;
|
|
71
71
|
return {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { I18n } from '@opra/
|
|
2
|
-
import {
|
|
3
|
-
export declare function createI18n(options?:
|
|
1
|
+
import { I18n } from '@opra/common';
|
|
2
|
+
import { I18nOptions } from '../interfaces/i18n-options.interface.js';
|
|
3
|
+
export declare function createI18n(options?: I18nOptions): Promise<I18n>;
|
package/esm/utils/create-i18n.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,16 +28,14 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@nano-sql/core": "^2.3.7",
|
|
31
|
-
"@opra/common": "^0.
|
|
32
|
-
"@opra/
|
|
33
|
-
"@opra/i18n": "^0.5.0",
|
|
34
|
-
"@opra/optionals": "^0.5.0",
|
|
35
|
-
"@opra/schema": "^0.5.0",
|
|
36
|
-
"@opra/url": "^0.5.0",
|
|
37
|
-
"axiosist": "^1.0.0",
|
|
31
|
+
"@opra/common": "^0.6.0",
|
|
32
|
+
"@opra/optionals": "^0.6.0",
|
|
38
33
|
"body-parser": "^1.20.1",
|
|
34
|
+
"dicer": "^0.3.1",
|
|
39
35
|
"express": "^4.18.2",
|
|
36
|
+
"http-parser-js": "^0.5.8",
|
|
40
37
|
"lodash": "^4.17.21",
|
|
38
|
+
"power-tasks": "^1.6.1",
|
|
41
39
|
"putil-isplainobject": "^1.1.4",
|
|
42
40
|
"putil-merge": "^3.9.0",
|
|
43
41
|
"putil-varhelpers": "^1.6.4",
|
|
@@ -46,6 +44,7 @@
|
|
|
46
44
|
},
|
|
47
45
|
"devDependencies": {
|
|
48
46
|
"@faker-js/faker": "^7.6.0",
|
|
47
|
+
"@types/dicer": "^0.2.2",
|
|
49
48
|
"@types/express": "^4.17.14"
|
|
50
49
|
},
|
|
51
50
|
"type": "module",
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pathToTree = void 0;
|
|
4
|
-
const dotPattern = /^([^.]+)\.(.*)$/;
|
|
5
|
-
function pathToTree(arr, lowerCaseKeys) {
|
|
6
|
-
if (!arr.length)
|
|
7
|
-
return;
|
|
8
|
-
return _pathToTree(arr, {}, lowerCaseKeys);
|
|
9
|
-
}
|
|
10
|
-
exports.pathToTree = pathToTree;
|
|
11
|
-
function _pathToTree(arr, target, lowerCaseKeys) {
|
|
12
|
-
for (let k of arr) {
|
|
13
|
-
if (lowerCaseKeys)
|
|
14
|
-
k = k.toLowerCase();
|
|
15
|
-
const m = dotPattern.exec(k);
|
|
16
|
-
if (m) {
|
|
17
|
-
const key = m[1];
|
|
18
|
-
if (target[key] === true)
|
|
19
|
-
continue;
|
|
20
|
-
const sub = target[key] = typeof target[key] === 'object' ? target[key] : {};
|
|
21
|
-
_pathToTree([m[2]], sub);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
target[k] = true;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return target;
|
|
28
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { SingletonResourceInfo } from '@opra/schema';
|
|
2
|
-
import { ISingletonResource } from '../interfaces/resource.interface.js';
|
|
3
|
-
import { JsonSingletonService } from '../services/json-singleton-service.js';
|
|
4
|
-
export declare class MetadataResource implements ISingletonResource<any> {
|
|
5
|
-
service: JsonSingletonService<any>;
|
|
6
|
-
init(resource: SingletonResourceInfo): void;
|
|
7
|
-
get(): any;
|
|
8
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { HeadersMap, HttpStatus } from '@opra/common';
|
|
2
|
-
import { OpraException } from '@opra/exception';
|
|
3
|
-
import { OpraDocument, OpraQuery } from '@opra/schema';
|
|
4
|
-
import { OpraURLSearchParams } from '@opra/url';
|
|
5
|
-
import { ContextType, IExecutionContext, IHttpExecutionContext } from '../interfaces/execution-context.interface.js';
|
|
6
|
-
export declare type QueryContextArgs = Pick<QueryContext, 'service' | 'executionContext' | 'query' | 'params' | 'headers' | 'userContext' | 'parentValue' | 'continueOnError'>;
|
|
7
|
-
export declare class QueryContext {
|
|
8
|
-
readonly service: OpraDocument;
|
|
9
|
-
readonly executionContext: IExecutionContext;
|
|
10
|
-
readonly query: OpraQuery;
|
|
11
|
-
readonly params: OpraURLSearchParams;
|
|
12
|
-
readonly headers: HeadersMap;
|
|
13
|
-
readonly parentValue?: any;
|
|
14
|
-
readonly resultPath: string;
|
|
15
|
-
readonly responseHeaders: HeadersMap;
|
|
16
|
-
response?: any;
|
|
17
|
-
errors: OpraException[];
|
|
18
|
-
status?: HttpStatus;
|
|
19
|
-
userContext?: any;
|
|
20
|
-
continueOnError?: boolean;
|
|
21
|
-
constructor(args: QueryContextArgs);
|
|
22
|
-
get type(): ContextType;
|
|
23
|
-
switchToHttp(): IHttpExecutionContext;
|
|
24
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const dotPattern = /^([^.]+)\.(.*)$/;
|
|
2
|
-
export function pathToTree(arr, lowerCaseKeys) {
|
|
3
|
-
if (!arr.length)
|
|
4
|
-
return;
|
|
5
|
-
return _pathToTree(arr, {}, lowerCaseKeys);
|
|
6
|
-
}
|
|
7
|
-
function _pathToTree(arr, target, lowerCaseKeys) {
|
|
8
|
-
for (let k of arr) {
|
|
9
|
-
if (lowerCaseKeys)
|
|
10
|
-
k = k.toLowerCase();
|
|
11
|
-
const m = dotPattern.exec(k);
|
|
12
|
-
if (m) {
|
|
13
|
-
const key = m[1];
|
|
14
|
-
if (target[key] === true)
|
|
15
|
-
continue;
|
|
16
|
-
const sub = target[key] = typeof target[key] === 'object' ? target[key] : {};
|
|
17
|
-
_pathToTree([m[2]], sub);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
target[k] = true;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return target;
|
|
24
|
-
}
|