@opra/core 0.0.8 → 0.0.11
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/exception/api-exception.js +32 -35
- package/cjs/exception/{errors → http-errors}/bad-request.error.js +7 -4
- package/cjs/exception/{errors → http-errors}/failed-dependency.error.js +7 -4
- package/cjs/exception/{errors → http-errors}/forbidden.error.js +7 -4
- package/cjs/exception/{errors → http-errors}/internal-server.error.js +10 -5
- package/cjs/exception/{errors → http-errors}/method-not-allowed.error.js +7 -4
- package/cjs/exception/{errors → http-errors}/not-found.error.js +6 -3
- package/cjs/exception/{errors → http-errors}/unauthorized.error.js +6 -3
- package/cjs/exception/{errors → http-errors}/unprocessable-entity.error.js +7 -4
- package/cjs/exception/index.js +9 -7
- package/cjs/exception/resource-errors/resource-conflict.error.js +19 -0
- package/cjs/exception/wrap-error.js +2 -2
- package/cjs/implementation/adapter/adapter.js +31 -29
- package/cjs/implementation/adapter/express-adapter.js +40 -9
- package/cjs/implementation/adapter/http-adapter.js +28 -35
- package/cjs/implementation/{execution-context.js → query-context.js} +18 -22
- package/cjs/implementation/resource/entity-resource-handler.js +16 -12
- package/cjs/implementation/resource/resource-handler.js +1 -1
- package/cjs/implementation/schema-generator.js +38 -51
- package/cjs/index.js +3 -4
- package/cjs/interfaces/{http-context.interface.js → execution-context.interface.js} +0 -0
- package/cjs/interfaces/{execution-query.interface.js → query.interface.js} +24 -24
- package/cjs/utils/create-i18n.js +21 -0
- package/cjs/utils/get-caller-file.util.js +19 -0
- package/cjs/utils/internal-data-types.js +54 -17
- package/esm/exception/api-exception.d.ts +3 -2
- package/esm/exception/api-exception.js +32 -35
- package/esm/exception/{errors → http-errors}/bad-request.error.d.ts +2 -1
- package/esm/exception/{errors → http-errors}/bad-request.error.js +7 -4
- package/esm/exception/{errors → http-errors}/failed-dependency.error.d.ts +2 -1
- package/esm/exception/{errors → http-errors}/failed-dependency.error.js +7 -4
- package/esm/exception/{errors → http-errors}/forbidden.error.d.ts +2 -1
- package/esm/exception/{errors → http-errors}/forbidden.error.js +7 -4
- package/esm/exception/{errors → http-errors}/internal-server.error.d.ts +2 -1
- package/esm/exception/{errors → http-errors}/internal-server.error.js +9 -5
- package/esm/exception/{errors → http-errors}/method-not-allowed.error.d.ts +2 -1
- package/esm/exception/{errors → http-errors}/method-not-allowed.error.js +7 -4
- package/esm/exception/{errors → http-errors}/not-found.error.d.ts +2 -1
- package/esm/exception/{errors → http-errors}/not-found.error.js +6 -3
- package/esm/exception/{errors → http-errors}/unauthorized.error.d.ts +2 -1
- package/esm/exception/{errors → http-errors}/unauthorized.error.js +6 -3
- package/esm/exception/{errors → http-errors}/unprocessable-entity.error.d.ts +2 -1
- package/esm/exception/{errors → http-errors}/unprocessable-entity.error.js +7 -4
- package/esm/exception/index.d.ts +9 -7
- package/esm/exception/index.js +9 -7
- package/esm/exception/resource-errors/resource-conflict.error.d.ts +4 -0
- package/esm/exception/resource-errors/resource-conflict.error.js +15 -0
- package/esm/exception/wrap-error.js +2 -2
- package/esm/implementation/adapter/adapter.d.ts +22 -14
- package/esm/implementation/adapter/adapter.js +31 -29
- package/esm/implementation/adapter/express-adapter.d.ts +2 -2
- package/esm/implementation/adapter/express-adapter.js +40 -9
- package/esm/implementation/adapter/http-adapter.d.ts +11 -12
- package/esm/implementation/adapter/http-adapter.js +28 -35
- package/esm/implementation/query-context.d.ts +32 -0
- package/esm/implementation/{execution-context.js → query-context.js} +15 -18
- package/esm/implementation/resource/container-resource-handler.d.ts +2 -2
- package/esm/implementation/resource/entity-resource-handler.d.ts +3 -3
- package/esm/implementation/resource/entity-resource-handler.js +16 -12
- package/esm/implementation/resource/resource-handler.d.ts +3 -3
- package/esm/implementation/resource/resource-handler.js +1 -1
- package/esm/implementation/schema-generator.js +38 -51
- package/esm/index.d.ts +3 -4
- package/esm/index.js +3 -4
- package/esm/interfaces/execution-context.interface.d.ts +39 -0
- package/esm/interfaces/{http-context.interface.js → execution-context.interface.js} +0 -0
- package/esm/interfaces/query.interface.d.ts +108 -0
- package/esm/interfaces/{execution-query.interface.js → query.interface.js} +23 -23
- package/esm/services/entity-resource-controller.d.ts +11 -11
- package/esm/types.d.ts +1 -3
- package/esm/utils/create-i18n.d.ts +3 -0
- package/esm/utils/create-i18n.js +16 -0
- package/esm/utils/get-caller-file.util.d.ts +1 -0
- package/esm/utils/get-caller-file.util.js +15 -0
- package/esm/utils/internal-data-types.d.ts +2 -1
- package/esm/utils/internal-data-types.js +53 -16
- package/i18n/en/error.json +12 -0
- package/package.json +10 -6
- package/cjs/interfaces/user-context.interface.js +0 -2
- package/esm/implementation/execution-context.d.ts +0 -42
- package/esm/interfaces/execution-query.interface.d.ts +0 -102
- package/esm/interfaces/http-context.interface.d.ts +0 -23
- package/esm/interfaces/user-context.interface.d.ts +0 -3
- package/esm/interfaces/user-context.interface.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
"build": "npm run build:cjs && npm run build:esm",
|
|
16
16
|
"build:cjs": "tsc -b tsconfig-build-cjs.json",
|
|
17
17
|
"build:esm": "tsc -b tsconfig-build-esm.json",
|
|
18
|
-
"postbuild": "
|
|
18
|
+
"postbuild": "npm run _copyi18n && npm run _copy_pkg_files",
|
|
19
|
+
"_copy_pkg_files": "cp README.md package.json ../../LICENSE ../../build/core && cp ../../package.cjs.json ../../build/core/cjs/package.json",
|
|
20
|
+
"_copyi18n": "cp -R i18n ../../build/core/i18n",
|
|
19
21
|
"lint": "eslint .",
|
|
20
22
|
"test": "jest",
|
|
21
23
|
"cover": "jest --collect-coverage",
|
|
@@ -25,14 +27,15 @@
|
|
|
25
27
|
"clean:cover": "rimraf ../../coverage/core"
|
|
26
28
|
},
|
|
27
29
|
"dependencies": {
|
|
28
|
-
"@opra/i18n": "^0.0.
|
|
29
|
-
"@opra/optionals": "^0.0.
|
|
30
|
-
"@opra/schema": "^0.0.
|
|
31
|
-
"@opra/url": "^0.0.
|
|
30
|
+
"@opra/i18n": "^0.0.11",
|
|
31
|
+
"@opra/optionals": "^0.0.11",
|
|
32
|
+
"@opra/schema": "^0.0.11",
|
|
33
|
+
"@opra/url": "^0.0.11",
|
|
32
34
|
"lodash": "^4.17.21",
|
|
33
35
|
"putil-isplainobject": "^1.1.4",
|
|
34
36
|
"putil-varhelpers": "^1.6.4",
|
|
35
37
|
"rule-judgment": "^1.1.5",
|
|
38
|
+
"strict-typed-events": "^2.2.0",
|
|
36
39
|
"ts-gems": "^2.2.0"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
@@ -59,6 +62,7 @@
|
|
|
59
62
|
"bin/",
|
|
60
63
|
"cjs/",
|
|
61
64
|
"esm/",
|
|
65
|
+
"i18n/",
|
|
62
66
|
"LICENSE",
|
|
63
67
|
"README.md"
|
|
64
68
|
],
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { SearchParams } from '@opra/url';
|
|
2
|
-
import { HttpStatus } from '../enums/index.js';
|
|
3
|
-
import { ApiException } from '../exception/index.js';
|
|
4
|
-
import { ExecutionQuery } from '../interfaces/execution-query.interface.js';
|
|
5
|
-
import { IHttpAdapterContext } from '../interfaces/http-context.interface.js';
|
|
6
|
-
import { HeadersObject } from '../utils/headers.js';
|
|
7
|
-
import { OpraService } from './opra-service.js';
|
|
8
|
-
export declare type ContextType = 'http' | 'ws' | 'rpc';
|
|
9
|
-
export declare type ExecutionContextArgs = Pick<ExecutionContext, 'type' | 'service' | 'request' | 'response' | 'adapterContext' | 'userContext' | 'continueOnError'>;
|
|
10
|
-
export declare class ExecutionContext {
|
|
11
|
-
readonly type: ContextType;
|
|
12
|
-
readonly service: OpraService;
|
|
13
|
-
readonly request: ExecutionRequest;
|
|
14
|
-
readonly response: ExecutionResponse;
|
|
15
|
-
readonly adapterContext: any;
|
|
16
|
-
userContext?: any;
|
|
17
|
-
continueOnError?: boolean;
|
|
18
|
-
constructor(args: ExecutionContextArgs);
|
|
19
|
-
switchToHttp(): IHttpAdapterContext;
|
|
20
|
-
}
|
|
21
|
-
export declare type ExecutionRequestArgs = Pick<ExecutionRequest, 'query' | 'parentValue'> & {
|
|
22
|
-
params?: SearchParams;
|
|
23
|
-
headers?: HeadersObject;
|
|
24
|
-
resultPath?: string;
|
|
25
|
-
};
|
|
26
|
-
export declare class ExecutionRequest {
|
|
27
|
-
readonly query: ExecutionQuery;
|
|
28
|
-
readonly params: SearchParams;
|
|
29
|
-
readonly headers: HeadersObject;
|
|
30
|
-
readonly parentValue?: any;
|
|
31
|
-
readonly resultPath: string;
|
|
32
|
-
constructor(args: ExecutionRequestArgs);
|
|
33
|
-
}
|
|
34
|
-
export declare type ExecutionResponseArgs = Pick<ExecutionResponse, 'status' | 'value' | 'total'>;
|
|
35
|
-
export declare class ExecutionResponse {
|
|
36
|
-
headers: HeadersObject;
|
|
37
|
-
errors: ApiException[];
|
|
38
|
-
status?: HttpStatus;
|
|
39
|
-
value?: any;
|
|
40
|
-
total?: number;
|
|
41
|
-
constructor(args?: ExecutionResponseArgs);
|
|
42
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { StrictOmit } from 'ts-gems';
|
|
2
|
-
import { OpraSchema } from '@opra/schema';
|
|
3
|
-
import { Expression } from '@opra/url';
|
|
4
|
-
import { EntityResourceHandler } from '../implementation/resource/entity-resource-handler.js';
|
|
5
|
-
import { KeyValue, OperationType, QueryScope, QueryType } from '../types.js';
|
|
6
|
-
export declare type ExecutionQuery = CreateQuery | ReadQuery | SearchQuery | UpdateQuery | UpdateManyQuery | DeleteQuery | DeleteManyQuery;
|
|
7
|
-
interface BaseQuery {
|
|
8
|
-
queryType: QueryType;
|
|
9
|
-
scope: QueryScope;
|
|
10
|
-
operationType: OperationType;
|
|
11
|
-
}
|
|
12
|
-
export interface CreateQuery extends BaseQuery {
|
|
13
|
-
queryType: 'create';
|
|
14
|
-
scope: 'collection';
|
|
15
|
-
operationType: 'create';
|
|
16
|
-
resource: EntityResourceHandler;
|
|
17
|
-
data: {};
|
|
18
|
-
pick?: string[];
|
|
19
|
-
omit?: string[];
|
|
20
|
-
include?: string[];
|
|
21
|
-
}
|
|
22
|
-
export interface ReadQuery extends BaseQuery {
|
|
23
|
-
queryType: 'get';
|
|
24
|
-
scope: 'instance';
|
|
25
|
-
operationType: 'read';
|
|
26
|
-
resource: EntityResourceHandler;
|
|
27
|
-
keyValue: KeyValue;
|
|
28
|
-
pick?: string[];
|
|
29
|
-
omit?: string[];
|
|
30
|
-
include?: string[];
|
|
31
|
-
nested?: PropertyQuery;
|
|
32
|
-
}
|
|
33
|
-
export interface PropertyQuery extends BaseQuery {
|
|
34
|
-
queryType: 'get';
|
|
35
|
-
scope: 'property';
|
|
36
|
-
operationType: 'read';
|
|
37
|
-
property: OpraSchema.Property;
|
|
38
|
-
nested?: PropertyQuery;
|
|
39
|
-
}
|
|
40
|
-
export interface UpdateQuery extends BaseQuery {
|
|
41
|
-
queryType: 'update';
|
|
42
|
-
scope: 'instance';
|
|
43
|
-
operationType: 'update';
|
|
44
|
-
resource: EntityResourceHandler;
|
|
45
|
-
keyValue: KeyValue;
|
|
46
|
-
data: {};
|
|
47
|
-
pick?: string[];
|
|
48
|
-
omit?: string[];
|
|
49
|
-
include?: string[];
|
|
50
|
-
}
|
|
51
|
-
export interface UpdateManyQuery extends BaseQuery {
|
|
52
|
-
queryType: 'updateMany';
|
|
53
|
-
scope: 'collection';
|
|
54
|
-
operationType: 'update';
|
|
55
|
-
resource: EntityResourceHandler;
|
|
56
|
-
filter?: string | Expression;
|
|
57
|
-
data: {};
|
|
58
|
-
}
|
|
59
|
-
export interface DeleteQuery extends BaseQuery {
|
|
60
|
-
queryType: 'delete';
|
|
61
|
-
scope: 'instance';
|
|
62
|
-
operationType: 'delete';
|
|
63
|
-
resource: EntityResourceHandler;
|
|
64
|
-
keyValue: KeyValue;
|
|
65
|
-
}
|
|
66
|
-
export interface DeleteManyQuery extends BaseQuery {
|
|
67
|
-
queryType: 'deleteMany';
|
|
68
|
-
scope: 'collection';
|
|
69
|
-
operationType: 'delete';
|
|
70
|
-
resource: EntityResourceHandler;
|
|
71
|
-
filter?: string | Expression;
|
|
72
|
-
}
|
|
73
|
-
export interface SearchQuery extends BaseQuery {
|
|
74
|
-
queryType: 'search';
|
|
75
|
-
scope: 'collection';
|
|
76
|
-
operationType: 'read';
|
|
77
|
-
resource: EntityResourceHandler;
|
|
78
|
-
pick?: string[];
|
|
79
|
-
omit?: string[];
|
|
80
|
-
include?: string[];
|
|
81
|
-
filter?: string | Expression;
|
|
82
|
-
limit?: number;
|
|
83
|
-
skip?: number;
|
|
84
|
-
distinct?: boolean;
|
|
85
|
-
count?: boolean;
|
|
86
|
-
sort?: string[];
|
|
87
|
-
}
|
|
88
|
-
export declare namespace ExecutionQuery {
|
|
89
|
-
function forCreate(resource: EntityResourceHandler, values: {}, options?: StrictOmit<CreateQuery, 'queryType' | 'scope' | 'operationType' | 'resource' | 'data'>): CreateQuery;
|
|
90
|
-
function forGet(resource: EntityResourceHandler, key: KeyValue, options?: StrictOmit<ReadQuery, 'queryType' | 'scope' | 'operationType' | 'resource' | 'keyValue'>): ReadQuery;
|
|
91
|
-
function forSearch(resource: EntityResourceHandler, options?: StrictOmit<SearchQuery, 'queryType' | 'scope' | 'operationType' | 'resource'>): SearchQuery;
|
|
92
|
-
function forGetProperty(property: OpraSchema.Property, options?: StrictOmit<PropertyQuery, 'queryType' | 'scope' | 'operationType' | 'property'>): PropertyQuery;
|
|
93
|
-
function forUpdate(resource: EntityResourceHandler, keyValue: KeyValue, values: any, options?: StrictOmit<UpdateQuery, 'queryType' | 'scope' | 'operationType' | 'resource' | 'keyValue' | 'data'>): UpdateQuery;
|
|
94
|
-
function forUpdateMany(resource: EntityResourceHandler, values: any, options?: StrictOmit<UpdateManyQuery, 'queryType' | 'scope' | 'operationType' | 'resource' | 'data'>): UpdateManyQuery;
|
|
95
|
-
function forDelete(resource: EntityResourceHandler, key: KeyValue): DeleteQuery;
|
|
96
|
-
function forDeleteMany(resource: EntityResourceHandler, options?: StrictOmit<DeleteManyQuery, 'queryType' | 'scope' | 'operationType' | 'resource'>): DeleteManyQuery;
|
|
97
|
-
function isCreateQuery(q: any): q is CreateQuery;
|
|
98
|
-
function isSearchQuery(q: any): q is SearchQuery;
|
|
99
|
-
function isReadQuery(q: any): q is ReadQuery;
|
|
100
|
-
function isDeleteQuery(q: any): q is DeleteQuery;
|
|
101
|
-
}
|
|
102
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export interface IHttpAdapterContext {
|
|
2
|
-
getRequest(): IHttpRequest;
|
|
3
|
-
getResponse(): IHttpResponse;
|
|
4
|
-
}
|
|
5
|
-
export interface IHttpRequest {
|
|
6
|
-
getInstance(): any;
|
|
7
|
-
getUrl(): string;
|
|
8
|
-
getMethod(): string;
|
|
9
|
-
getHeaderNames(): string[];
|
|
10
|
-
getHeader(name: string): string | undefined;
|
|
11
|
-
getHeaders(): Record<string, any>;
|
|
12
|
-
getBody(): any;
|
|
13
|
-
}
|
|
14
|
-
export interface IHttpResponse {
|
|
15
|
-
getInstance(): any;
|
|
16
|
-
getStatus(): number | undefined;
|
|
17
|
-
setStatus(value: number): this;
|
|
18
|
-
getHeaderNames(name: string): string[];
|
|
19
|
-
getHeader(name: string): string | undefined;
|
|
20
|
-
setHeader(name: string, value: string): this;
|
|
21
|
-
send(body: any): this;
|
|
22
|
-
end(): this;
|
|
23
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|