@vaadin/hilla-frontend 24.7.0-alpha9 → 24.7.0-beta2

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/Connect.d.ts CHANGED
@@ -1,173 +1,177 @@
1
- import type { ReactiveControllerHost } from '@lit/reactive-element';
2
- import { type ActionOnLostSubscription, FluxConnection, type FluxSubscriptionStateChangeEvent } from './FluxConnection.js';
1
+ import type { ReactiveControllerHost } from "@lit/reactive-element";
2
+ import { type ActionOnLostSubscription, FluxConnection, type FluxSubscriptionStateChangeEvent } from "./FluxConnection.js";
3
+ export declare const BODY_PART_NAME = "hilla_body_part";
3
4
  export type MaybePromise<T> = Promise<T> | T;
4
5
  /**
5
- * Represents the connection to and endpoint returning a subscription rather than a value.
6
- */
6
+ * Represents the connection to and endpoint returning a subscription rather than a value.
7
+ */
7
8
  export interface Subscription<T> {
8
- /** Cancels the subscription. No values are made available after calling this. */
9
- cancel(): void;
10
- context(context: ReactiveControllerHost): Subscription<T>;
11
- /** Called when the subscription has completed. No values are made available after calling this. */
12
- onComplete(callback: () => void): Subscription<T>;
13
- /** Called when an exception occured in the subscription. */
14
- onError(callback: (message: string) => void): Subscription<T>;
15
- /** Called when a new value is available. */
16
- onNext(callback: (value: T) => void): Subscription<T>;
17
- /** Called when the subscription state changes. */
18
- onConnectionStateChange(callback: (event: FluxSubscriptionStateChangeEvent) => void): Subscription<T>;
19
- /**
20
- * Called when the connection is restored, but there's no longer a valid subscription. If the callback returns
21
- * `ActionOnLostSubscription.RESUBSCRIBE`, the subscription will be re-established by connecting to the same
22
- * server method again. If the callback returns `ActionOnLostSubscription.REMOVE`, the subscription will be
23
- * forgotten. This is also the default behavior if the callback is not set or if it returns `undefined`.
24
- */
25
- onSubscriptionLost(callback: () => ActionOnLostSubscription | void): Subscription<T>;
9
+ /** Cancels the subscription. No values are made available after calling this. */
10
+ cancel(): void;
11
+ context(context: ReactiveControllerHost): Subscription<T>;
12
+ /** Called when the subscription has completed. No values are made available after calling this. */
13
+ onComplete(callback: () => void): Subscription<T>;
14
+ /** Called when an exception occured in the subscription. */
15
+ onError(callback: (message: string) => void): Subscription<T>;
16
+ /** Called when a new value is available. */
17
+ onNext(callback: (value: T) => void): Subscription<T>;
18
+ /** Called when the subscription state changes. */
19
+ onConnectionStateChange(callback: (event: FluxSubscriptionStateChangeEvent) => void): Subscription<T>;
20
+ /**
21
+ * Called when the connection is restored, but there's no longer a valid subscription. If the callback returns
22
+ * `ActionOnLostSubscription.RESUBSCRIBE`, the subscription will be re-established by connecting to the same
23
+ * server method again. If the callback returns `ActionOnLostSubscription.REMOVE`, the subscription will be
24
+ * forgotten. This is also the default behavior if the callback is not set or if it returns `undefined`.
25
+ */
26
+ onSubscriptionLost(callback: () => ActionOnLostSubscription | void): Subscription<T>;
26
27
  }
27
28
  /**
28
- * The `ConnectClient` constructor options.
29
- */
29
+ * The `ConnectClient` constructor options.
30
+ */
30
31
  export interface ConnectClientOptions {
31
- /**
32
- * The `middlewares` property value.
33
- */
34
- middlewares?: Middleware[];
35
- /**
36
- * The `prefix` property value.
37
- */
38
- prefix?: string;
39
- /**
40
- * The Atmosphere options for the FluxConnection.
41
- */
42
- atmosphereOptions?: Partial<Atmosphere.Request>;
32
+ /**
33
+ * The `middlewares` property value.
34
+ */
35
+ middlewares?: Middleware[];
36
+ /**
37
+ * The `prefix` property value.
38
+ */
39
+ prefix?: string;
40
+ /**
41
+ * The Atmosphere options for the FluxConnection.
42
+ */
43
+ atmosphereOptions?: Partial<Atmosphere.Request>;
43
44
  }
44
45
  export interface EndpointCallMetaInfo {
45
- /**
46
- * The endpoint name.
47
- */
48
- endpoint: string;
49
- /**
50
- * The method name to call on in the endpoint class.
51
- */
52
- method: string;
53
- /**
54
- * Optional object with method call arguments.
55
- */
56
- params?: Record<string, unknown>;
46
+ /**
47
+ * The endpoint name.
48
+ */
49
+ endpoint: string;
50
+ /**
51
+ * The method name to call on in the endpoint class.
52
+ */
53
+ method: string;
54
+ /**
55
+ * Optional object with method call arguments.
56
+ */
57
+ params?: Record<string, unknown>;
57
58
  }
58
59
  /**
59
- * An object with the call arguments and the related Request instance.
60
- * See also {@link ConnectClient.call | the call() method in ConnectClient}.
61
- */
60
+ * An object with the call arguments and the related Request instance.
61
+ * See also {@link ConnectClient.call | the call() method in ConnectClient}.
62
+ */
62
63
  export interface MiddlewareContext extends EndpointCallMetaInfo {
63
- /**
64
- * The Fetch API Request object reflecting the other properties.
65
- */
66
- request: Request;
64
+ /**
65
+ * The Fetch API Request object reflecting the other properties.
66
+ */
67
+ request: Request;
67
68
  }
68
69
  /**
69
- * An async middleware callback that invokes the next middleware in the chain
70
- * or makes the actual request.
71
- * @param context - The information about the call and request
72
- */
70
+ * An async middleware callback that invokes the next middleware in the chain
71
+ * or makes the actual request.
72
+ * @param context - The information about the call and request
73
+ */
73
74
  export type MiddlewareNext = (context: MiddlewareContext) => MaybePromise<Response>;
74
75
  /**
75
- * An interface that allows defining a middleware as a class.
76
- */
76
+ * An interface that allows defining a middleware as a class.
77
+ */
77
78
  export interface MiddlewareClass {
78
- /**
79
- * @param context - The information about the call and request
80
- * @param next - Invokes the next in the call chain
81
- */
82
- invoke(context: MiddlewareContext, next: MiddlewareNext): MaybePromise<Response>;
79
+ /**
80
+ * @param context - The information about the call and request
81
+ * @param next - Invokes the next in the call chain
82
+ */
83
+ invoke(context: MiddlewareContext, next: MiddlewareNext): MaybePromise<Response>;
83
84
  }
84
85
  /**
85
- * An async callback function that can intercept the request and response
86
- * of a call.
87
- */
86
+ * An async callback function that can intercept the request and response
87
+ * of a call.
88
+ */
88
89
  export type MiddlewareFunction = (context: MiddlewareContext, next: MiddlewareNext) => MaybePromise<Response>;
89
90
  /**
90
- * An async callback that can intercept the request and response
91
- * of a call, could be either a function or a class.
92
- */
91
+ * An async callback that can intercept the request and response
92
+ * of a call, could be either a function or a class.
93
+ */
93
94
  export type Middleware = MiddlewareClass | MiddlewareFunction;
94
95
  /**
95
- * A list of parameters supported by {@link ConnectClient.call | the call() method in ConnectClient}.
96
- */
96
+ * A list of parameters supported by {@link ConnectClient.call | the call() method in ConnectClient}.
97
+ */
97
98
  export interface EndpointRequestInit {
98
- /**
99
- * An AbortSignal to set request's signal.
100
- */
101
- signal?: AbortSignal | null;
99
+ /**
100
+ * An AbortSignal to set request's signal.
101
+ */
102
+ signal?: AbortSignal | null;
103
+ /**
104
+ * If set to true, the connection state will not be updated during the request.
105
+ */
106
+ mute?: boolean;
102
107
  }
103
108
  /**
104
- * A low-level network calling utility. It stores
105
- * a prefix and facilitates remote calls to endpoint class methods
106
- * on the Hilla backend.
107
- *
108
- * Example usage:
109
- *
110
- * ```js
111
- * const client = new ConnectClient();
112
- * const responseData = await client.call('MyEndpoint', 'myMethod');
113
- * ```
114
- *
115
- * ### Prefix
116
- *
117
- * The client supports an `prefix` constructor option:
118
- * ```js
119
- * const client = new ConnectClient({prefix: '/my-connect-prefix'});
120
- * ```
121
- *
122
- * The default prefix is '/connect'.
123
- *
124
- */
109
+ * A low-level network calling utility. It stores
110
+ * a prefix and facilitates remote calls to endpoint class methods
111
+ * on the Hilla backend.
112
+ *
113
+ * Example usage:
114
+ *
115
+ * ```js
116
+ * const client = new ConnectClient();
117
+ * const responseData = await client.call('MyEndpoint', 'myMethod');
118
+ * ```
119
+ *
120
+ * ### Prefix
121
+ *
122
+ * The client supports an `prefix` constructor option:
123
+ * ```js
124
+ * const client = new ConnectClient({prefix: '/my-connect-prefix'});
125
+ * ```
126
+ *
127
+ * The default prefix is '/connect'.
128
+ *
129
+ */
125
130
  export declare class ConnectClient {
126
- #private;
127
- /**
128
- * The array of middlewares that are invoked during a call.
129
- */
130
- middlewares: Middleware[];
131
- /**
132
- * The Hilla endpoint prefix
133
- */
134
- prefix: string;
135
- /**
136
- * The Atmosphere options for the FluxConnection.
137
- */
138
- atmosphereOptions: Partial<Atmosphere.Request>;
139
- /**
140
- * @param options - Constructor options.
141
- */
142
- constructor(options?: ConnectClientOptions);
143
- /**
144
- * Gets a representation of the underlying persistent network connection used for subscribing to Flux type endpoint
145
- * methods.
146
- */
147
- get fluxConnection(): FluxConnection;
148
- /**
149
- * Calls the given endpoint method defined using the endpoint and method
150
- * parameters with the parameters given as params.
151
- * Asynchronously returns the parsed JSON response data.
152
- *
153
- * @param endpoint - Endpoint name.
154
- * @param method - Method name to call in the endpoint class.
155
- * @param params - Optional parameters to pass to the method.
156
- * @param init - Optional parameters for the request
157
- * @returns Decoded JSON response data.
158
- */
159
- call(endpoint: string, method: string, params?: Record<string, unknown>, init?: EndpointRequestInit): Promise<any>;
160
- /**
161
- * Subscribes to the given method defined using the endpoint and method
162
- * parameters with the parameters given as params. The method must return a
163
- * compatible type such as a Flux.
164
- * Returns a subscription that is used to fetch values as they become available.
165
- *
166
- * @param endpoint - Endpoint name.
167
- * @param method - Method name to call in the endpoint class.
168
- * @param params - Optional parameters to pass to the method.
169
- * @returns A subscription used to handles values as they become available.
170
- */
171
- subscribe(endpoint: string, method: string, params?: any): Subscription<any>;
131
+ #private;
132
+ /**
133
+ * The array of middlewares that are invoked during a call.
134
+ */
135
+ middlewares: Middleware[];
136
+ /**
137
+ * The Hilla endpoint prefix
138
+ */
139
+ prefix: string;
140
+ /**
141
+ * The Atmosphere options for the FluxConnection.
142
+ */
143
+ atmosphereOptions: Partial<Atmosphere.Request>;
144
+ /**
145
+ * @param options - Constructor options.
146
+ */
147
+ constructor(options?: ConnectClientOptions);
148
+ /**
149
+ * Gets a representation of the underlying persistent network connection used for subscribing to Flux type endpoint
150
+ * methods.
151
+ */
152
+ get fluxConnection(): FluxConnection;
153
+ /**
154
+ * Calls the given endpoint method defined using the endpoint and method
155
+ * parameters with the parameters given as params.
156
+ * Asynchronously returns the parsed JSON response data.
157
+ *
158
+ * @param endpoint - Endpoint name.
159
+ * @param method - Method name to call in the endpoint class.
160
+ * @param params - Optional parameters to pass to the method.
161
+ * @param init - Optional parameters for the request
162
+ * @returns Decoded JSON response data.
163
+ */
164
+ call(endpoint: string, method: string, params?: Record<string, unknown>, init?: EndpointRequestInit): Promise<any>;
165
+ /**
166
+ * Subscribes to the given method defined using the endpoint and method
167
+ * parameters with the parameters given as params. The method must return a
168
+ * compatible type such as a Flux.
169
+ * Returns a subscription that is used to fetch values as they become available.
170
+ *
171
+ * @param endpoint - Endpoint name.
172
+ * @param method - Method name to call in the endpoint class.
173
+ * @param params - Optional parameters to pass to the method.
174
+ * @returns A subscription used to handles values as they become available.
175
+ */
176
+ subscribe(endpoint: string, method: string, params?: any): Subscription<any>;
172
177
  }
173
- //# sourceMappingURL=Connect.d.ts.map