@azure-net/kit 1.2.0 → 1.2.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.
@@ -1,4 +1,5 @@
1
1
  import { createErrorParser } from './ErrorHandler.js';
2
+ import { AppEvents } from '../../index.js';
2
3
  export const createAsyncHelpers = (opts) => {
3
4
  const errorParser = opts?.parseError ?? createErrorParser();
4
5
  const createAsyncAction = async (action, args) => {
@@ -25,10 +26,12 @@ export const createAsyncHelpers = (opts) => {
25
26
  }
26
27
  catch (err) {
27
28
  const error = errorParser(err);
28
- if (args?.reject)
29
- throw error;
29
+ const { publish } = AppEvents();
30
+ publish('OnAsyncHelperError', error);
30
31
  const result = { error, response: args?.fallbackResponse, success: false };
31
32
  await args?.onError?.(result);
33
+ if (args?.reject)
34
+ throw error;
32
35
  return result;
33
36
  }
34
37
  };
@@ -44,6 +47,8 @@ export const createAsyncHelpers = (opts) => {
44
47
  }
45
48
  catch (err) {
46
49
  const error = errorParser(err);
50
+ const { publish } = AppEvents();
51
+ publish('OnAsyncHelperError', error);
47
52
  await args?.onError?.(error);
48
53
  if (args?.reject)
49
54
  throw error;
@@ -3,5 +3,6 @@ export * from './shared/middleware/index.js';
3
3
  export * from './shared/classMirror/index.js';
4
4
  export * from './shared/cookie/index.js';
5
5
  export * from './shared/boundaryProvider/index.js';
6
+ export * from './shared/appEventBus/index.js';
6
7
  export * from './ui/index.js';
7
8
  export * from './svelte/index.js';
@@ -3,5 +3,6 @@ export * from './shared/middleware/index.js';
3
3
  export * from './shared/classMirror/index.js';
4
4
  export * from './shared/cookie/index.js';
5
5
  export * from './shared/boundaryProvider/index.js';
6
+ export * from './shared/appEventBus/index.js';
6
7
  export * from './ui/index.js';
7
8
  export * from './svelte/index.js';
@@ -1,5 +1,4 @@
1
1
  import { type Options } from 'ky';
2
- import { EventBus } from 'azure-net-tools';
3
2
  export interface IHttpServiceResponse<T = unknown> {
4
3
  headers: Record<string, string>;
5
4
  status: number;
@@ -30,7 +29,6 @@ export declare class HttpServiceError<T> implements IHttpServiceError<T> {
30
29
  export interface IHttpServiceOptions extends Options {
31
30
  responseFormat?: 'json' | 'blob' | 'text' | 'arrayBuffer' | 'body';
32
31
  }
33
- export declare const httpServiceEventBus: EventBus<"HttpServiceError">;
34
32
  export declare class HttpService {
35
33
  private readonly baseUrl;
36
34
  private readonly instance;
@@ -1,5 +1,4 @@
1
1
  import ky, {} from 'ky';
2
- import { EventBus } from 'azure-net-tools';
3
2
  export class HttpServiceResponse {
4
3
  headers;
5
4
  status;
@@ -30,9 +29,6 @@ export class HttpServiceError {
30
29
  this.original = original;
31
30
  }
32
31
  }
33
- export const httpServiceEventBus = new EventBus({
34
- HttpServiceError: []
35
- });
36
32
  export class HttpService {
37
33
  baseUrl;
38
34
  instance;
@@ -155,7 +151,6 @@ export class HttpService {
155
151
  original: err,
156
152
  message: 'Request failed'
157
153
  });
158
- httpServiceEventBus.publish('HttpServiceError', error);
159
154
  return this.errorHandler ? this.errorHandler(error) : error;
160
155
  }
161
156
  }
@@ -0,0 +1,4 @@
1
+ export declare const AppEvents: () => {
2
+ subscribe: <T>(channel: "OnAsyncHelperError", listener: (data: T) => void) => void;
3
+ publish: <T>(channel: "OnAsyncHelperError", data: T) => void;
4
+ };
@@ -0,0 +1,9 @@
1
+ import { EventBus } from 'azure-net-tools';
2
+ import { createPresenter } from 'edges-svelte';
3
+ export const AppEvents = createPresenter('GlobalAppEventBus', () => {
4
+ const appEventBus = new EventBus();
5
+ return {
6
+ subscribe: appEventBus.subscribe,
7
+ publish: appEventBus.publish
8
+ };
9
+ });
@@ -0,0 +1 @@
1
+ export * from './EventBus.js';
@@ -0,0 +1 @@
1
+ export * from './EventBus.js';
@@ -8,7 +8,7 @@ export const createActiveForm = (onSubmit, config) => {
8
8
  const submit = async () => {
9
9
  pending = true;
10
10
  try {
11
- const result = await onSubmit(formData);
11
+ const result = await onSubmit(ObjectUtil.deepClone(formData));
12
12
  if (result.error?.fields) {
13
13
  formErrors = result.error.fields;
14
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-net/kit",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",