@azure-net/kit 6.0.0-next → 6.0.0-next.1

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.
@@ -67,28 +67,38 @@ export const createAsyncHelpers = () => {
67
67
  const beforeSendResult = await beforeSendResolver(args);
68
68
  if (beforeSendResult)
69
69
  return beforeSendResult;
70
- const req = async () => {
70
+ const executeAction = async () => {
71
71
  const response = await Promise.resolve(action());
72
- const result = { response, success: true };
73
- await args?.onSuccess?.(result);
74
- return result;
72
+ return { response, success: true };
75
73
  };
76
- try {
77
- return await req();
78
- }
79
- catch (err) {
80
- const { error, retryResult } = await prepareErrors(normalizeError(err), async () => await req());
74
+ const handleFailure = async (err, retry) => {
75
+ const { error, retryResult } = await prepareErrors(normalizeError(err), retry);
81
76
  if (retryResult) {
82
- return retryResult;
77
+ return completeSuccess(retryResult);
83
78
  }
84
79
  const result = { error, response: args?.fallbackResponse, success: false };
85
80
  try {
86
81
  await args?.onError?.(result);
87
82
  }
88
- catch (err) {
89
- throw await resolveAzureNetKitError(new AsyncHelperError('onError caught exception', { cause: normalizeError(err) }));
83
+ catch (onErrorException) {
84
+ throw await resolveAzureNetKitError(new AsyncHelperError('onError caught exception', { cause: normalizeError(onErrorException) }));
90
85
  }
91
86
  return result;
87
+ };
88
+ const completeSuccess = async (result) => {
89
+ try {
90
+ await args?.onSuccess?.(result);
91
+ return result;
92
+ }
93
+ catch (err) {
94
+ return handleFailure(err);
95
+ }
96
+ };
97
+ try {
98
+ return completeSuccess(await executeAction());
99
+ }
100
+ catch (err) {
101
+ return handleFailure(err, executeAction);
92
102
  }
93
103
  };
94
104
  const createAsyncResource = async (action, args) => {
@@ -76,7 +76,7 @@ class SchemaBuilderImpl {
76
76
  const _preparedData = prepare(data);
77
77
  let _errors = {};
78
78
  let _isValid = true;
79
- if (typeof _preparedData !== 'object') {
79
+ if (_preparedData === null || typeof _preparedData !== 'object') {
80
80
  throw new AzureNetKitInternalError('[Schema] Data in "from" method can be only valid object or formData.');
81
81
  }
82
82
  const validated = (params) => {
@@ -162,10 +162,14 @@ const parseBodyByFormat = async (response, format) => {
162
162
  return (await response.arrayBuffer());
163
163
  case 'body':
164
164
  return response.body;
165
- case 'json':
166
- return (await response.json());
167
- default:
168
- return (await response.json());
165
+ case 'json': {
166
+ const text = await response.text();
167
+ return (text.trim() ? JSON.parse(text) : undefined);
168
+ }
169
+ default: {
170
+ const text = await response.text();
171
+ return (text.trim() ? JSON.parse(text) : undefined);
172
+ }
169
173
  }
170
174
  };
171
175
  const withTimeout = (signal, timeout) => {
@@ -13,7 +13,7 @@ type ProviderFactory<T extends ServiceMap, D extends Record<string, ProviderWith
13
13
  }) => T;
14
14
  export interface ProviderSettings<T extends ServiceMap, D extends Record<string, ProviderWithType<ServiceMap>>> {
15
15
  dependsOn?: D;
16
- boot?: (services: ResolvedServices<T>) => void | Promise<void>;
16
+ boot?: (services: ResolvedServices<T>) => undefined;
17
17
  register: ProviderFactory<T, D>;
18
18
  }
19
19
  export declare const createBoundaryProvider: <T extends ServiceMap, D extends Record<string, ProviderWithType<ServiceMap>>>(name: string, settings: ProviderSettings<T, D>) => ProviderWithType<T>;
@@ -14,17 +14,17 @@ const getProviderCache = (providerName) => {
14
14
  }
15
15
  else {
16
16
  const context = RequestContext.current();
17
- if (!context.data.providers) {
18
- context.data.providers = new Map();
17
+ if (!context.data.azureNetKitBoundaryProviders) {
18
+ context.data.azureNetKitBoundaryProviders = new Map();
19
19
  }
20
- const providers = context.data.providers;
20
+ const providers = context.data.azureNetKitBoundaryProviders;
21
21
  if (!providers.has(providerName)) {
22
22
  providers.set(providerName, new Map());
23
23
  }
24
- if (!context.data.providersToCleanup) {
25
- context.data.providersToCleanup = new Set();
24
+ if (!context.data.azureNetKitBoundaryProvidersToCleanup) {
25
+ context.data.azureNetKitBoundaryProvidersToCleanup = new Set();
26
26
  }
27
- context.data.providersToCleanup.add(providerName);
27
+ context.data.azureNetKitBoundaryProvidersToCleanup.add(providerName);
28
28
  return providers.get(providerName);
29
29
  }
30
30
  };
@@ -161,12 +161,13 @@ export const createBoundaryProvider = (name, settings) => {
161
161
  providerProxyCache.set(name, providerProxy);
162
162
  }
163
163
  if (boot && !getBootFlag(name)) {
164
- setBootFlag(name, true);
165
164
  getFactories();
166
165
  const bootResult = boot(providerProxy);
167
- if (bootResult instanceof Promise) {
168
- bootResult.catch((err) => console.error(`Error in boot for provider '${name}':`, err));
166
+ if (bootResult && typeof bootResult.then === 'function') {
167
+ void Promise.resolve(bootResult).catch(() => undefined);
168
+ throw new AzureNetKitInternalError(`[BoundaryProvider] Boot for provider '${name}' must be synchronous.`);
169
169
  }
170
+ setBootFlag(name, true);
170
171
  }
171
172
  return providerProxy;
172
173
  };
@@ -199,7 +200,7 @@ export async function cleanupProvider(name) {
199
200
  }
200
201
  else {
201
202
  const context = RequestContext.current();
202
- const providers = context.data.providers;
203
+ const providers = context.data.azureNetKitBoundaryProviders;
203
204
  if (providers?.has(name)) {
204
205
  const cache = providers.get(name);
205
206
  providers.delete(name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-net/kit",
3
- "version": "6.0.0-next",
3
+ "version": "6.0.0-next.1",
4
4
  "license": "MIT",
5
5
  "author": "Pixel1917",
6
6
  "description": "Universal toolkit and library collection, developed as part of the Azure-net ecosystem",