@azure-net/kit 0.6.6 → 0.7.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/dist/core/application/ProxyResourceService.d.ts +4 -0
- package/dist/core/application/ProxyResourceService.js +21 -0
- package/dist/core/application/index.d.ts +1 -1
- package/dist/core/application/index.js +1 -1
- package/dist/core/index.d.ts +5 -4
- package/dist/core/index.js +5 -4
- package/dist/core/infra/datasource/BaseDatasource.d.ts +16 -0
- package/dist/core/{datasource → infra/datasource}/BaseDatasource.js +0 -7
- package/dist/core/infra/resource/BaseResource.d.ts +10 -0
- package/dist/core/infra/resource/BaseResource.js +5 -0
- package/dist/core/infra/resource/index.d.ts +1 -0
- package/dist/core/infra/resource/index.js +1 -0
- package/dist/core/infra/response/BaseResponse.d.ts +30 -0
- package/dist/core/infra/response/BaseResponse.js +69 -0
- package/dist/core/provider/dependencies/ErrorHandler.d.ts +1 -1
- package/dist/core/provider/dependencies/ErrorHandler.js +1 -1
- package/package.json +1 -1
- package/dist/core/appLayers/AppLayers.d.ts +0 -6
- package/dist/core/appLayers/AppLayers.js +0 -7
- package/dist/core/appLayers/index.d.ts +0 -1
- package/dist/core/appLayers/index.js +0 -1
- package/dist/core/application/ResourceService.d.ts +0 -11
- package/dist/core/application/ResourceService.js +0 -13
- package/dist/core/datasource/BaseDatasource.d.ts +0 -33
- package/dist/core/response/BaseResponse.d.ts +0 -11
- package/dist/core/response/BaseResponse.js +0 -13
- /package/dist/core/{datasource → infra/datasource}/index.d.ts +0 -0
- /package/dist/core/{datasource → infra/datasource}/index.js +0 -0
- /package/dist/core/{httpService → infra/httpService}/HttpService.d.ts +0 -0
- /package/dist/core/{httpService → infra/httpService}/HttpService.js +0 -0
- /package/dist/core/{httpService → infra/httpService}/Statuses.d.ts +0 -0
- /package/dist/core/{httpService → infra/httpService}/Statuses.js +0 -0
- /package/dist/core/{httpService → infra/httpService}/index.d.ts +0 -0
- /package/dist/core/{httpService → infra/httpService}/index.js +0 -0
- /package/dist/core/{query → infra/query}/QueryBuilder.d.ts +0 -0
- /package/dist/core/{query → infra/query}/QueryBuilder.js +0 -0
- /package/dist/core/{query → infra/query}/index.d.ts +0 -0
- /package/dist/core/{query → infra/query}/index.js +0 -0
- /package/dist/core/{response → infra/response}/index.d.ts +0 -0
- /package/dist/core/{response → infra/response}/index.js +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class ProxyResourceService {
|
|
2
|
+
repository;
|
|
3
|
+
constructor(repo) {
|
|
4
|
+
this.repository = repo;
|
|
5
|
+
const proto = Object.getPrototypeOf(repo);
|
|
6
|
+
for (const name of Object.getOwnPropertyNames(proto)) {
|
|
7
|
+
if (name === 'constructor')
|
|
8
|
+
continue;
|
|
9
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, name);
|
|
10
|
+
if (!descriptor || typeof descriptor.value !== 'function')
|
|
11
|
+
continue;
|
|
12
|
+
if (name in this)
|
|
13
|
+
continue;
|
|
14
|
+
Object.defineProperty(this, name, {
|
|
15
|
+
value: descriptor.value.bind(repo),
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './ProxyResourceService.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './ProxyResourceService.js';
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export * from './infra/response/index.js';
|
|
2
|
+
export * from './infra/resource/index.js';
|
|
3
|
+
export * from './infra/httpService/index.js';
|
|
4
|
+
export * from './infra/datasource/index.js';
|
|
5
|
+
export * from './infra/query/index.js';
|
|
1
6
|
export * from './application/index.js';
|
|
2
|
-
export * from './response/index.js';
|
|
3
|
-
export * from './httpService/index.js';
|
|
4
|
-
export * from './datasource/index.js';
|
|
5
7
|
export * from './request/index.js';
|
|
6
|
-
export * from './query/index.js';
|
|
7
8
|
export * from './boundaryProvider/index.js';
|
package/dist/core/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export * from './infra/response/index.js';
|
|
2
|
+
export * from './infra/resource/index.js';
|
|
3
|
+
export * from './infra/httpService/index.js';
|
|
4
|
+
export * from './infra/datasource/index.js';
|
|
5
|
+
export * from './infra/query/index.js';
|
|
1
6
|
export * from './application/index.js';
|
|
2
|
-
export * from './response/index.js';
|
|
3
|
-
export * from './httpService/index.js';
|
|
4
|
-
export * from './datasource/index.js';
|
|
5
7
|
export * from './request/index.js';
|
|
6
|
-
export * from './query/index.js';
|
|
7
8
|
export * from './boundaryProvider/index.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HttpService, HttpServiceResponse } from '../httpService/HttpService.js';
|
|
2
|
+
import { QueryBuilder } from '../query/index.js';
|
|
3
|
+
export type CreateRequestCallbackType<T> = (params: {
|
|
4
|
+
http: HttpService;
|
|
5
|
+
query: QueryBuilder;
|
|
6
|
+
}) => Promise<HttpServiceResponse<T>>;
|
|
7
|
+
export declare class BaseHttpDatasource {
|
|
8
|
+
protected readonly httpClient: HttpService;
|
|
9
|
+
protected readonly query: QueryBuilder;
|
|
10
|
+
constructor(params: {
|
|
11
|
+
http?: HttpService;
|
|
12
|
+
query?: QueryBuilder;
|
|
13
|
+
});
|
|
14
|
+
private _createRawRequest;
|
|
15
|
+
readonly createRawRequest: <T>(callback: CreateRequestCallbackType<T>) => Promise<HttpServiceResponse<T>>;
|
|
16
|
+
}
|
|
@@ -7,13 +7,6 @@ export class BaseHttpDatasource {
|
|
|
7
7
|
this.httpClient = params.http ?? new HttpService({ baseUrl: '' });
|
|
8
8
|
this.query = params.query ?? new QueryBuilder();
|
|
9
9
|
}
|
|
10
|
-
async createRequest(callback) {
|
|
11
|
-
return await callback({ http: this.httpClient, query: this.query })
|
|
12
|
-
.then((response) => response)
|
|
13
|
-
.catch((err) => {
|
|
14
|
-
throw err;
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
10
|
async _createRawRequest(callback) {
|
|
18
11
|
return await callback({ http: this.httpClient, query: this.query }).catch((err) => {
|
|
19
12
|
throw err;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type IResource<T> = {
|
|
2
|
+
[K in keyof T as K extends string ? (T[K] extends (...args: unknown[]) => unknown ? never : K) : never]: T[K];
|
|
3
|
+
};
|
|
4
|
+
export interface IBaseResource {
|
|
5
|
+
toPlainObject(): IResource<this>;
|
|
6
|
+
}
|
|
7
|
+
export declare class Resource implements IBaseResource {
|
|
8
|
+
toPlainObject(): IResource<this>;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './BaseResource.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './BaseResource.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HttpServiceResponse } from '../../index.js';
|
|
2
|
+
type DeepKeys<T> = T extends object ? {
|
|
3
|
+
[K in keyof T & string]: T[K] extends object ? K | `${K}.${DeepKeys<T[K]>}` : K;
|
|
4
|
+
}[keyof T & string] : never;
|
|
5
|
+
type DeepValue<T, Path extends string> = Path extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? DeepValue<T[Key], Rest> : never : Path extends keyof T ? T[Path] : never;
|
|
6
|
+
type ResponseBuilderState<TData, TMeta = unknown> = {
|
|
7
|
+
data: TData;
|
|
8
|
+
meta: TMeta;
|
|
9
|
+
};
|
|
10
|
+
export declare class ResponseBuilder<TData = unknown, TMeta = object, TWrapper = TData> {
|
|
11
|
+
protected readonly response: HttpServiceResponse<TWrapper>;
|
|
12
|
+
protected state: ResponseBuilderState<TData, TMeta>;
|
|
13
|
+
constructor(response: HttpServiceResponse<TWrapper>);
|
|
14
|
+
protected unwrapData(data: TWrapper): TData;
|
|
15
|
+
toResource<TResource>(ResourceClass: new (data: TData) => {
|
|
16
|
+
toPlainObject(): TResource;
|
|
17
|
+
}): ResponseBuilder<TResource, TMeta, TWrapper>;
|
|
18
|
+
extract<TPath extends DeepKeys<TData>>(path: TPath): ResponseBuilder<DeepValue<TData, TPath>, TMeta, TWrapper>;
|
|
19
|
+
addMeta<TNewMeta extends Record<string, unknown>>(metaData: TNewMeta | ((current: TMeta) => TNewMeta)): ResponseBuilder<TData, TMeta & TNewMeta, TWrapper>;
|
|
20
|
+
getData(): TData;
|
|
21
|
+
get(): {
|
|
22
|
+
data: TData;
|
|
23
|
+
meta: TMeta;
|
|
24
|
+
};
|
|
25
|
+
getFlatten(): {
|
|
26
|
+
data: TData;
|
|
27
|
+
} & TMeta;
|
|
28
|
+
getRaw(): HttpServiceResponse<TWrapper>;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { HttpServiceResponse } from '../../index.js';
|
|
2
|
+
export class ResponseBuilder {
|
|
3
|
+
response;
|
|
4
|
+
state;
|
|
5
|
+
constructor(response) {
|
|
6
|
+
this.response = response;
|
|
7
|
+
this.state = {
|
|
8
|
+
data: this.unwrapData(response.data),
|
|
9
|
+
meta: {}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
unwrapData(data) {
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
toResource(ResourceClass) {
|
|
16
|
+
const resource = new ResourceClass(this.state.data);
|
|
17
|
+
const newResponse = new ResponseBuilder(this.response);
|
|
18
|
+
newResponse.state = {
|
|
19
|
+
...this.state,
|
|
20
|
+
data: resource.toPlainObject()
|
|
21
|
+
};
|
|
22
|
+
return newResponse;
|
|
23
|
+
}
|
|
24
|
+
extract(path) {
|
|
25
|
+
const keys = path.split('.');
|
|
26
|
+
let result = this.state.data;
|
|
27
|
+
for (const key of keys) {
|
|
28
|
+
if (result && typeof result === 'object' && key in result) {
|
|
29
|
+
result = result[key];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new Error(`Path "${path}" not found in response data`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const newResponse = new ResponseBuilder(this.response);
|
|
36
|
+
newResponse.state = {
|
|
37
|
+
...this.state,
|
|
38
|
+
data: result
|
|
39
|
+
};
|
|
40
|
+
return newResponse;
|
|
41
|
+
}
|
|
42
|
+
addMeta(metaData) {
|
|
43
|
+
const newMeta = typeof metaData === 'function' ? metaData(this.state.meta) : metaData;
|
|
44
|
+
const newResponse = new ResponseBuilder(this.response);
|
|
45
|
+
newResponse.state = {
|
|
46
|
+
...this.state,
|
|
47
|
+
meta: { ...this.state.meta, ...newMeta }
|
|
48
|
+
};
|
|
49
|
+
return newResponse;
|
|
50
|
+
}
|
|
51
|
+
getData() {
|
|
52
|
+
return this.state.data;
|
|
53
|
+
}
|
|
54
|
+
get() {
|
|
55
|
+
return {
|
|
56
|
+
data: this.state.data,
|
|
57
|
+
meta: this.state.meta
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
getFlatten() {
|
|
61
|
+
return {
|
|
62
|
+
data: this.state.data,
|
|
63
|
+
...this.state.meta
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
getRaw() {
|
|
67
|
+
return this.response;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseRequest, type RequestErrors } from '../../request/index.js';
|
|
2
|
-
import { HttpServiceError } from '../../httpService/index.js';
|
|
2
|
+
import { HttpServiceError } from '../../infra/httpService/index.js';
|
|
3
3
|
export type AppErrorType = 'http' | 'request' | 'app' | 'abort';
|
|
4
4
|
export interface AppError<T = unknown, D = never> {
|
|
5
5
|
type: AppErrorType;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './AppLayers.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './AppLayers.js';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { HttpServiceResponse } from '../httpService/index.js';
|
|
2
|
-
export declare class ResourceService {
|
|
3
|
-
protected transformResponse<TData extends object, TResult = TData, TKey extends keyof TData | undefined = undefined>(requestPromise: Promise<HttpServiceResponse<TData>>, options?: {
|
|
4
|
-
responseModel?: {
|
|
5
|
-
new (response: HttpServiceResponse<TData>): {
|
|
6
|
-
json(): TResult;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
key?: TKey;
|
|
10
|
-
}): Promise<TKey extends keyof TData ? TData[TKey] : TResult>;
|
|
11
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { HttpServiceResponse } from '../httpService/index.js';
|
|
2
|
-
export class ResourceService {
|
|
3
|
-
async transformResponse(requestPromise, options) {
|
|
4
|
-
const response = await requestPromise;
|
|
5
|
-
if (options?.responseModel) {
|
|
6
|
-
return new options.responseModel(response).json();
|
|
7
|
-
}
|
|
8
|
-
if (options?.key) {
|
|
9
|
-
return response.data[options.key];
|
|
10
|
-
}
|
|
11
|
-
return response.data;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { HttpService, HttpServiceResponse } from '../httpService/HttpService.js';
|
|
2
|
-
import { QueryBuilder } from '../query/index.js';
|
|
3
|
-
type ApplyWrapper<TWrapper, T, TDataKey extends keyof TWrapper> = TWrapper extends Record<TDataKey, unknown> ? Omit<TWrapper, TDataKey> & {
|
|
4
|
-
[K in TDataKey]: T;
|
|
5
|
-
} : T;
|
|
6
|
-
export interface IHttpDatasource<TWrapper = never, TDataKey extends keyof TWrapper = never> {
|
|
7
|
-
createRequest<T>(callback: <J = ApplyWrapper<TWrapper, T, TDataKey>>(params: {
|
|
8
|
-
http: HttpService;
|
|
9
|
-
query: QueryBuilder;
|
|
10
|
-
}) => Promise<HttpServiceResponse<J>>): Promise<HttpServiceResponse<ApplyWrapper<TWrapper, T, TDataKey>>>;
|
|
11
|
-
createRawRequest<T>(callback: (params: {
|
|
12
|
-
http: HttpService;
|
|
13
|
-
query: QueryBuilder;
|
|
14
|
-
}) => Promise<HttpServiceResponse<T>>): Promise<HttpServiceResponse<T>>;
|
|
15
|
-
}
|
|
16
|
-
export declare class BaseHttpDatasource<TWrapper = never, TDataKey extends keyof TWrapper = never> implements IHttpDatasource<TWrapper, TDataKey> {
|
|
17
|
-
protected readonly httpClient: HttpService;
|
|
18
|
-
protected readonly query: QueryBuilder;
|
|
19
|
-
constructor(params: {
|
|
20
|
-
http?: HttpService;
|
|
21
|
-
query?: QueryBuilder;
|
|
22
|
-
});
|
|
23
|
-
createRequest<T>(callback: <J = ApplyWrapper<TWrapper, T, TDataKey>>(params: {
|
|
24
|
-
http: HttpService;
|
|
25
|
-
query: QueryBuilder;
|
|
26
|
-
}) => Promise<HttpServiceResponse<J>>): Promise<HttpServiceResponse<ApplyWrapper<TWrapper, T, TDataKey>>>;
|
|
27
|
-
private _createRawRequest;
|
|
28
|
-
readonly createRawRequest: <T>(callback: (params: {
|
|
29
|
-
http: HttpService;
|
|
30
|
-
query: QueryBuilder;
|
|
31
|
-
}) => Promise<HttpServiceResponse<T>>) => Promise<HttpServiceResponse<T>>;
|
|
32
|
-
}
|
|
33
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { HttpServiceResponse } from '../httpService/index.js';
|
|
2
|
-
export interface IBaseResponse<T, D = T> {
|
|
3
|
-
transform(data: HttpServiceResponse<T>): D;
|
|
4
|
-
json(): D;
|
|
5
|
-
}
|
|
6
|
-
export declare class BaseResponse<T, D = T> implements IBaseResponse<T, D> {
|
|
7
|
-
protected response: HttpServiceResponse<T>;
|
|
8
|
-
constructor(response: HttpServiceResponse<T>);
|
|
9
|
-
transform(response: HttpServiceResponse<T>): D;
|
|
10
|
-
json(): D;
|
|
11
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { HttpServiceResponse } from '../httpService/index.js';
|
|
2
|
-
export class BaseResponse {
|
|
3
|
-
response;
|
|
4
|
-
constructor(response) {
|
|
5
|
-
this.response = response;
|
|
6
|
-
}
|
|
7
|
-
transform(response) {
|
|
8
|
-
return response.data;
|
|
9
|
-
}
|
|
10
|
-
json() {
|
|
11
|
-
return this.transform(this.response);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|