@azure-net/kit 3.1.0 → 3.9.2
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/README.md +2 -2
- package/dist/core/delivery/index.d.ts +1 -4
- package/dist/core/delivery/index.js +1 -4
- package/dist/core/delivery/injectableDependencies/AsyncHelpers.d.ts +28 -30
- package/dist/core/delivery/injectableDependencies/AsyncHelpers.js +80 -116
- package/dist/core/delivery/injectableDependencies/ErrorHandler.d.ts +3 -21
- package/dist/core/delivery/injectableDependencies/ErrorHandler.js +11 -42
- package/dist/core/delivery/schema/Schema.d.ts +8 -1
- package/dist/core/delivery/schema/Schema.js +12 -3
- package/dist/core/delivery.d.ts +5 -0
- package/dist/core/delivery.js +5 -0
- package/dist/core/errors.d.ts +4 -0
- package/dist/core/errors.js +4 -0
- package/dist/core/index.d.ts +7 -8
- package/dist/core/index.js +7 -8
- package/dist/core/infra/datasource/BaseDatasource.d.ts +11 -11
- package/dist/core/infra/datasource/BaseDatasource.js +4 -4
- package/dist/core/infra/httpService/HttpServiceInstance.d.ts +90 -0
- package/dist/core/infra/httpService/HttpServiceInstance.js +340 -0
- package/dist/core/infra/httpService/index.d.ts +1 -1
- package/dist/core/infra/httpService/index.js +1 -1
- package/dist/core/infra/query/QueryBuilder.d.ts +9 -21
- package/dist/core/infra/query/QueryBuilder.js +63 -50
- package/dist/core/infra/response/BaseResponse.js +3 -2
- package/dist/core/infra.d.ts +6 -0
- package/dist/core/infra.js +6 -0
- package/dist/core/shared/appError/AppError.d.ts +30 -0
- package/dist/core/shared/appError/AppError.js +66 -0
- package/dist/core/shared/appEventBus/EventBus.d.ts +1 -1
- package/dist/core/shared/appEventBus/EventBus.js +3 -3
- package/dist/core/shared/boundaryProvider/Provider.d.ts +2 -2
- package/dist/core/shared/boundaryProvider/Provider.js +16 -9
- package/dist/core/shared/classMirror/ClassMirror.d.ts +7 -2
- package/dist/core/shared/classMirror/ClassMirror.js +34 -15
- package/dist/core/shared/cookie/UniversalCookie.js +9 -11
- package/dist/core/shared/middleware/Middleware.js +12 -8
- package/dist/core/svelte/ActiveForm/ActiveForm.svelte.d.ts +10 -6
- package/dist/core/svelte/ActiveForm/ActiveForm.svelte.js +47 -41
- package/dist/core/svelte/AsyncSignal/AsyncSignal.svelte.d.ts +0 -1
- package/dist/core/svelte/AsyncSignal/AsyncSignal.svelte.js +21 -30
- package/dist/core/svelte/Query/Query.svelte.d.ts +11 -12
- package/dist/core/svelte/Query/Query.svelte.js +43 -55
- package/dist/core/ui/onClickOutside/OnClickOutside.js +1 -1
- package/dist/core/ui/scrollTo/index.js +2 -2
- package/dist/edges/context/index.d.ts +1 -1
- package/dist/edges/context/index.js +1 -1
- package/dist/edges/dev/index.d.ts +1 -1
- package/dist/edges/dev/index.js +1 -1
- package/dist/edges/index.d.ts +1 -1
- package/dist/edges/index.js +1 -1
- package/dist/edges/plugin/index.d.ts +1 -1
- package/dist/edges/plugin/index.js +1 -1
- package/dist/edges/server/index.d.ts +1 -1
- package/dist/edges/server/index.js +1 -1
- package/dist/edges/state/index.d.ts +1 -1
- package/dist/edges/state/index.js +1 -1
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +1 -1
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.js +2 -1
- package/package.json +45 -47
- package/dist/core/delivery/serverAction/CreateServerAction.d.ts +0 -15
- package/dist/core/delivery/serverAction/CreateServerAction.js +0 -22
- package/dist/core/delivery/serverAction/index.d.ts +0 -1
- package/dist/core/delivery/serverAction/index.js +0 -1
- package/dist/core/infra/httpService/HttpService.d.ts +0 -74
- package/dist/core/infra/httpService/HttpService.js +0 -164
- package/dist/core/shared/eventBus/EventBus.d.ts +0 -87
- package/dist/core/shared/eventBus/EventBus.js +0 -227
- package/dist/core/shared/eventBus/index.d.ts +0 -1
- package/dist/core/shared/eventBus/index.js +0 -1
package/README.md
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
## 🚀 What's included?
|
|
12
12
|
|
|
13
|
-
- **Built-in store** — flexible and SSR-friendly state management powered by [edges
|
|
14
|
-
- **Localization and translation** — ready-to-use i18n solution ([edges-
|
|
13
|
+
- **Built-in store** — flexible and SSR-friendly state management powered by [@azure-net/edges](https://github.com/Pixel1917/edge-s).
|
|
14
|
+
- **Localization and translation** — ready-to-use i18n solution ([@azure-net/edges-translations](https://github.com/Pixel1917/edges-svelte-translations)) for multilingual applications.
|
|
15
15
|
- **Extensive utilities** — for working with text, objects, dates, and common tasks.
|
|
16
16
|
- **Data validation** — handy rules and validators.
|
|
17
17
|
- **Reusable base abstractions** — `Repositories`, `Services`, `Providers`, and `Datasources` for quick setup and reuse.
|
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { createErrorHandler } from './ErrorHandler.js';
|
|
2
|
+
import { type AppError, type IAppError } from '../../shared/appError/AppError.js';
|
|
3
|
+
export interface AsyncActionResponse<T, D = never, ErrorResult = Record<never, never>> {
|
|
3
4
|
success: boolean;
|
|
4
5
|
response: T;
|
|
5
|
-
error?:
|
|
6
|
+
error?: IAppError<D> & ErrorResult;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
export interface AsyncHelperRetry {
|
|
9
|
+
can: boolean;
|
|
10
|
+
call?: () => Promise<Error | void>;
|
|
11
|
+
}
|
|
12
|
+
type Action<Res> = () => Promise<Res>;
|
|
13
|
+
export interface AsyncActionSettings<Res = never, Req = never, ErrorResult = AppError<Error>> {
|
|
14
|
+
beforeSend?: (actions: {
|
|
15
|
+
next: () => void;
|
|
16
|
+
abort: (reason?: Error) => void;
|
|
17
|
+
}) => void | Promise<void>;
|
|
18
|
+
onSuccess?: (result: AsyncActionResponse<Res, never, ErrorResult>) => Promise<unknown> | unknown;
|
|
19
|
+
onError?: (result: AsyncActionResponse<never, Req, ErrorResult>) => Promise<unknown> | unknown;
|
|
20
|
+
fallbackResponse?: Res;
|
|
21
|
+
}
|
|
22
|
+
export interface AsyncResourceSettings<Res = never, Req = never, ErrorResult = AppError<Error>> extends AsyncActionSettings<Res, Req, ErrorResult> {
|
|
23
|
+
reject?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare class AsyncHelperError extends Error {
|
|
26
|
+
}
|
|
27
|
+
export declare const createAsyncHelpers: <ErrorResult extends object>(opts?: {
|
|
28
|
+
handler?: ReturnType<typeof createErrorHandler<ErrorResult>>;
|
|
10
29
|
}) => {
|
|
11
|
-
createAsyncAction: <Res =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
onError?: (result: AsyncActionResponse<never, Req, Custom>) => Promise<unknown> | unknown;
|
|
15
|
-
reject?: boolean;
|
|
16
|
-
abort?: {
|
|
17
|
-
condition: boolean;
|
|
18
|
-
onAbort?: () => void;
|
|
19
|
-
};
|
|
20
|
-
fallbackResponse?: Res;
|
|
21
|
-
maxRetries?: number;
|
|
22
|
-
}) => Promise<AsyncActionResponse<Res, Req, Custom>>;
|
|
23
|
-
createAsyncResource: <Res, Req_1 = unknown>(action: ActionOrThunk<Res>, args?: {
|
|
24
|
-
beforeSend?: (next: () => void, abort: () => void) => void | Promise<void>;
|
|
25
|
-
onSuccess?: (result: Res) => Promise<unknown> | unknown;
|
|
26
|
-
onError?: (error: AppError<Req_1, Custom>) => Promise<unknown> | unknown;
|
|
27
|
-
reject?: boolean;
|
|
28
|
-
abort?: {
|
|
29
|
-
condition: boolean;
|
|
30
|
-
onAbort?: () => void;
|
|
31
|
-
};
|
|
32
|
-
fallbackResponse?: Res;
|
|
33
|
-
maxRetries?: number;
|
|
34
|
-
}) => Promise<Res>;
|
|
30
|
+
createAsyncAction: <Res = never, Req = never>(action: Action<Res>, args?: AsyncActionSettings<Res, Req, ErrorResult>) => Promise<AsyncActionResponse<Res, Req, ErrorResult>>;
|
|
31
|
+
createAsyncResource: <Res = never, Req_1 = never>(action: Action<Res>, args?: AsyncResourceSettings<Res, Req_1, ErrorResult>) => Promise<Res>;
|
|
32
|
+
errorParser: <T = unknown>(error: Error, asyncHelperRetry?: AsyncHelperRetry) => Promise<IAppError<T> & ErrorResult>;
|
|
35
33
|
};
|
|
36
34
|
export {};
|
|
@@ -1,57 +1,74 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createErrorHandler } from './ErrorHandler.js';
|
|
2
|
+
import {} from '../../shared/appError/AppError.js';
|
|
3
|
+
export class AsyncHelperError extends Error {
|
|
4
|
+
}
|
|
3
5
|
export const createAsyncHelpers = (opts) => {
|
|
4
|
-
const errorParser = opts?.
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
success: false,
|
|
17
|
-
error: abortError,
|
|
18
|
-
response: args?.fallbackResponse
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
if (args?.beforeSend) {
|
|
22
|
-
const beforeSendResult = await new Promise((resolve) => {
|
|
23
|
-
const next = () => resolve('next');
|
|
24
|
-
const abort = () => resolve('abort');
|
|
25
|
-
Promise.resolve(args.beforeSend(next, abort)).catch((err) => {
|
|
26
|
-
console.error('Error in beforeSend:', err);
|
|
27
|
-
resolve('abort');
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
if (beforeSendResult === 'abort') {
|
|
31
|
-
const abortError = {
|
|
32
|
-
type: 'abort',
|
|
33
|
-
message: 'Aborted in beforeSend',
|
|
34
|
-
original: new Error('Aborted in beforeSend')
|
|
35
|
-
};
|
|
36
|
-
if (args?.reject)
|
|
37
|
-
throw abortError;
|
|
38
|
-
return {
|
|
39
|
-
success: false,
|
|
40
|
-
error: abortError,
|
|
41
|
-
response: args?.fallbackResponse
|
|
42
|
-
};
|
|
6
|
+
const errorParser = opts?.handler ?? createErrorHandler();
|
|
7
|
+
const normalizeError = (err) => (err instanceof Error ? err : new Error(String(err)));
|
|
8
|
+
const prepareErrors = async (error, retry) => {
|
|
9
|
+
let retryResult = undefined;
|
|
10
|
+
const retryFunc = async () => {
|
|
11
|
+
if (retry) {
|
|
12
|
+
return await retry()
|
|
13
|
+
.then((res) => {
|
|
14
|
+
retryResult = res;
|
|
15
|
+
return undefined;
|
|
16
|
+
})
|
|
17
|
+
.catch((err) => normalizeError(err));
|
|
43
18
|
}
|
|
44
|
-
}
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
19
|
+
};
|
|
20
|
+
const parsedError = await errorParser(normalizeError(error), { can: !!retry, call: retry ? () => retryFunc() : undefined });
|
|
21
|
+
return { error: parsedError, retryResult };
|
|
22
|
+
};
|
|
23
|
+
const beforeSendResolver = async (settings) => {
|
|
24
|
+
if (!settings?.beforeSend)
|
|
25
|
+
return undefined;
|
|
26
|
+
let abortReason;
|
|
27
|
+
let aborted = false;
|
|
28
|
+
await new Promise((resolve) => {
|
|
29
|
+
let settled = false;
|
|
30
|
+
const beforeSend = settings.beforeSend;
|
|
31
|
+
const guardTimer = setTimeout(() => {
|
|
32
|
+
settle(true);
|
|
33
|
+
}, 30000);
|
|
34
|
+
const settle = (isAbort, reason) => {
|
|
35
|
+
if (settled)
|
|
36
|
+
return;
|
|
37
|
+
settled = true;
|
|
38
|
+
clearTimeout(guardTimer);
|
|
39
|
+
aborted = isAbort;
|
|
40
|
+
abortReason = reason;
|
|
41
|
+
resolve();
|
|
42
|
+
};
|
|
43
|
+
const next = () => settle(false);
|
|
44
|
+
const abort = (reason) => settle(true, reason);
|
|
45
|
+
try {
|
|
46
|
+
const maybePromise = beforeSend({ next, abort });
|
|
47
|
+
if (maybePromise && typeof maybePromise.then === 'function') {
|
|
48
|
+
maybePromise.then(() => settle(false), (err) => settle(true, normalizeError(err)));
|
|
49
|
+
return;
|
|
52
50
|
}
|
|
51
|
+
settle(false);
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
settle(true, normalizeError(err));
|
|
53
55
|
}
|
|
54
|
-
|
|
56
|
+
});
|
|
57
|
+
if (!aborted)
|
|
58
|
+
return undefined;
|
|
59
|
+
const { error } = await prepareErrors(abortReason ?? new AsyncHelperError('Aborted in beforeSend'));
|
|
60
|
+
return {
|
|
61
|
+
success: false,
|
|
62
|
+
error,
|
|
63
|
+
response: undefined
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
const createAsyncAction = async (action, args) => {
|
|
67
|
+
const beforeSendResult = await beforeSendResolver(args);
|
|
68
|
+
if (beforeSendResult)
|
|
69
|
+
return beforeSendResult;
|
|
70
|
+
const req = async () => {
|
|
71
|
+
const response = await Promise.resolve(action());
|
|
55
72
|
const result = { response, success: true };
|
|
56
73
|
await args?.onSuccess?.(result);
|
|
57
74
|
return result;
|
|
@@ -60,83 +77,30 @@ export const createAsyncHelpers = (opts) => {
|
|
|
60
77
|
return await req();
|
|
61
78
|
}
|
|
62
79
|
catch (err) {
|
|
63
|
-
|
|
64
|
-
const retry = async () => await req(true)
|
|
65
|
-
.then((res) => (retryResult = res))
|
|
66
|
-
.catch(() => undefined);
|
|
67
|
-
const error = await errorParser(err, async () => await retry());
|
|
80
|
+
const { error, retryResult } = await prepareErrors(normalizeError(err), async () => await req());
|
|
68
81
|
if (retryResult) {
|
|
69
82
|
return retryResult;
|
|
70
83
|
}
|
|
71
|
-
const { bus } = AppEvents();
|
|
72
|
-
bus.publish('OnAsyncHelperError', error);
|
|
73
84
|
const result = { error, response: args?.fallbackResponse, success: false };
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
85
|
+
try {
|
|
86
|
+
await args?.onError?.(result);
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
throw await errorParser(new AsyncHelperError('onError caught exception', { cause: normalizeError(err) }));
|
|
90
|
+
}
|
|
77
91
|
return result;
|
|
78
92
|
}
|
|
79
93
|
};
|
|
80
94
|
const createAsyncResource = async (action, args) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
if (args?.beforeSend) {
|
|
86
|
-
const beforeSendResult = await new Promise((resolve) => {
|
|
87
|
-
const next = () => resolve('next');
|
|
88
|
-
const abort = () => resolve('abort');
|
|
89
|
-
Promise.resolve(args.beforeSend(next, abort)).catch((err) => {
|
|
90
|
-
console.error('Error in beforeSend:', err);
|
|
91
|
-
resolve('abort');
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
if (beforeSendResult === 'abort') {
|
|
95
|
-
if (args?.reject) {
|
|
96
|
-
throw {
|
|
97
|
-
type: 'abort',
|
|
98
|
-
message: 'Aborted in beforeSend',
|
|
99
|
-
original: new Error('Aborted in beforeSend')
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
return args.fallbackResponse;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
const maxRetries = args?.maxRetries ?? 3;
|
|
106
|
-
let retries = 0;
|
|
107
|
-
const req = async (isRetry = false) => {
|
|
108
|
-
if (isRetry) {
|
|
109
|
-
retries++;
|
|
110
|
-
if (retries > maxRetries) {
|
|
111
|
-
return Promise.reject(Error('Max retries reached'));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
const response = await Promise.resolve(typeof action === 'function' ? action() : action);
|
|
115
|
-
await args?.onSuccess?.(response);
|
|
116
|
-
return response;
|
|
117
|
-
};
|
|
118
|
-
try {
|
|
119
|
-
return await req();
|
|
120
|
-
}
|
|
121
|
-
catch (err) {
|
|
122
|
-
let retryResult;
|
|
123
|
-
const retry = async () => await req(true)
|
|
124
|
-
.then((res) => (retryResult = res))
|
|
125
|
-
.catch(() => undefined);
|
|
126
|
-
const error = await errorParser(err, async () => await retry());
|
|
127
|
-
if (retryResult) {
|
|
128
|
-
return retryResult;
|
|
129
|
-
}
|
|
130
|
-
const { bus } = AppEvents();
|
|
131
|
-
bus.publish('OnAsyncHelperError', error);
|
|
132
|
-
await args?.onError?.(error);
|
|
133
|
-
if (args?.reject)
|
|
134
|
-
throw error;
|
|
135
|
-
return args?.fallbackResponse;
|
|
95
|
+
const result = await createAsyncAction(action, args);
|
|
96
|
+
if (!result.success && args?.reject) {
|
|
97
|
+
throw result.error;
|
|
136
98
|
}
|
|
99
|
+
return result.response;
|
|
137
100
|
};
|
|
138
101
|
return {
|
|
139
102
|
createAsyncAction,
|
|
140
|
-
createAsyncResource
|
|
103
|
+
createAsyncResource,
|
|
104
|
+
errorParser
|
|
141
105
|
};
|
|
142
106
|
};
|
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
export interface AppError<T = unknown, CustomErrorField = never> {
|
|
5
|
-
type: AppErrorType;
|
|
6
|
-
message: string;
|
|
7
|
-
fields?: RequestErrors<T>;
|
|
8
|
-
status?: number;
|
|
9
|
-
original?: HttpServiceError<T> | SchemaFail<T> | Error;
|
|
10
|
-
custom?: CustomErrorField;
|
|
11
|
-
retry?: () => unknown;
|
|
12
|
-
}
|
|
13
|
-
export type ErrorType<T = unknown> = Error | HttpServiceError<T> | SchemaFail<T>;
|
|
14
|
-
export declare const baseParseHttpError: <T = unknown, D = never>(error: HttpServiceError<T>, retry?: () => unknown | Promise<unknown>) => Promise<AppError<T, D>>;
|
|
15
|
-
export declare const baseParseSchemaError: <SchemaData = unknown, D = never>(error: SchemaFail<SchemaData>, retry?: () => unknown | Promise<unknown>) => Promise<AppError<SchemaData, D>>;
|
|
16
|
-
export declare const baseParseBaseError: <D = never>(error: Error, retry?: () => unknown | Promise<unknown>) => Promise<AppError<never, D>>;
|
|
17
|
-
export declare const createErrorParser: <BaseError = unknown, Custom = unknown>(parsers?: {
|
|
18
|
-
parseBaseError?: typeof baseParseBaseError<Custom>;
|
|
19
|
-
parseHttpError?: typeof baseParseHttpError<BaseError, Custom>;
|
|
20
|
-
parseSchemaError?: typeof baseParseSchemaError<BaseError, Custom>;
|
|
21
|
-
}) => (<T = unknown>(error: ErrorType<BaseError>, retry?: () => unknown | Promise<unknown>) => Promise<AppError<T, Custom>>);
|
|
1
|
+
import { AppError, type IAppError } from '../../shared/appError/AppError.js';
|
|
2
|
+
import type { AsyncHelperRetry } from './AsyncHelpers.js';
|
|
3
|
+
export declare const createErrorHandler: <CustomData extends object>(handle?: <T = unknown>(error: AppError<T>, asyncHelperRetry: AsyncHelperRetry) => Promise<IAppError<T> & CustomData>) => <T = unknown>(error: Error, asyncHelperRetry?: AsyncHelperRetry) => Promise<IAppError<T> & CustomData>;
|
|
@@ -1,45 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return { ...err, retry: undefined, original: undefined };
|
|
12
|
-
};
|
|
13
|
-
export const baseParseSchemaError = async (error, retry) => {
|
|
14
|
-
const err = {
|
|
15
|
-
type: 'schema',
|
|
16
|
-
message: 'schema validation error',
|
|
17
|
-
status: 422,
|
|
18
|
-
fields: error.getErrors(),
|
|
19
|
-
original: error,
|
|
20
|
-
retry
|
|
21
|
-
};
|
|
22
|
-
return { ...err, retry: undefined, original: undefined };
|
|
23
|
-
};
|
|
24
|
-
export const baseParseBaseError = async (error, retry) => {
|
|
25
|
-
const err = {
|
|
26
|
-
type: 'app',
|
|
27
|
-
message: error.message,
|
|
28
|
-
original: error,
|
|
29
|
-
retry
|
|
30
|
-
};
|
|
31
|
-
return { ...err, retry: undefined, original: undefined };
|
|
32
|
-
};
|
|
33
|
-
export const createErrorParser = (parsers) => {
|
|
34
|
-
return async (error, retry) => {
|
|
35
|
-
const { parseBaseError = baseParseBaseError, parseHttpError = baseParseHttpError, parseSchemaError = baseParseSchemaError } = parsers ?? {};
|
|
36
|
-
switch (true) {
|
|
37
|
-
case error instanceof HttpServiceError:
|
|
38
|
-
return (await parseHttpError(error, retry));
|
|
39
|
-
case error instanceof SchemaFail:
|
|
40
|
-
return (await parseSchemaError(error, retry));
|
|
41
|
-
default:
|
|
42
|
-
return (await parseBaseError(error, retry));
|
|
1
|
+
import { AppError } from '../../shared/appError/AppError.js';
|
|
2
|
+
export const createErrorHandler = (handle) => {
|
|
3
|
+
return async (error, asyncHelperRetry) => {
|
|
4
|
+
const appError = new AppError(error);
|
|
5
|
+
if (handle) {
|
|
6
|
+
const handled = await handle(appError, asyncHelperRetry ?? { can: false });
|
|
7
|
+
if (handled?.appErrorConvert) {
|
|
8
|
+
return handled;
|
|
9
|
+
}
|
|
10
|
+
throw new Error('Method "handle" must return result of "toPlainObject" method in AppError');
|
|
43
11
|
}
|
|
12
|
+
return appError.toPlainObject();
|
|
44
13
|
};
|
|
45
14
|
};
|
|
@@ -24,9 +24,16 @@ type ValidationErrors<Errors> = Errors extends ReadonlyArray<infer U> ? Validati
|
|
|
24
24
|
} : ValidationMessage;
|
|
25
25
|
export type RequestErrors<SchemaData> = Partial<ValidationErrors<SchemaData>>;
|
|
26
26
|
export type RequestRules<SchemaData> = Partial<Record<DeepKeys<SchemaData>, ValidationRuleResult<SchemaData>[]>>;
|
|
27
|
-
export
|
|
27
|
+
export interface ISchemaError<SchemaData> extends Error {
|
|
28
|
+
message: string;
|
|
29
|
+
data: RequestErrors<SchemaData>;
|
|
30
|
+
}
|
|
31
|
+
export declare class SchemaFail<SchemaData> extends Error implements ISchemaError<SchemaData> {
|
|
28
32
|
private _errors;
|
|
33
|
+
data: RequestErrors<SchemaData>;
|
|
34
|
+
message: string;
|
|
29
35
|
constructor(_errors: RequestErrors<SchemaData>);
|
|
36
|
+
getSelfTypedData<SelfTypedData = unknown>(): RequestErrors<SelfTypedData>;
|
|
30
37
|
getErrors(): Partial<ValidationErrors<SchemaData>>;
|
|
31
38
|
}
|
|
32
39
|
interface SchemaBuilder<SchemaData, Rules = unknown, TransformResult = SchemaData, CustomMethods = unknown> {
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import { FormDataUtil } from 'azure-net
|
|
2
|
-
|
|
1
|
+
import { FormDataUtil } from '@azure-net/tools';
|
|
2
|
+
import { AzureNetKitInternalError } from '../../shared/appError/AppError.js';
|
|
3
|
+
export class SchemaFail extends Error {
|
|
3
4
|
_errors;
|
|
5
|
+
data;
|
|
6
|
+
message;
|
|
4
7
|
constructor(_errors) {
|
|
8
|
+
super('Validation failed');
|
|
5
9
|
this._errors = _errors;
|
|
10
|
+
this.message = 'Validation failed';
|
|
11
|
+
this.data = _errors;
|
|
12
|
+
}
|
|
13
|
+
getSelfTypedData() {
|
|
14
|
+
return this.data;
|
|
6
15
|
}
|
|
7
16
|
getErrors() {
|
|
8
17
|
return this._errors;
|
|
@@ -67,7 +76,7 @@ class SchemaBuilderImpl {
|
|
|
67
76
|
let _errors = {};
|
|
68
77
|
let _isValid = true;
|
|
69
78
|
if (typeof _preparedData !== 'object') {
|
|
70
|
-
throw
|
|
79
|
+
throw new AzureNetKitInternalError('[Schema] Data in "from" method can be only valid object or formData.');
|
|
71
80
|
}
|
|
72
81
|
const validated = (params) => {
|
|
73
82
|
_isValid = true;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createPresenter, createStore, createPresenterFactory, createStoreFactory, clearCache } from '../edges/index.js';
|
|
2
|
+
export { createAsyncHelpers, type AsyncHelperRetry, type AsyncResourceSettings, type AsyncActionResponse } from './delivery/injectableDependencies/AsyncHelpers.js';
|
|
3
|
+
export { createErrorHandler } from './delivery/injectableDependencies/ErrorHandler.js';
|
|
4
|
+
export { createSchemaFactory, schema, type Schema, type RequestErrors, type ISchemaError, type ValidationResult, type ValidationRuleResult, type ValidationParams } from './delivery/schema/Schema.js';
|
|
5
|
+
export { createRules, validationMessagesRu, validationMessagesI18n, validationMessagesEn, type ValidationRuleParams } from './delivery/schema/rules/index.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createPresenter, createStore, createPresenterFactory, createStoreFactory, clearCache } from '../edges/index.js';
|
|
2
|
+
export { createAsyncHelpers } from './delivery/injectableDependencies/AsyncHelpers.js';
|
|
3
|
+
export { createErrorHandler } from './delivery/injectableDependencies/ErrorHandler.js';
|
|
4
|
+
export { createSchemaFactory, schema } from './delivery/schema/Schema.js';
|
|
5
|
+
export { createRules, validationMessagesRu, validationMessagesI18n, validationMessagesEn } from './delivery/schema/rules/index.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { AppError, ErrorTypes, AzureNetKitInternalError, type IAppError } from './shared/appError/AppError.js';
|
|
2
|
+
export { HttpServiceError } from './infra/httpService/HttpServiceInstance.js';
|
|
3
|
+
export { AsyncHelperError } from './delivery/injectableDependencies/AsyncHelpers.js';
|
|
4
|
+
export { SchemaFail } from './delivery/schema/Schema.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { AppError, ErrorTypes, AzureNetKitInternalError } from './shared/appError/AppError.js';
|
|
2
|
+
export { HttpServiceError } from './infra/httpService/HttpServiceInstance.js';
|
|
3
|
+
export { AsyncHelperError } from './delivery/injectableDependencies/AsyncHelpers.js';
|
|
4
|
+
export { SchemaFail } from './delivery/schema/Schema.js';
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export * from './svelte/index.js';
|
|
1
|
+
export { event, stop, prevent, once, immediate, type EventHandler, onClickOutside, scrollTo, Mask, masked } from './ui/index.js';
|
|
2
|
+
export { createQuery, createAsyncSignal, createActiveForm, refreshAsyncSignal, refreshAllAsyncSignals, type AsyncSignalOptions, type AsyncSignalSvelte, type QueryController, type CreateQueryOptions, type AsyncSignalSource, type AsyncStatus } from './svelte/index.js';
|
|
3
|
+
export { createMiddlewareManager, type IMiddleware } from './shared/middleware/index.js';
|
|
4
|
+
export { ClassMirror } from './shared/classMirror/index.js';
|
|
5
|
+
export { UniversalCookie, type CookieOptions } from './shared/cookie/index.js';
|
|
6
|
+
export { createBoundaryProvider, cleanupProvider, type ProviderSettings } from './shared/boundaryProvider/index.js';
|
|
7
|
+
export { AppEvents } from './shared/appEventBus/index.js';
|
package/dist/core/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export * from './svelte/index.js';
|
|
1
|
+
export { event, stop, prevent, once, immediate, onClickOutside, scrollTo, Mask, masked } from './ui/index.js';
|
|
2
|
+
export { createQuery, createAsyncSignal, createActiveForm, refreshAsyncSignal, refreshAllAsyncSignals } from './svelte/index.js';
|
|
3
|
+
export { createMiddlewareManager } from './shared/middleware/index.js';
|
|
4
|
+
export { ClassMirror } from './shared/classMirror/index.js';
|
|
5
|
+
export { UniversalCookie } from './shared/cookie/index.js';
|
|
6
|
+
export { createBoundaryProvider, cleanupProvider } from './shared/boundaryProvider/index.js';
|
|
7
|
+
export { AppEvents } from './shared/appEventBus/index.js';
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { type IHttpServiceInstance, type IHttpServiceResponse } from '../httpService/HttpServiceInstance.js';
|
|
2
|
+
import { type IQueryBuilderInstance } from '../query/index.js';
|
|
3
3
|
export type CreateRequestCallbackType<T> = (params: {
|
|
4
|
-
http:
|
|
5
|
-
query:
|
|
6
|
-
}) => Promise<
|
|
7
|
-
export declare class BaseHttpDatasource
|
|
8
|
-
protected readonly httpClient:
|
|
9
|
-
protected readonly query:
|
|
4
|
+
http: IHttpServiceInstance;
|
|
5
|
+
query: IQueryBuilderInstance;
|
|
6
|
+
}) => Promise<IHttpServiceResponse<T>>;
|
|
7
|
+
export declare class BaseHttpDatasource {
|
|
8
|
+
protected readonly httpClient: IHttpServiceInstance;
|
|
9
|
+
protected readonly query: IQueryBuilderInstance;
|
|
10
10
|
constructor(params: {
|
|
11
|
-
http?:
|
|
12
|
-
query?:
|
|
11
|
+
http?: IHttpServiceInstance;
|
|
12
|
+
query?: IQueryBuilderInstance;
|
|
13
13
|
});
|
|
14
14
|
private _createRawRequest;
|
|
15
|
-
readonly createRawRequest: <T>(callback: CreateRequestCallbackType<T>) => Promise<
|
|
15
|
+
readonly createRawRequest: <T>(callback: CreateRequestCallbackType<T>) => Promise<IHttpServiceResponse<T>>;
|
|
16
16
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createHttpServiceInstance } from '../httpService/HttpServiceInstance.js';
|
|
2
|
+
import { createQueryInstance } from '../query/index.js';
|
|
3
3
|
export class BaseHttpDatasource {
|
|
4
4
|
httpClient;
|
|
5
5
|
query;
|
|
6
6
|
constructor(params) {
|
|
7
|
-
this.httpClient = params.http ??
|
|
8
|
-
this.query = params.query ??
|
|
7
|
+
this.httpClient = params.http ?? createHttpServiceInstance();
|
|
8
|
+
this.query = params.query ?? createQueryInstance();
|
|
9
9
|
}
|
|
10
10
|
async _createRawRequest(callback) {
|
|
11
11
|
return await callback({ http: this.httpClient, query: this.query }).catch((err) => {
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export type SearchParamsInit = string | string[][] | Record<string, string> | URLSearchParams | undefined;
|
|
2
|
+
export type SearchParamsOption = SearchParamsInit | Record<string, string | number | boolean | undefined> | Array<Array<string | number | boolean>>;
|
|
3
|
+
export declare enum HttpInstanceFetchMethods {
|
|
4
|
+
GET = "GET",
|
|
5
|
+
POST = "POST",
|
|
6
|
+
PUT = "PUT",
|
|
7
|
+
PATCH = "PATCH",
|
|
8
|
+
DELETE = "DELETE",
|
|
9
|
+
HEAD = "HEAD",
|
|
10
|
+
OPTIONS = "OPTIONS"
|
|
11
|
+
}
|
|
12
|
+
export interface IHttpServiceResponse<T = unknown> {
|
|
13
|
+
headers: Record<string, string>;
|
|
14
|
+
status: number;
|
|
15
|
+
success: boolean;
|
|
16
|
+
data: T;
|
|
17
|
+
message: string;
|
|
18
|
+
raw?: Response;
|
|
19
|
+
}
|
|
20
|
+
export interface IHttpServiceError<T = unknown> {
|
|
21
|
+
type: HttpErrorTypes;
|
|
22
|
+
response?: Response;
|
|
23
|
+
original?: Error;
|
|
24
|
+
message: string;
|
|
25
|
+
status: number;
|
|
26
|
+
data?: T;
|
|
27
|
+
}
|
|
28
|
+
export declare class HttpServiceResponse<T> implements IHttpServiceResponse<T> {
|
|
29
|
+
headers: Record<string, string>;
|
|
30
|
+
status: number;
|
|
31
|
+
success: boolean;
|
|
32
|
+
data: T;
|
|
33
|
+
message: string;
|
|
34
|
+
raw?: Response;
|
|
35
|
+
constructor({ headers, status, success, data, message, raw }: IHttpServiceResponse<T>);
|
|
36
|
+
}
|
|
37
|
+
export declare enum HttpErrorTypes {
|
|
38
|
+
Internal = "internal",
|
|
39
|
+
External = "external"
|
|
40
|
+
}
|
|
41
|
+
export declare class HttpServiceError<T> extends Error implements IHttpServiceError<T> {
|
|
42
|
+
data?: T;
|
|
43
|
+
status: number;
|
|
44
|
+
message: string;
|
|
45
|
+
type: HttpErrorTypes;
|
|
46
|
+
original?: Error;
|
|
47
|
+
response?: Response;
|
|
48
|
+
constructor({ status, data, message, original, type, response }: Partial<IHttpServiceError<T>>);
|
|
49
|
+
}
|
|
50
|
+
export interface HttpInstanceNormalizedRequest {
|
|
51
|
+
url: string | URL;
|
|
52
|
+
method: HttpInstanceFetchMethods;
|
|
53
|
+
headers: Headers;
|
|
54
|
+
body: BodyInit | null | undefined;
|
|
55
|
+
responseFormat: 'json' | 'blob' | 'text' | 'arrayBuffer' | 'body';
|
|
56
|
+
includeRaw: boolean;
|
|
57
|
+
timeout: number | false;
|
|
58
|
+
retry: number;
|
|
59
|
+
stringifyJson: (data: unknown) => string | undefined;
|
|
60
|
+
fetch: typeof fetch;
|
|
61
|
+
requestInit: Omit<RequestInit, 'method' | 'headers' | 'body'>;
|
|
62
|
+
}
|
|
63
|
+
export type HttpInstanceOnRequest = (request: HttpInstanceNormalizedRequest) => void | Promise<void>;
|
|
64
|
+
export type HttpInstanceOnError = (error: HttpServiceError<unknown>, request: HttpInstanceNormalizedRequest) => void | Promise<void>;
|
|
65
|
+
export type HttpInstanceDoFetch = <T = unknown>(request: HttpInstanceNormalizedRequest) => Promise<IHttpServiceResponse<T>>;
|
|
66
|
+
export interface IHttpInstanceOptions extends Omit<RequestInit, 'headers' | 'method'> {
|
|
67
|
+
headers?: NonNullable<RequestInit['headers']> | Record<string, string | undefined>;
|
|
68
|
+
json?: unknown;
|
|
69
|
+
stringifyJson?: (data: unknown) => string | undefined;
|
|
70
|
+
searchParams?: SearchParamsOption;
|
|
71
|
+
prefixUrl?: URL | string;
|
|
72
|
+
timeout?: number | false;
|
|
73
|
+
retry?: number;
|
|
74
|
+
includeRaw?: boolean;
|
|
75
|
+
responseFormat?: 'json' | 'blob' | 'text' | 'arrayBuffer' | 'body';
|
|
76
|
+
onRequest?: HttpInstanceOnRequest;
|
|
77
|
+
onError?: HttpInstanceOnError;
|
|
78
|
+
doFetch?: HttpInstanceDoFetch;
|
|
79
|
+
}
|
|
80
|
+
export type HttpInstanceRequestMethod = <T = unknown>(url: string | URL, options?: IHttpInstanceOptions) => Promise<IHttpServiceResponse<T>>;
|
|
81
|
+
export interface IHttpServiceInstance {
|
|
82
|
+
get: HttpInstanceRequestMethod;
|
|
83
|
+
post: HttpInstanceRequestMethod;
|
|
84
|
+
put: HttpInstanceRequestMethod;
|
|
85
|
+
delete: HttpInstanceRequestMethod;
|
|
86
|
+
patch: HttpInstanceRequestMethod;
|
|
87
|
+
head: HttpInstanceRequestMethod;
|
|
88
|
+
options: HttpInstanceRequestMethod;
|
|
89
|
+
}
|
|
90
|
+
export declare const createHttpServiceInstance: (config?: IHttpInstanceOptions) => IHttpServiceInstance;
|