@fhss-web-team/frontend-utils 1.6.1 → 1.6.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,352 +1,4 @@
1
- import { Signal } from '@angular/core';
2
- type JsonValue = string | number | boolean | null | JsonArray | JsonObject;
3
- export type JsonObject = {
4
- [key: string]: JsonValue;
5
- };
6
- type JsonArray = JsonValue[];
7
- export type Json = JsonObject | JsonArray;
8
- export type Maybe<T> = T | undefined | null;
9
- type DefaultError = {
10
- code?: string;
11
- message?: string;
12
- details?: Json;
13
- };
14
- type KnownHeaderKeys = 'Accept' | 'Accept-Encoding' | 'Accept-Language' | 'Access-Control-Request-Headers' | 'Access-Control-Request-Method' | 'Authorization' | 'Cache-Control' | 'Connection' | 'Content-Encoding' | 'Content-Length' | 'Content-Type' | 'Cookie' | 'Date' | 'Expect' | 'Forwarded' | 'From' | 'Host' | 'If-Match' | 'If-Modified-Since' | 'If-None-Match' | 'If-Range' | 'If-Unmodified-Since' | 'Keep-Alive' | 'Max-Forwards' | 'Origin' | 'Prefer' | 'Priority' | 'Proxy-Authorization' | 'Range' | 'Referer' | 'TE' | 'Transfer-Encoding' | 'Upgrade' | 'User-Agent' | 'Via';
15
- /**
16
- * A value that may be a plain value of type `T` or a reactive `Signal<T>`.
17
- *
18
- * This is useful in APIs that accept either static or reactive values,
19
- * allowing flexibility while maintaining type safety.
20
- *
21
- * Use `unwrapSignal` to extract the underlying value in a uniform way.
22
- *
23
- * @template T The underlying value type.
24
- */
25
- export type MaybeSignal<T> = T | Signal<T>;
26
- /**
27
- * Reads the underlying value from a MaybeSignal.
28
- *
29
- * This function is designed for use with reactive APIs (like fetchSignal) where it's important
30
- * that Angular's computed methods register the dependency. If the input is a Signal, invoking it
31
- * not only returns its current value but also tracks the signal for reactivity. If the input is
32
- * a plain value, it simply returns that value.
33
- *
34
- * @template T The type of the value.
35
- * @param value A plain value or a Signal that yields the value.
36
- * @returns The current value, with dependency tracking enabled if the input is a Signal.
37
- */
38
- export declare function readMaybeSignal<T>(value: MaybeSignal<T>): T;
39
- type FetchSignalRequest = {
40
- url: string;
41
- body?: unknown;
42
- params?: Record<string, string | number | boolean | undefined>;
43
- headers?: Partial<Record<KnownHeaderKeys, string>> & Record<string, string>;
44
- };
45
- /**
46
- * Represents the reactive result of an HTTP fetch request.
47
- */
48
- export type FetchSignal<Response, Error = DefaultError> = {
49
- value: Signal<Maybe<Response>>;
50
- persistentValue: Signal<Maybe<Response>>;
51
- isLoading: Signal<boolean>;
52
- error: Signal<Maybe<Error>>;
53
- statusCode: Signal<Maybe<number>>;
54
- headers: Signal<Maybe<Record<string, string>>>;
55
- refresh: (abortSignal?: AbortSignal) => void;
56
- };
57
- type FetchSignalFactory = {
58
- /**
59
- * Initiates a reactive HTTP GET request using the provided request configuration.
60
- *
61
- * @template Response - The expected response type.
62
- * @template Error - The expected error shape (defaults to `DefaultError`).
63
- * @param request - The configuration object for the HTTP GET request.
64
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
65
- * @returns A `FetchSignal` object containing reactive signals for the response data, loading state, status code, error, headers, and a refresh method.
66
- */
67
- <Response extends Json, Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean): FetchSignal<Response, Error>;
68
- /**
69
- * Initiates a reactive HTTP GET request using the provided request configuration and parses the response as JSON.
70
- *
71
- * @template Response - The expected response type.
72
- * @template Error - The expected error shape (defaults to `DefaultError`).
73
- * @param request - The configuration object for the HTTP GET request.
74
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
75
- * @returns A `FetchSignal` object with the JSON-parsed response.
76
- */
77
- json: <Response extends Json, Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<Response, Error>;
78
- /**
79
- * Initiates a reactive HTTP GET request using the provided request configuration and parses the response as plain text.
80
- *
81
- * @template Error - The expected error shape (defaults to `DefaultError`).
82
- * @param request - The configuration object for the HTTP GET request.
83
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
84
- * @returns A `FetchSignal` object with the text response.
85
- */
86
- text: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<string, Error>;
87
- /**
88
- * Initiates a reactive HTTP GET request using the provided request configuration and parses the response as a Blob.
89
- *
90
- * @template Error - The expected error shape (defaults to `DefaultError`).
91
- * @param request - The configuration object for the HTTP GET request.
92
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
93
- * @returns A `FetchSignal` object with the Blob response.
94
- */
95
- blob: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<Blob, Error>;
96
- /**
97
- * Initiates a reactive HTTP GET request using the provided request configuration and parses the response as an ArrayBuffer.
98
- *
99
- * @template Error - The expected error shape (defaults to `DefaultError`).
100
- * @param request - The configuration object for the HTTP GET request.
101
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
102
- * @returns A `FetchSignal` object with the ArrayBuffer response.
103
- */
104
- arrayBuffer: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<ArrayBuffer, Error>;
105
- get: {
106
- /**
107
- * Initiates a reactive HTTP GET request using the provided request configuration.
108
- *
109
- * @template Response - The expected response type.
110
- * @template Error - The expected error shape (defaults to `DefaultError`).
111
- * @param request - The configuration object for the HTTP GET request.
112
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
113
- * @returns A `FetchSignal` object containing reactive signals for the response data, loading state, status code, error, headers, and a refresh method.
114
- */
115
- <Response extends Json, Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean): FetchSignal<Response, Error>;
116
- /**
117
- * Initiates a reactive HTTP GET request using the provided request configuration and parses the response as JSON.
118
- *
119
- * @template Response - The expected response type.
120
- * @template Error - The expected error shape (defaults to `DefaultError`).
121
- * @param request - The configuration object for the HTTP GET request.
122
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
123
- * @returns A `FetchSignal` object with the JSON-parsed response.
124
- */
125
- json: <Response extends Json, Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<Response, Error>;
126
- /**
127
- * Initiates a reactive HTTP GET request using the provided request configuration and parses the response as plain text.
128
- *
129
- * @template Error - The expected error shape (defaults to `DefaultError`).
130
- * @param request - The configuration object for the HTTP GET request.
131
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
132
- * @returns A `FetchSignal` object with the text response.
133
- */
134
- text: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<string, Error>;
135
- /**
136
- * Initiates a reactive HTTP GET request using the provided request configuration and parses the response as a Blob.
137
- *
138
- * @template Error - The expected error shape (defaults to `DefaultError`).
139
- * @param request - The configuration object for the HTTP GET request.
140
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
141
- * @returns A `FetchSignal` object with the Blob response.
142
- */
143
- blob: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<Blob, Error>;
144
- /**
145
- * Initiates a reactive HTTP GET request using the provided request configuration and parses the response as an ArrayBuffer.
146
- *
147
- * @template Error - The expected error shape (defaults to `DefaultError`).
148
- * @param request - The configuration object for the HTTP GET request.
149
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
150
- * @returns A `FetchSignal` object with the ArrayBuffer response.
151
- */
152
- arrayBuffer: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<ArrayBuffer, Error>;
153
- };
154
- post: {
155
- /**
156
- * Initiates a reactive HTTP POST request using the provided request configuration.
157
- *
158
- * @template Response - The expected response type.
159
- * @template Error - The expected error shape (defaults to `DefaultError`).
160
- * @param request - The configuration object for the HTTP POST request, which must include a body.
161
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
162
- * @returns A `FetchSignal` object containing reactive signals for the response data, loading state, status code, error, headers, and a refresh method.
163
- */
164
- <Response extends Json, Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean): FetchSignal<Response, Error>;
165
- /**
166
- * Initiates a reactive HTTP POST request using the provided request configuration and parses the response as JSON.
167
- *
168
- * @template Response - The expected response type.
169
- * @template Error - The expected error shape (defaults to `DefaultError`).
170
- * @param request - The configuration object for the HTTP POST request, which must include a body.
171
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
172
- * @returns A `FetchSignal` object with the JSON-parsed response.
173
- */
174
- json: <Response extends Json, Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<Response, Error>;
175
- /**
176
- * Initiates a reactive HTTP POST request using the provided request configuration and parses the response as plain text.
177
- *
178
- * @template Error - The expected error shape (defaults to `DefaultError`).
179
- * @param request - The configuration object for the HTTP POST request, which must include a body.
180
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
181
- * @returns A `FetchSignal` object with the text response.
182
- */
183
- text: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<string, Error>;
184
- /**
185
- * Initiates a reactive HTTP POST request using the provided request configuration and parses the response as a Blob.
186
- *
187
- * @template Error - The expected error shape (defaults to `DefaultError`).
188
- * @param request - The configuration object for the HTTP POST request, which must include a body.
189
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
190
- * @returns A `FetchSignal` object with the Blob response.
191
- */
192
- blob: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<Blob, Error>;
193
- /**
194
- * Initiates a reactive HTTP POST request using the provided request configuration and parses the response as an ArrayBuffer.
195
- *
196
- * @template Error - The expected error shape (defaults to `DefaultError`).
197
- * @param request - The configuration object for the HTTP POST request, which must include a body.
198
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
199
- * @returns A `FetchSignal` object with the ArrayBuffer response.
200
- */
201
- arrayBuffer: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<ArrayBuffer, Error>;
202
- };
203
- put: {
204
- /**
205
- * Initiates a reactive HTTP PUT request using the provided request configuration.
206
- *
207
- * @template Response - The expected response type.
208
- * @template Error - The expected error shape (defaults to `DefaultError`).
209
- * @param request - The configuration object for the HTTP PUT request, which must include a body.
210
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
211
- * @returns A `FetchSignal` object containing reactive signals for the response data, loading state, status code, error, headers, and a refresh method.
212
- */
213
- <Response extends Json, Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean): FetchSignal<Response, Error>;
214
- /**
215
- * Initiates a reactive HTTP PUT request using the provided request configuration and parses the response as JSON.
216
- *
217
- * @template Response - The expected response type.
218
- * @template Error - The expected error shape (defaults to `DefaultError`).
219
- * @param request - The configuration object for the HTTP PUT request, which must include a body.
220
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
221
- * @returns A `FetchSignal` object with the JSON-parsed response.
222
- */
223
- json: <Response extends Json, Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<Response, Error>;
224
- /**
225
- * Initiates a reactive HTTP PUT request using the provided request configuration and parses the response as plain text.
226
- *
227
- * @template Error - The expected error shape (defaults to `DefaultError`).
228
- * @param request - The configuration object for the HTTP PUT request, which must include a body.
229
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
230
- * @returns A `FetchSignal` object with the text response.
231
- */
232
- text: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<string, Error>;
233
- /**
234
- * Initiates a reactive HTTP PUT request using the provided request configuration and parses the response as a Blob.
235
- *
236
- * @template Error - The expected error shape (defaults to `DefaultError`).
237
- * @param request - The configuration object for the HTTP PUT request, which must include a body.
238
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
239
- * @returns A `FetchSignal` object with the Blob response.
240
- */
241
- blob: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<Blob, Error>;
242
- /**
243
- * Initiates a reactive HTTP PUT request using the provided request configuration and parses the response as an ArrayBuffer.
244
- *
245
- * @template Error - The expected error shape (defaults to `DefaultError`).
246
- * @param request - The configuration object for the HTTP PUT request, which must include a body.
247
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
248
- * @returns A `FetchSignal` object with the ArrayBuffer response.
249
- */
250
- arrayBuffer: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<ArrayBuffer, Error>;
251
- };
252
- patch: {
253
- /**
254
- * Initiates a reactive HTTP PATCH request using the provided request configuration.
255
- *
256
- * @template Response - The expected response type.
257
- * @template Error - The expected error shape (defaults to `DefaultError`).
258
- * @param request - The configuration object for the HTTP PATCH request, which must include a body.
259
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
260
- * @returns A `FetchSignal` object containing reactive signals for the response data, loading state, status code, error, headers, and a refresh method.
261
- */
262
- <Response extends Json, Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean): FetchSignal<Response, Error>;
263
- /**
264
- * Initiates a reactive HTTP PATCH request using the provided request configuration and parses the response as JSON.
265
- *
266
- * @template Response - The expected response type.
267
- * @template Error - The expected error shape (defaults to `DefaultError`).
268
- * @param request - The configuration object for the HTTP PATCH request, which must include a body.
269
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
270
- * @returns A `FetchSignal` object with the JSON-parsed response.
271
- */
272
- json: <Response extends Json, Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<Response, Error>;
273
- /**
274
- * Initiates a reactive HTTP PATCH request using the provided request configuration and parses the response as plain text.
275
- *
276
- * @template Error - The expected error shape (defaults to `DefaultError`).
277
- * @param request - The configuration object for the HTTP PATCH request, which must include a body.
278
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
279
- * @returns A `FetchSignal` object with the text response.
280
- */
281
- text: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<string, Error>;
282
- /**
283
- * Initiates a reactive HTTP PATCH request using the provided request configuration and parses the response as a Blob.
284
- *
285
- * @template Error - The expected error shape (defaults to `DefaultError`).
286
- * @param request - The configuration object for the HTTP PATCH request, which must include a body.
287
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
288
- * @returns A `FetchSignal` object with the Blob response.
289
- */
290
- blob: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<Blob, Error>;
291
- /**
292
- * Initiates a reactive HTTP PATCH request using the provided request configuration and parses the response as an ArrayBuffer.
293
- *
294
- * @template Error - The expected error shape (defaults to `DefaultError`).
295
- * @param request - The configuration object for the HTTP PATCH request, which must include a body.
296
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
297
- * @returns A `FetchSignal` object with the ArrayBuffer response.
298
- */
299
- arrayBuffer: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<ArrayBuffer, Error>;
300
- };
301
- delete: {
302
- /**
303
- * Initiates a reactive HTTP DELETE request using the provided request configuration.
304
- *
305
- * @template Response - The expected response type.
306
- * @template Error - The expected error shape (defaults to `DefaultError`).
307
- * @param request - The configuration object for the HTTP DELETE request.
308
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
309
- * @returns A `FetchSignal` object containing reactive signals for the response data, loading state, status code, error, headers, and a refresh method.
310
- */
311
- <Response extends Json, Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean): FetchSignal<Response, Error>;
312
- /**
313
- * Initiates a reactive HTTP DELETE request using the provided request configuration and parses the response as JSON.
314
- *
315
- * @template Response - The expected response type.
316
- * @template Error - The expected error shape (defaults to `DefaultError`).
317
- * @param request - The configuration object for the HTTP DELETE request.
318
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
319
- * @returns A `FetchSignal` object with the JSON-parsed response.
320
- */
321
- json: <Response extends Json, Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<Response, Error>;
322
- /**
323
- * Initiates a reactive HTTP DELETE request using the provided request configuration and parses the response as plain text.
324
- *
325
- * @template Error - The expected error shape (defaults to `DefaultError`).
326
- * @param request - The configuration object for the HTTP DELETE request.
327
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
328
- * @returns A `FetchSignal` object with the text response.
329
- */
330
- text: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<string, Error>;
331
- /**
332
- * Initiates a reactive HTTP DELETE request using the provided request configuration and parses the response as a Blob.
333
- *
334
- * @template Error - The expected error shape (defaults to `DefaultError`).
335
- * @param request - The configuration object for the HTTP DELETE request.
336
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
337
- * @returns A `FetchSignal` object with the Blob response.
338
- */
339
- blob: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<Blob, Error>;
340
- /**
341
- * Initiates a reactive HTTP DELETE request using the provided request configuration and parses the response as an ArrayBuffer.
342
- *
343
- * @template Error - The expected error shape (defaults to `DefaultError`).
344
- * @param request - The configuration object for the HTTP DELETE request.
345
- * @param autoRefresh - whether or not the request should be automatically refreshed when the request input signals have changed value
346
- * @returns A `FetchSignal` object with the ArrayBuffer response.
347
- */
348
- arrayBuffer: <Error extends Json = DefaultError>(request: () => FetchSignalRequest, autoRefresh?: boolean) => FetchSignal<ArrayBuffer, Error>;
349
- };
350
- };
1
+ import { FetchSignalFactory, Json } from './fetch-signal.types';
351
2
  declare const fetchSignal: FetchSignalFactory;
352
3
  export { fetchSignal };
4
+ export type { Json };