@opra/core 0.1.0 → 0.2.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/enums/http-headers.enum.js +3 -2
- package/cjs/implementation/adapter-utils/entity-resource-execute.util.js +36 -34
- package/cjs/implementation/adapter-utils/resource-prepare.util.js +1 -1
- package/cjs/implementation/adapter.js +14 -19
- package/cjs/implementation/express-adapter.js +3 -0
- package/cjs/implementation/headers-map.js +18 -0
- package/cjs/implementation/http-adapter.js +65 -79
- package/cjs/implementation/query-context.js +12 -19
- package/cjs/index.js +0 -2
- package/cjs/services/json-data-service.js +367 -131
- package/cjs/utils/path-to-tree.js +7 -5
- package/esm/enums/http-headers.enum.d.ts +3 -2
- package/esm/enums/http-headers.enum.js +3 -2
- package/esm/implementation/adapter-utils/entity-resource-execute.util.js +35 -33
- package/esm/implementation/adapter-utils/resource-execute.util.d.ts +2 -2
- package/esm/implementation/adapter-utils/resource-prepare.util.d.ts +2 -2
- package/esm/implementation/adapter-utils/resource-prepare.util.js +1 -1
- package/esm/implementation/adapter.d.ts +2 -2
- package/esm/implementation/adapter.js +12 -17
- package/esm/implementation/express-adapter.js +2 -0
- package/esm/implementation/headers-map.d.ts +5 -0
- package/esm/implementation/headers-map.js +14 -0
- package/esm/implementation/http-adapter.d.ts +6 -6
- package/esm/implementation/http-adapter.js +61 -75
- package/esm/implementation/query-context.d.ts +9 -15
- package/esm/implementation/query-context.js +11 -17
- package/esm/index.d.ts +0 -2
- package/esm/index.js +0 -2
- package/esm/interfaces/entity-service.interface.d.ts +8 -6
- package/esm/services/json-data-service.d.ts +56 -39
- package/esm/services/json-data-service.js +365 -129
- package/esm/types.d.ts +0 -3
- package/esm/utils/path-to-tree.d.ts +1 -1
- package/esm/utils/path-to-tree.js +7 -5
- package/i18n/en/error.json +5 -5
- package/package.json +11 -8
- package/cjs/exception/api-exception.js +0 -68
- package/cjs/exception/http-errors/bad-request.error.js +0 -26
- package/cjs/exception/http-errors/failed-dependency.error.js +0 -25
- package/cjs/exception/http-errors/forbidden.error.js +0 -27
- package/cjs/exception/http-errors/internal-server.error.js +0 -27
- package/cjs/exception/http-errors/method-not-allowed.error.js +0 -26
- package/cjs/exception/http-errors/not-acceptable.error.js +0 -26
- package/cjs/exception/http-errors/not-found.error.js +0 -29
- package/cjs/exception/http-errors/unauthorized.error.js +0 -26
- package/cjs/exception/http-errors/unprocessable-entity.error.js +0 -25
- package/cjs/exception/index.js +0 -15
- package/cjs/exception/resource-errors/resource-conflict.error.js +0 -19
- package/cjs/exception/resource-errors/resource-not-found.error.js +0 -19
- package/cjs/exception/wrap-error.js +0 -17
- package/cjs/interfaces/query.interface.js +0 -207
- package/esm/exception/api-exception.d.ts +0 -40
- package/esm/exception/api-exception.js +0 -64
- package/esm/exception/http-errors/bad-request.error.d.ts +0 -10
- package/esm/exception/http-errors/bad-request.error.js +0 -22
- package/esm/exception/http-errors/failed-dependency.error.d.ts +0 -9
- package/esm/exception/http-errors/failed-dependency.error.js +0 -21
- package/esm/exception/http-errors/forbidden.error.d.ts +0 -11
- package/esm/exception/http-errors/forbidden.error.js +0 -23
- package/esm/exception/http-errors/internal-server.error.d.ts +0 -9
- package/esm/exception/http-errors/internal-server.error.js +0 -22
- package/esm/exception/http-errors/method-not-allowed.error.d.ts +0 -10
- package/esm/exception/http-errors/method-not-allowed.error.js +0 -22
- package/esm/exception/http-errors/not-acceptable.error.d.ts +0 -10
- package/esm/exception/http-errors/not-acceptable.error.js +0 -22
- package/esm/exception/http-errors/not-found.error.d.ts +0 -13
- package/esm/exception/http-errors/not-found.error.js +0 -25
- package/esm/exception/http-errors/unauthorized.error.d.ts +0 -10
- package/esm/exception/http-errors/unauthorized.error.js +0 -22
- package/esm/exception/http-errors/unprocessable-entity.error.d.ts +0 -9
- package/esm/exception/http-errors/unprocessable-entity.error.js +0 -21
- package/esm/exception/index.d.ts +0 -12
- package/esm/exception/index.js +0 -12
- package/esm/exception/resource-errors/resource-conflict.error.d.ts +0 -4
- package/esm/exception/resource-errors/resource-conflict.error.js +0 -15
- package/esm/exception/resource-errors/resource-not-found.error.d.ts +0 -4
- package/esm/exception/resource-errors/resource-not-found.error.js +0 -15
- package/esm/exception/wrap-error.d.ts +0 -2
- package/esm/exception/wrap-error.js +0 -13
- package/esm/interfaces/query.interface.d.ts +0 -115
- package/esm/interfaces/query.interface.js +0 -203
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { ResponsiveMap } from '@opra/schema';
|
|
2
1
|
import { OpraURLSearchParams } from '@opra/url';
|
|
3
|
-
import {
|
|
2
|
+
import { HeadersMap } from './headers-map.js';
|
|
4
3
|
export class QueryContext {
|
|
5
4
|
service;
|
|
6
5
|
executionContext;
|
|
@@ -9,14 +8,21 @@ export class QueryContext {
|
|
|
9
8
|
headers;
|
|
10
9
|
parentValue;
|
|
11
10
|
resultPath;
|
|
11
|
+
responseHeaders;
|
|
12
12
|
response;
|
|
13
|
+
errors = [];
|
|
14
|
+
status;
|
|
13
15
|
userContext;
|
|
14
16
|
continueOnError;
|
|
15
17
|
constructor(args) {
|
|
16
|
-
Object.assign(this, args);
|
|
17
|
-
this.
|
|
18
|
+
// Object.assign(this, args);
|
|
19
|
+
this.service = args.service;
|
|
20
|
+
this.executionContext = args.executionContext;
|
|
21
|
+
this.query = args.query;
|
|
22
|
+
// this.response = new QueryResponse();
|
|
18
23
|
this.params = this.params || new OpraURLSearchParams();
|
|
19
|
-
this.headers =
|
|
24
|
+
this.headers = new HeadersMap(args.headers);
|
|
25
|
+
this.responseHeaders = new HeadersMap();
|
|
20
26
|
this.resultPath = this.resultPath || '';
|
|
21
27
|
}
|
|
22
28
|
get type() {
|
|
@@ -28,15 +34,3 @@ export class QueryContext {
|
|
|
28
34
|
return this.executionContext;
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
|
-
export class QueryResponse {
|
|
32
|
-
headers;
|
|
33
|
-
errors = [];
|
|
34
|
-
status;
|
|
35
|
-
value;
|
|
36
|
-
total;
|
|
37
|
-
constructor(args) {
|
|
38
|
-
if (args)
|
|
39
|
-
Object.assign(this, args);
|
|
40
|
-
this.headers = new ResponsiveMap(undefined, Array.from(Object.values(HttpHeaders)));
|
|
41
|
-
}
|
|
42
|
-
}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
export * from './types.js';
|
|
3
3
|
export * from './enums/index.js';
|
|
4
|
-
export * from './exception/index.js';
|
|
5
4
|
export * from './interfaces/execution-context.interface.js';
|
|
6
|
-
export * from './interfaces/query.interface.js';
|
|
7
5
|
export * from './interfaces/entity-service.interface.js';
|
|
8
6
|
export * from './implementation/query-context.js';
|
|
9
7
|
export * from './implementation/adapter.js';
|
package/esm/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
export * from './types.js';
|
|
3
3
|
export * from './enums/index.js';
|
|
4
|
-
export * from './exception/index.js';
|
|
5
4
|
export * from './interfaces/execution-context.interface.js';
|
|
6
|
-
export * from './interfaces/query.interface.js';
|
|
7
5
|
export * from './interfaces/entity-service.interface.js';
|
|
8
6
|
export * from './implementation/query-context.js';
|
|
9
7
|
export * from './implementation/adapter.js';
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { Maybe } from 'ts-gems';
|
|
2
|
+
import { IResource, OpraResource } from '@opra/schema';
|
|
2
3
|
import { EntityOutput } from '@sqb/connect';
|
|
3
4
|
import { QueryContext } from '../implementation/query-context.js';
|
|
4
5
|
export interface IEntityService {
|
|
5
6
|
processRequest(ctx: QueryContext): any;
|
|
6
7
|
}
|
|
7
|
-
export declare abstract class EntityResourceController<T
|
|
8
|
-
search(ctx: QueryContext): Promise<
|
|
9
|
-
get(ctx: QueryContext): Promise<Maybe<
|
|
10
|
-
count(ctx: QueryContext): Promise<
|
|
11
|
-
create(ctx: QueryContext): Promise<
|
|
12
|
-
update(ctx: QueryContext): Promise<Maybe<
|
|
8
|
+
export declare abstract class EntityResourceController<T, TOutput = EntityOutput<T>> implements IResource {
|
|
9
|
+
search(ctx: QueryContext): Promise<TOutput[]>;
|
|
10
|
+
get(ctx: QueryContext): Promise<Maybe<TOutput>>;
|
|
11
|
+
count(ctx: QueryContext): Promise<number>;
|
|
12
|
+
create(ctx: QueryContext): Promise<TOutput>;
|
|
13
|
+
update(ctx: QueryContext): Promise<Maybe<TOutput>>;
|
|
13
14
|
updateMany(ctx: QueryContext): Promise<Maybe<number>>;
|
|
14
15
|
delete(ctx: QueryContext): Promise<Maybe<boolean | number>>;
|
|
15
16
|
deleteMany(ctx: QueryContext): Promise<Maybe<number>>;
|
|
17
|
+
abstract init(service: OpraResource): void | Promise<void>;
|
|
16
18
|
abstract getService(ctx: QueryContext): IEntityService | Promise<IEntityService>;
|
|
17
19
|
}
|
|
@@ -1,15 +1,60 @@
|
|
|
1
1
|
import { Maybe } from 'ts-gems';
|
|
2
|
+
import { EntityResource, EntityType, OpraAnyQuery, OpraSchema } from '@opra/schema';
|
|
2
3
|
import { Expression } from '@opra/url';
|
|
3
4
|
import { QueryContext } from '../implementation/query-context.js';
|
|
4
5
|
import { IEntityService } from '../interfaces/entity-service.interface.js';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
data
|
|
10
|
-
|
|
6
|
+
import { EntityInput, EntityOutput } from '../types.js';
|
|
7
|
+
export interface JsonDataServiceOptions {
|
|
8
|
+
resourceName?: string;
|
|
9
|
+
defaultLimit?: number;
|
|
10
|
+
data?: any[];
|
|
11
|
+
}
|
|
12
|
+
export declare class JsonDataService<T, TOutput = EntityOutput<T>> implements IEntityService {
|
|
13
|
+
readonly resource: EntityResource;
|
|
14
|
+
private _status;
|
|
15
|
+
private _initError;
|
|
16
|
+
private _dbName;
|
|
17
|
+
private _initData?;
|
|
18
|
+
defaultLimit: number;
|
|
19
|
+
constructor(resource: EntityResource, options?: JsonDataServiceOptions);
|
|
20
|
+
get dataType(): EntityType;
|
|
21
|
+
get primaryKey(): string;
|
|
22
|
+
get resourceName(): string;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
processRequest(ctx: QueryContext): Promise<any>;
|
|
25
|
+
get(keyValue: any, options?: JsonDataService.GetOptions): Promise<Maybe<TOutput>>;
|
|
26
|
+
count(options?: JsonDataService.SearchOptions): Promise<number>;
|
|
27
|
+
search(options?: JsonDataService.SearchOptions): Promise<TOutput[]>;
|
|
28
|
+
create(data: EntityInput<T>, options?: JsonDataService.CreateOptions): Promise<TOutput>;
|
|
29
|
+
update(keyValue: any, data: EntityInput<T>, options?: JsonDataService.UpdateOptions): Promise<Maybe<TOutput>>;
|
|
30
|
+
updateMany(data: EntityInput<T>, options?: JsonDataService.UpdateManyOptions): Promise<number>;
|
|
31
|
+
delete(keyValue: any): Promise<boolean>;
|
|
32
|
+
deleteMany(options?: JsonDataService.DeleteManyOptions): Promise<number>;
|
|
33
|
+
private _waitInitializing;
|
|
34
|
+
protected _init(): Promise<void>;
|
|
35
|
+
protected _prepare(query: OpraAnyQuery): {
|
|
36
|
+
method: OpraSchema.EntityMethod;
|
|
37
|
+
options: any;
|
|
38
|
+
keyValue?: any;
|
|
39
|
+
values?: any;
|
|
40
|
+
args: any[];
|
|
41
|
+
};
|
|
42
|
+
protected _convertSelect(args: {
|
|
43
|
+
pick?: string[];
|
|
44
|
+
omit?: string[];
|
|
45
|
+
include?: string[];
|
|
46
|
+
}): string[];
|
|
47
|
+
protected _convertFilter(str: string | Expression | undefined | {}): any;
|
|
11
48
|
}
|
|
12
49
|
export declare namespace JsonDataService {
|
|
50
|
+
type CountOptions = {
|
|
51
|
+
filter?: string | Expression | {};
|
|
52
|
+
};
|
|
53
|
+
type CreateOptions = {
|
|
54
|
+
pick?: string[];
|
|
55
|
+
omit?: string[];
|
|
56
|
+
include?: string[];
|
|
57
|
+
};
|
|
13
58
|
type GetOptions = {
|
|
14
59
|
pick?: string[];
|
|
15
60
|
omit?: string[];
|
|
@@ -19,16 +64,12 @@ export declare namespace JsonDataService {
|
|
|
19
64
|
pick?: string[];
|
|
20
65
|
omit?: string[];
|
|
21
66
|
include?: string[];
|
|
67
|
+
filter?: any[];
|
|
68
|
+
sort?: string[];
|
|
22
69
|
limit?: number;
|
|
23
70
|
skip?: number;
|
|
24
71
|
distinct?: boolean;
|
|
25
|
-
|
|
26
|
-
filter?: string | Expression | {};
|
|
27
|
-
};
|
|
28
|
-
type CreateOptions = {
|
|
29
|
-
pick?: string[];
|
|
30
|
-
omit?: string[];
|
|
31
|
-
include?: string[];
|
|
72
|
+
count?: boolean;
|
|
32
73
|
};
|
|
33
74
|
type UpdateOptions = {
|
|
34
75
|
pick?: string[];
|
|
@@ -36,33 +77,9 @@ export declare namespace JsonDataService {
|
|
|
36
77
|
include?: string[];
|
|
37
78
|
};
|
|
38
79
|
type UpdateManyOptions = {
|
|
39
|
-
filter?:
|
|
80
|
+
filter?: any[];
|
|
40
81
|
};
|
|
41
82
|
type DeleteManyOptions = {
|
|
42
|
-
filter?:
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
export declare class JsonDataService<T, TOutput = EntityOutput<T>> implements IEntityService {
|
|
46
|
-
resourceName: string;
|
|
47
|
-
data: T[];
|
|
48
|
-
primaryKey: string;
|
|
49
|
-
constructor(args: JsonDataServiceAgs<T>);
|
|
50
|
-
processRequest(ctx: QueryContext): any;
|
|
51
|
-
get(keyValue: any, options?: JsonDataService.GetOptions): Maybe<TOutput>;
|
|
52
|
-
count(options?: JsonDataService.SearchOptions): Maybe<number>;
|
|
53
|
-
search(options?: JsonDataService.SearchOptions): Maybe<TOutput>[];
|
|
54
|
-
create(data: EntityInput<T>, options?: JsonDataService.CreateOptions): TOutput;
|
|
55
|
-
update(keyValue: any, data: EntityInput<T>, options?: JsonDataService.UpdateOptions): Maybe<TOutput>;
|
|
56
|
-
updateMany(data: EntityInput<T>, options?: JsonDataService.UpdateManyOptions): number;
|
|
57
|
-
delete(keyValue: any): boolean;
|
|
58
|
-
deleteMany(options?: JsonDataService.DeleteManyOptions): number;
|
|
59
|
-
static filterFields(obj: any, pick: string[] | undefined, omit: string[] | undefined, include: string[] | undefined): any;
|
|
60
|
-
static prepare(query: OpraQuery): {
|
|
61
|
-
method: QueryType;
|
|
62
|
-
options: any;
|
|
63
|
-
keyValue?: any;
|
|
64
|
-
values?: any;
|
|
65
|
-
args: any[];
|
|
83
|
+
filter?: any[];
|
|
66
84
|
};
|
|
67
|
-
static convertFilter(str: string | Expression | undefined | {}): any;
|
|
68
85
|
}
|