@azure-net/kit 4.0.0 → 4.1.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/delivery/injectableDependencies/ErrorHandler.d.ts +5 -1
- package/dist/core/delivery/injectableDependencies/ErrorHandler.js +2 -1
- package/dist/core/delivery/schema/rules/Rules.d.ts +3 -2
- package/dist/core/delivery/schema/rules/Rules.js +17 -1
- package/dist/core/delivery/schema/rules/messages/En.js +1 -0
- package/dist/core/delivery/schema/rules/messages/Ru.js +1 -0
- package/dist/core/delivery/schema/rules/messages/WithI18n.js +1 -0
- package/dist/core/delivery/schema/rules/messages/types.d.ts +1 -0
- package/dist/core/shared/appEventBus/EventBus.d.ts +1 -3
- package/dist/core/shared/appEventBus/EventBus.js +1 -3
- package/dist/core/shared/boundaryProvider/Provider.js +25 -1
- package/dist/core/shared/middleware/Middleware.d.ts +2 -0
- package/dist/core/shared/middleware/Middleware.js +2 -0
- package/package.json +4 -4
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { AppError, type IAppError } from '../../shared/appError/AppError.js';
|
|
2
|
+
import { AppEvents } from '../../shared/appEventBus/index.js';
|
|
2
3
|
import type { AsyncHelperRetry } from './AsyncHelpers.js';
|
|
3
|
-
export
|
|
4
|
+
export type ErrorHandlerContext = {
|
|
5
|
+
AppEvents: typeof AppEvents;
|
|
6
|
+
};
|
|
7
|
+
export declare const createErrorHandler: <CustomData extends object>(handle?: <T = unknown>(error: AppError<T>, asyncHelperRetry: AsyncHelperRetry, context: ErrorHandlerContext) => Promise<IAppError<T> & CustomData>) => <T = unknown>(error: Error, asyncHelperRetry?: AsyncHelperRetry) => Promise<IAppError<T> & CustomData>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AppError } from '../../shared/appError/AppError.js';
|
|
2
|
+
import { AppEvents } from '../../shared/appEventBus/index.js';
|
|
2
3
|
export const createErrorHandler = (handle) => {
|
|
3
4
|
return async (error, asyncHelperRetry) => {
|
|
4
5
|
const appError = new AppError(error);
|
|
5
6
|
if (handle) {
|
|
6
|
-
const handled = await handle(appError, asyncHelperRetry ?? { can: false });
|
|
7
|
+
const handled = await handle(appError, asyncHelperRetry ?? { can: false }, { AppEvents });
|
|
7
8
|
if (handled?.appErrorConvert) {
|
|
8
9
|
return handled;
|
|
9
10
|
}
|
|
@@ -55,8 +55,9 @@ export declare const createRules: <M extends BaseValidationMessages>(validationM
|
|
|
55
55
|
whiteSpaces?: boolean;
|
|
56
56
|
}>) => ValidationRuleResult<T, D_9>;
|
|
57
57
|
phone: <T = unknown, D_10 = unknown>(params?: ValidationRuleParams<"phone">) => ValidationRuleResult<T, D_10>;
|
|
58
|
-
|
|
58
|
+
date: <T = unknown, D_11 = unknown>(params?: ValidationRuleParams<"date">) => ValidationRuleResult<T, D_11>;
|
|
59
|
+
allowedOnly: <T = unknown, D_12 = unknown>(params?: ValidationRuleParams<"allowedOnly", {
|
|
59
60
|
allowed?: unknown[];
|
|
60
|
-
}>) => ValidationRuleResult<T,
|
|
61
|
+
}>) => ValidationRuleResult<T, D_12>;
|
|
61
62
|
};
|
|
62
63
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DateUtil } from '@azure-net/tools';
|
|
1
2
|
/**
|
|
2
3
|
*
|
|
3
4
|
* @param validationMessages - BaseValidationMessages
|
|
@@ -211,6 +212,21 @@ export const createRules = (validationMessages) => {
|
|
|
211
212
|
return undefined;
|
|
212
213
|
};
|
|
213
214
|
};
|
|
215
|
+
/**
|
|
216
|
+
*
|
|
217
|
+
* @param params - ValidationRuleParams<'date'>
|
|
218
|
+
* @returns ValidationRuleResult<T, D>
|
|
219
|
+
* @description Checks if the value is a valid date.
|
|
220
|
+
*/
|
|
221
|
+
const date = (params) => {
|
|
222
|
+
const { message } = { ...params, message: params?.message ?? validationMessages.date };
|
|
223
|
+
return ({ val }) => {
|
|
224
|
+
if (checkVal(val)) {
|
|
225
|
+
return val instanceof Date || typeof val === 'string' ? (DateUtil.isDate(val) ? undefined : message()) : message();
|
|
226
|
+
}
|
|
227
|
+
return undefined;
|
|
228
|
+
};
|
|
229
|
+
};
|
|
214
230
|
/**
|
|
215
231
|
*
|
|
216
232
|
* @param params - ValidationRuleParams<'email'>
|
|
@@ -387,5 +403,5 @@ export const createRules = (validationMessages) => {
|
|
|
387
403
|
return undefined;
|
|
388
404
|
};
|
|
389
405
|
};
|
|
390
|
-
return { string, number, required, password, notSameAs, sameAs, array, boolean, email, finite, lettersOnly, phone, allowedOnly };
|
|
406
|
+
return { string, number, required, password, notSameAs, sameAs, array, boolean, email, finite, lettersOnly, phone, date, allowedOnly };
|
|
391
407
|
};
|
|
@@ -4,6 +4,7 @@ import { AzureNetKitInternalError } from '../appError/AppError.js';
|
|
|
4
4
|
const clientCache = new Map();
|
|
5
5
|
const factoriesCache = new WeakMap();
|
|
6
6
|
const providerProxyCache = new Map();
|
|
7
|
+
const clientConstructionStack = [];
|
|
7
8
|
const clientBootFlags = new Map();
|
|
8
9
|
const getProviderCache = (providerName) => {
|
|
9
10
|
if (BROWSER) {
|
|
@@ -54,6 +55,29 @@ const setBootFlag = (providerName, value) => {
|
|
|
54
55
|
bootFlags.set(providerName, value);
|
|
55
56
|
}
|
|
56
57
|
};
|
|
58
|
+
const getConstructionStack = () => {
|
|
59
|
+
if (BROWSER)
|
|
60
|
+
return clientConstructionStack;
|
|
61
|
+
const context = RequestContext.current();
|
|
62
|
+
return (context.data.boundaryProviderConstructionStack ??= []);
|
|
63
|
+
};
|
|
64
|
+
const runWithCycleGuard = (key, callback) => {
|
|
65
|
+
const stack = getConstructionStack();
|
|
66
|
+
if (stack.includes(key)) {
|
|
67
|
+
const cycleStart = stack.indexOf(key);
|
|
68
|
+
const cyclePath = [...stack.slice(cycleStart), key].join(' -> ');
|
|
69
|
+
throw new AzureNetKitInternalError(`[BoundaryProvider] Circular provider dependency detected: ${cyclePath}`);
|
|
70
|
+
}
|
|
71
|
+
stack.push(key);
|
|
72
|
+
try {
|
|
73
|
+
return callback();
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
const idx = stack.lastIndexOf(key);
|
|
77
|
+
if (idx !== -1)
|
|
78
|
+
stack.splice(idx, 1);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
57
81
|
export const createBoundaryProvider = (name, settings) => {
|
|
58
82
|
const { dependsOn = {}, boot, register } = settings;
|
|
59
83
|
const providerFn = () => {
|
|
@@ -101,7 +125,7 @@ export const createBoundaryProvider = (name, settings) => {
|
|
|
101
125
|
if (typeof factory !== 'function') {
|
|
102
126
|
throw new AzureNetKitInternalError('[BoundaryProvider] Factory must be a function');
|
|
103
127
|
}
|
|
104
|
-
const instance = factory();
|
|
128
|
+
const instance = runWithCycleGuard(`${name}.${key}`, () => factory());
|
|
105
129
|
if (instance && typeof instance?.then === 'function') {
|
|
106
130
|
throw new AzureNetKitInternalError(`[BoundaryProvider] Service '${key}' in provider '${name}' returned Promise.`);
|
|
107
131
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type BeforeNavigate, error, type Page, type RequestEvent } from '@sveltejs/kit';
|
|
2
2
|
import { UniversalCookie } from '../cookie/index.js';
|
|
3
|
+
import { AppEvents } from '../appEventBus/index.js';
|
|
3
4
|
type RedirectStatus = 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
|
|
4
5
|
export type IMiddleware = (middlewareData: {
|
|
5
6
|
to: RequestEvent['url'] | Page['url'];
|
|
@@ -8,6 +9,7 @@ export type IMiddleware = (middlewareData: {
|
|
|
8
9
|
next: (location?: string | URL, status?: RedirectStatus) => void;
|
|
9
10
|
isServer: boolean;
|
|
10
11
|
cookies: typeof UniversalCookie;
|
|
12
|
+
AppEvents: typeof AppEvents;
|
|
11
13
|
event?: RequestEvent;
|
|
12
14
|
page: Page;
|
|
13
15
|
}) => Promise<void> | void;
|
|
@@ -4,6 +4,7 @@ import { beforeNavigate, goto } from '$app/navigation';
|
|
|
4
4
|
import { page } from '$app/state';
|
|
5
5
|
import { BROWSER } from '@azure-net/tools/environment';
|
|
6
6
|
import { UniversalCookie } from '../cookie/index.js';
|
|
7
|
+
import { AppEvents } from '../appEventBus/index.js';
|
|
7
8
|
export const createMiddlewareManager = (middlewares) => {
|
|
8
9
|
const universalRedirect = (location, status = 301, navigation) => {
|
|
9
10
|
if (BROWSER) {
|
|
@@ -40,6 +41,7 @@ export const createMiddlewareManager = (middlewares) => {
|
|
|
40
41
|
event,
|
|
41
42
|
page,
|
|
42
43
|
cookies: UniversalCookie,
|
|
44
|
+
AppEvents,
|
|
43
45
|
isServer: !BROWSER,
|
|
44
46
|
to,
|
|
45
47
|
from,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-net/kit",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Pixel1917",
|
|
6
6
|
"description": "Universal toolkit and library collection, developed as part of the Azure-net ecosystem",
|
|
@@ -128,9 +128,9 @@
|
|
|
128
128
|
"utils"
|
|
129
129
|
],
|
|
130
130
|
"dependencies": {
|
|
131
|
-
"@azure-net/edges": "^1.2.
|
|
132
|
-
"@azure-net/edges-translations": "^1.2.
|
|
133
|
-
"@azure-net/tools": "^1.2.
|
|
131
|
+
"@azure-net/edges": "^1.2.7",
|
|
132
|
+
"@azure-net/edges-translations": "^1.2.7",
|
|
133
|
+
"@azure-net/tools": "^1.2.7"
|
|
134
134
|
},
|
|
135
135
|
"scripts": {
|
|
136
136
|
"dev": "vite dev",
|