@reforgium/statum 3.0.1 → 3.1.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.
- package/CHANGELOG.md +218 -0
- package/LICENSE +21 -0
- package/README.md +33 -6
- package/fesm2022/reforgium-statum.mjs +137 -656
- package/package.json +17 -6
- package/types/reforgium-statum.d.ts +44 -310
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.
|
|
2
|
+
"version": "3.1.1",
|
|
3
3
|
"name": "@reforgium/statum",
|
|
4
|
-
"description": "Signals-first
|
|
4
|
+
"description": "Signals-first API state and query stores for Angular",
|
|
5
5
|
"author": "rtommievich",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -21,10 +21,21 @@
|
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"reforgium",
|
|
24
|
-
"
|
|
24
|
+
"angular",
|
|
25
|
+
"angular-library",
|
|
26
|
+
"signals",
|
|
27
|
+
"signal-store",
|
|
25
28
|
"store",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
29
|
+
"data-store",
|
|
30
|
+
"resource-store",
|
|
31
|
+
"entity-store",
|
|
32
|
+
"dictionary",
|
|
33
|
+
"query",
|
|
34
|
+
"pagination",
|
|
35
|
+
"cache",
|
|
36
|
+
"http",
|
|
37
|
+
"api",
|
|
38
|
+
"serializer"
|
|
28
39
|
],
|
|
29
40
|
"types": "../../dist/@reforgium/statum/index.d.ts",
|
|
30
41
|
"files": [
|
|
@@ -42,7 +53,7 @@
|
|
|
42
53
|
"peerDependencies": {
|
|
43
54
|
"@angular/common": ">=18.0.0",
|
|
44
55
|
"@angular/core": ">=18.0.0",
|
|
45
|
-
"@reforgium/internal": ">=
|
|
56
|
+
"@reforgium/internal": ">=2.0.0",
|
|
46
57
|
"rxjs": ">=7.0.0"
|
|
47
58
|
},
|
|
48
59
|
"module": "fesm2022/reforgium-statum.mjs",
|
|
@@ -1,295 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataType, SerializerConfig, Serializer, RestMethods, AnyDict, AnyType, QueryParams, PageableRequest, PageableResponse, StorageStrategy } from '@reforgium/internal';
|
|
2
|
+
export { DataType, FieldConcatType, FieldConfig, FormatConfig, LocalStorage, LruCache, MemoryStorage, ParseFormatConfig, SerializedType, Serializer, SerializerConfig, SerializerFieldError, SessionStorage, StorageInterface, StorageStrategy, StorageStrategyOptions, Types, storageStrategy } from '@reforgium/internal';
|
|
2
3
|
import * as _angular_core from '@angular/core';
|
|
3
4
|
import { Signal, WritableSignal, EnvironmentProviders, InjectionToken } from '@angular/core';
|
|
5
|
+
import { HttpResponse } from '@angular/common/http';
|
|
4
6
|
import * as _reforgium_statum from '@reforgium/statum';
|
|
5
7
|
|
|
6
|
-
/**
|
|
7
|
-
* List of supported primitive and composite data types
|
|
8
|
-
* that can be serialized/deserialized.
|
|
9
|
-
*
|
|
10
|
-
* Used in field serialization configuration.
|
|
11
|
-
*/
|
|
12
|
-
type Types = 'string' | 'number' | 'boolean' | 'array' | 'object' | 'date' | 'period' | 'nullable';
|
|
13
|
-
type FieldConcatType = 'comma' | 'multi' | 'json';
|
|
14
|
-
/**
|
|
15
|
-
* Allowed "flat" values after serialization.
|
|
16
|
-
* Such values are safe to pass in a query string or JSON.
|
|
17
|
-
*/
|
|
18
|
-
type SerializedPrimitives = string | number | boolean | null;
|
|
19
|
-
type SerializedTypeType = SerializedPrimitives | SerializedPrimitives[];
|
|
20
|
-
type DatePeriod = [Date | null, Date | null];
|
|
21
|
-
/**
|
|
22
|
-
* Generic configuration shape to define `parse`/`format`
|
|
23
|
-
* for converting a value from/to a serialized form.
|
|
24
|
-
*
|
|
25
|
-
* @template TypeFrom — domain type before serialization
|
|
26
|
-
* @template TypeTo — serialized type (by default a primitive/array of primitives)
|
|
27
|
-
*/
|
|
28
|
-
type ParseFormatConfig<TypeFrom, TypeTo = SerializedTypeType> = {
|
|
29
|
-
parse?: (val: TypeTo) => TypeFrom;
|
|
30
|
-
format?: (val: TypeFrom) => TypeTo;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Simplified configuration when only `format` is needed.
|
|
34
|
-
*/
|
|
35
|
-
type FormatConfig<TypeFrom, TypeTo = SerializedTypeType> = {
|
|
36
|
-
format?: (val: TypeFrom) => TypeTo;
|
|
37
|
-
};
|
|
38
|
-
type FieldConfig = ({
|
|
39
|
-
type: Types;
|
|
40
|
-
concatType?: FieldConcatType;
|
|
41
|
-
} | FieldsTypeConfig<DataType, AnyType>) & {
|
|
42
|
-
concatType?: FieldConcatType;
|
|
43
|
-
};
|
|
44
|
-
type FieldsTypeConfig<EntityType extends DataType, TypeFrom, TypeTo = SerializedTypeType> = {
|
|
45
|
-
parse: (val: TypeTo, data: SerializedType) => TypeFrom;
|
|
46
|
-
format: (val: TypeFrom, data: EntityType) => TypeTo;
|
|
47
|
-
};
|
|
48
|
-
type PeriodSplitMode = {
|
|
49
|
-
mode: 'split';
|
|
50
|
-
dateFromKeyPostfix: string;
|
|
51
|
-
dateToKeyPostfix: string;
|
|
52
|
-
};
|
|
53
|
-
type PeriodJoinMode = {
|
|
54
|
-
mode: 'join';
|
|
55
|
-
concat: string;
|
|
56
|
-
};
|
|
57
|
-
type SerializerConfig = {
|
|
58
|
-
mapString: {
|
|
59
|
-
trim?: boolean;
|
|
60
|
-
} & ParseFormatConfig<string>;
|
|
61
|
-
mapNumber: {
|
|
62
|
-
fromString?: boolean;
|
|
63
|
-
} & ParseFormatConfig<number>;
|
|
64
|
-
mapBoolean: {
|
|
65
|
-
true?: string;
|
|
66
|
-
false?: string;
|
|
67
|
-
} & ParseFormatConfig<boolean>;
|
|
68
|
-
mapDate: {
|
|
69
|
-
dateFormat?: string;
|
|
70
|
-
} & ParseFormatConfig<Date>;
|
|
71
|
-
/**
|
|
72
|
-
* Settings for date period transformation.
|
|
73
|
-
* Allows choosing a mode:
|
|
74
|
-
* - split: split the period into two keys (e.g., createdFrom/createdTo)
|
|
75
|
-
* - join: join into a string using a delimiter
|
|
76
|
-
* And set the date format.
|
|
77
|
-
*/
|
|
78
|
-
mapPeriod: {
|
|
79
|
-
transformMode?: PeriodSplitMode | PeriodJoinMode;
|
|
80
|
-
dateFormat?: string;
|
|
81
|
-
} & ParseFormatConfig<DatePeriod>;
|
|
82
|
-
/**
|
|
83
|
-
* Settings for handling "empty" values.
|
|
84
|
-
* - remove: remove the field from the result;
|
|
85
|
-
* - replaceWith: replace with a fixed value;
|
|
86
|
-
* - includeEmptyString: treat an empty string as "nullable".
|
|
87
|
-
*/
|
|
88
|
-
mapNullable: {
|
|
89
|
-
remove?: boolean;
|
|
90
|
-
replaceWith?: string;
|
|
91
|
-
includeEmptyString?: boolean;
|
|
92
|
-
} & ParseFormatConfig<null | undefined>;
|
|
93
|
-
/**
|
|
94
|
-
* Array settings:
|
|
95
|
-
* - concatType: serialization strategy (`comma` | `multi` | `json`);
|
|
96
|
-
* - removeNullable: remove empty items;
|
|
97
|
-
* - format: custom array formatter.
|
|
98
|
-
*/
|
|
99
|
-
mapArray: {
|
|
100
|
-
concatType: FieldConcatType;
|
|
101
|
-
removeNullable?: boolean;
|
|
102
|
-
} & FormatConfig<AnyType[]>;
|
|
103
|
-
/**
|
|
104
|
-
* Object settings:
|
|
105
|
-
* - deep: deep (recursive) serialization or treat as JSON string;
|
|
106
|
-
* - format: custom object formatter.
|
|
107
|
-
*/
|
|
108
|
-
mapObject: {
|
|
109
|
-
deep: boolean;
|
|
110
|
-
} & FormatConfig<DataType>;
|
|
111
|
-
/**
|
|
112
|
-
* Per-field overrides by key.
|
|
113
|
-
*/
|
|
114
|
-
mapFields?: Record<string, FieldConfig>;
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* Flat serialization result: dictionary key → primitive(s).
|
|
118
|
-
*/
|
|
119
|
-
type SerializedType = Record<string, SerializedTypeType>;
|
|
120
|
-
/**
|
|
121
|
-
* Generic dictionary of domain data.
|
|
122
|
-
*/
|
|
123
|
-
type DataType = AnyDict;
|
|
124
|
-
|
|
125
|
-
declare class SerializerFieldError extends Error {
|
|
126
|
-
readonly field: string;
|
|
127
|
-
readonly stage: 'parse' | 'format';
|
|
128
|
-
readonly originalError: unknown;
|
|
129
|
-
constructor(field: string, stage: 'parse' | 'format', originalError: unknown);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Universal serializer/deserializer for values used in forms, filters, and DTOs.
|
|
133
|
-
*
|
|
134
|
-
* Supports types: `string | number | boolean | Date | [Date, Date] (period) | array | object | nullable`.
|
|
135
|
-
* Capabilities:
|
|
136
|
-
* - normalize values according to config (trim strings, parse numbers from strings, boolean strings, etc.),
|
|
137
|
-
* - transform date periods into paired keys (`from/to`) or a single joined string,
|
|
138
|
-
* - build/parse a query string (or JSON) to and from an object.
|
|
139
|
-
*
|
|
140
|
-
* Example:
|
|
141
|
-
* ```ts
|
|
142
|
-
* type Filters = { q?: string; active?: boolean; created?: [Date, Date] | null };
|
|
143
|
-
* const s = new Serializer<Filters>({
|
|
144
|
-
* mapPeriod: { transformMode: { mode: 'split', dateFromKeyPostfix: 'From', dateToKeyPostfix: 'To' } }
|
|
145
|
-
* });
|
|
146
|
-
*
|
|
147
|
-
* // -> { q: 'john', createdFrom: '2025-01-01', createdTo: '2025-01-31' }
|
|
148
|
-
* const plain = s.serialize({
|
|
149
|
-
* q: ' john ',
|
|
150
|
-
* active: undefined,
|
|
151
|
-
* created: [new Date('2025-01-01'), new Date('2025-01-31')]
|
|
152
|
-
* });
|
|
153
|
-
*
|
|
154
|
-
* // -> 'q=john&createdFrom=2025-01-01&createdTo=2025-01-31'
|
|
155
|
-
* const qs = s.toQuery({ q: 'john', created: [new Date('2025-01-01'), new Date('2025-01-31')] });
|
|
156
|
-
*
|
|
157
|
-
* // <- { q: 'john', created: [Date, Date] }
|
|
158
|
-
* const parsed = s.deserialize('q=john&createdFrom=2025-01-01&createdTo=2025-01-31');
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
declare class Serializer<EntityType extends DataType> {
|
|
162
|
-
readonly config: SerializerConfig;
|
|
163
|
-
/**
|
|
164
|
-
* Creates a serializer with a partially overridden configuration.
|
|
165
|
-
* Provide only the options you want to change (the rest are taken from defaults).
|
|
166
|
-
*
|
|
167
|
-
* @param config partial transformation configuration
|
|
168
|
-
*/
|
|
169
|
-
constructor(config?: Partial<SerializerConfig>);
|
|
170
|
-
/**
|
|
171
|
-
* Converts a domain object into a flat serialized representation
|
|
172
|
-
* (ready to send to an API or build a query string).
|
|
173
|
-
*
|
|
174
|
-
* Rules are taken from `config`:
|
|
175
|
-
* — strings can be trimmed (if enabled),
|
|
176
|
-
* — numbers can be converted from strings/numbers,
|
|
177
|
-
* — boolean supports custom true/false representations,
|
|
178
|
-
* — dates are formatted by `dateFormat`,
|
|
179
|
-
* — date periods can be split/joined,
|
|
180
|
-
* — `nullable` can be removed from the result (`remove`) or formatted.
|
|
181
|
-
*
|
|
182
|
-
* @param obj source object
|
|
183
|
-
* @returns a flat dictionary with string/primitive values
|
|
184
|
-
*/
|
|
185
|
-
serialize(obj: EntityType): SerializedType;
|
|
186
|
-
/**
|
|
187
|
-
* Parse serialized data into a domain object.
|
|
188
|
-
*
|
|
189
|
-
* Source can be:
|
|
190
|
-
* — a query string (`key=value&arr=1,2`) or `JSON.stringify(obj)`,
|
|
191
|
-
* — an already prepared flat object.
|
|
192
|
-
*
|
|
193
|
-
* Transformations are reverse of `serialize`: strings → number/boolean/Date/period,
|
|
194
|
-
* arrays are collected according to strategy (`comma`/`pipe`/`multi`), objects — deeply or as JSON.
|
|
195
|
-
*
|
|
196
|
-
* @param val query string or object
|
|
197
|
-
* @returns a domain object of the specified type
|
|
198
|
-
*/
|
|
199
|
-
deserialize: (val: string | AnyDict) => EntityType;
|
|
200
|
-
/** Parse only query-string input. */
|
|
201
|
-
deserializeQuery: (query: string) => EntityType;
|
|
202
|
-
/** Parse only JSON object input. */
|
|
203
|
-
deserializeJson: (json: string) => EntityType;
|
|
204
|
-
/**
|
|
205
|
-
* Build a query string from a domain object using `serialize` rules
|
|
206
|
-
* and the array joining strategy (`concatType`).
|
|
207
|
-
*
|
|
208
|
-
* @param val domain object
|
|
209
|
-
* @returns query string (suitable for URL or history API)
|
|
210
|
-
*/
|
|
211
|
-
toQuery: (val: EntityType) => string;
|
|
212
|
-
/**
|
|
213
|
-
* Returns a new serializer instance with a merged configuration.
|
|
214
|
-
* Useful for ad-hoc overrides for a specific call.
|
|
215
|
-
*
|
|
216
|
-
* @param config partial config changes
|
|
217
|
-
* @returns new `Serializer` with the provided `config` applied
|
|
218
|
-
*/
|
|
219
|
-
withConfig(config: Partial<SerializerConfig>): Serializer<EntityType>;
|
|
220
|
-
private serializeElement;
|
|
221
|
-
private deserializeElement;
|
|
222
|
-
private parseQuery;
|
|
223
|
-
private parseJsonObject;
|
|
224
|
-
private parseInputString;
|
|
225
|
-
private mergeConfig;
|
|
226
|
-
private resolveArrayFieldModes;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
8
|
declare const createQuerySerializer: <EntityType extends DataType = DataType>(config?: Partial<SerializerConfig>) => Serializer<EntityType>;
|
|
230
9
|
declare const createBodySerializer: <EntityType extends DataType = DataType>(config?: Partial<SerializerConfig>) => Serializer<EntityType>;
|
|
231
10
|
declare const createStrictSerializer: <EntityType extends DataType = DataType>(config?: Partial<SerializerConfig>) => Serializer<EntityType>;
|
|
232
11
|
|
|
233
|
-
type StorageStrategy = 'memory' | 'lru' | 'session' | 'persist';
|
|
234
|
-
type StorageStrategyOptions = {
|
|
235
|
-
lruLimit?: number;
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
type StorageInterface<Key, Type> = {
|
|
239
|
-
prefix?: string;
|
|
240
|
-
get(key: Key): Type | null;
|
|
241
|
-
set(key: Key, value: Type): void;
|
|
242
|
-
remove(key: Key): void;
|
|
243
|
-
clear(): void;
|
|
244
|
-
get length(): number;
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
declare class LruCache<KeyT, ValueT> implements StorageInterface<KeyT, ValueT> {
|
|
248
|
-
private map;
|
|
249
|
-
private _limit;
|
|
250
|
-
constructor(limit?: number);
|
|
251
|
-
get limit(): number;
|
|
252
|
-
get length(): number;
|
|
253
|
-
set limit(value: number);
|
|
254
|
-
get(key: KeyT): NonNullable<ValueT> | null;
|
|
255
|
-
set(key: KeyT, value: ValueT): void;
|
|
256
|
-
remove(key: KeyT): boolean;
|
|
257
|
-
clear(): void;
|
|
258
|
-
has(key: KeyT): boolean;
|
|
259
|
-
keys(): KeyT[];
|
|
260
|
-
values(): ValueT[];
|
|
261
|
-
entries(): [KeyT, ValueT][];
|
|
262
|
-
toArray(): ValueT[];
|
|
263
|
-
fromArray(entries: [KeyT, ValueT][]): void;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Factory for data storage strategies.
|
|
268
|
-
*
|
|
269
|
-
* Returns a `StorageInterface` implementation depending on the selected strategy:
|
|
270
|
-
* - `'memory'` — in-memory storage (for the session lifetime);
|
|
271
|
-
* - `'session'` — `sessionStorage`, lives until the tab is closed;
|
|
272
|
-
* - `'persist'` — `localStorage`, persists between sessions;
|
|
273
|
-
* - `'lru'` — size-limited cache (Least Recently Used).
|
|
274
|
-
*
|
|
275
|
-
* Used to choose an appropriate storage implementation
|
|
276
|
-
* depending on the scenario: temporary data, long-term, cache, etc.
|
|
277
|
-
*
|
|
278
|
-
* @param strategy storage strategy type (`memory`, `session`, `persist`, `lru`)
|
|
279
|
-
* @returns instance implementing `StorageInterface<Key, Type>`
|
|
280
|
-
*/
|
|
281
|
-
declare const storageStrategy: <Key = string, Type extends AnyType = AnyDict>(strategy: StorageStrategy, options?: StorageStrategyOptions) => StorageInterface<Key, Type>;
|
|
282
|
-
|
|
283
12
|
/**
|
|
284
13
|
* Object for request body (payload).
|
|
285
14
|
* Commonly used with POST/PUT/PATCH/DELETE.
|
|
15
|
+
* `FormData`, `Blob`, and `ArrayBuffer` are passed through as-is without serialization.
|
|
286
16
|
*/
|
|
287
|
-
type PayloadData = AnyDict;
|
|
17
|
+
type PayloadData = AnyDict | FormData | Blob | ArrayBuffer;
|
|
288
18
|
/**
|
|
289
|
-
* Simple parameters dictionary (string/number).
|
|
290
|
-
* Suitable for path params and query.
|
|
19
|
+
* Simple path parameters dictionary (string/number).
|
|
291
20
|
*/
|
|
292
21
|
type SimpleDict = Record<string, string | number>;
|
|
22
|
+
/**
|
|
23
|
+
* Query parameters dictionary with scalar and array support.
|
|
24
|
+
*/
|
|
25
|
+
type QueryDict = Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
|
|
293
26
|
/**
|
|
294
27
|
* Resource status in `ResourceStore`:
|
|
295
28
|
* - `idle` — not loaded yet
|
|
@@ -310,6 +43,11 @@ type RetryConfig = {
|
|
|
310
43
|
attempts?: number;
|
|
311
44
|
delayMs?: number;
|
|
312
45
|
backoff?: RetryBackoff;
|
|
46
|
+
/**
|
|
47
|
+
* Add ±25% random jitter to the retry delay to avoid synchronized retries
|
|
48
|
+
* across multiple clients hitting the same endpoint simultaneously.
|
|
49
|
+
*/
|
|
50
|
+
jitter?: boolean;
|
|
313
51
|
shouldRetry?: (error: unknown, attempt: number) => boolean;
|
|
314
52
|
};
|
|
315
53
|
/**
|
|
@@ -347,6 +85,12 @@ type ResourceStoreOptions = {
|
|
|
347
85
|
retry?: RetryConfig;
|
|
348
86
|
/** Trace hook for request/cache lifecycle events. */
|
|
349
87
|
onTrace?: (event: ResourceTraceEvent) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Side-effect hook called with the full `HttpResponse` for every completed request.
|
|
90
|
+
* Useful for reading response headers (e.g. `X-Total-Count`, `Link`, correlation IDs).
|
|
91
|
+
* Errors thrown here are silently swallowed.
|
|
92
|
+
*/
|
|
93
|
+
onResponse?: (response: HttpResponse<unknown>) => void;
|
|
350
94
|
serializer?: Partial<SerializerConfig>;
|
|
351
95
|
};
|
|
352
96
|
/**
|
|
@@ -355,7 +99,7 @@ type ResourceStoreOptions = {
|
|
|
355
99
|
* - `query` — query string parameters
|
|
356
100
|
* - `payload` — request body (for mutations)
|
|
357
101
|
*/
|
|
358
|
-
type CallArgs<Params extends SimpleDict = SimpleDict, Query extends
|
|
102
|
+
type CallArgs<Params extends SimpleDict = SimpleDict, Query extends QueryDict = QueryDict, Payload extends PayloadData = PayloadData> = {
|
|
359
103
|
params?: Params;
|
|
360
104
|
query?: Query;
|
|
361
105
|
payload?: Payload;
|
|
@@ -385,6 +129,12 @@ type CallConfig<Response, Type> = {
|
|
|
385
129
|
* - 'arraybuffer' - response as an ArrayBuffer
|
|
386
130
|
*/
|
|
387
131
|
responseType?: 'json' | 'text' | 'blob' | 'arraybuffer';
|
|
132
|
+
/**
|
|
133
|
+
* Controls what is passed to `parseResponse`:
|
|
134
|
+
* - `'body'` (default) — receives the response body (`Response`)
|
|
135
|
+
* - `'response'` — receives the full `HttpResponse<Response>` (headers, status, body)
|
|
136
|
+
*/
|
|
137
|
+
observe?: 'body' | 'response';
|
|
388
138
|
/**
|
|
389
139
|
* Custom response parser.
|
|
390
140
|
* Allows converting server `Response` to the domain type `Type`.
|
|
@@ -481,7 +231,7 @@ declare class ResourceStore<Data> {
|
|
|
481
231
|
* @param cfg Call settings (strategy, ttlMs, revalidate, parseResponse, delay, delayMode, dedupe, promote)
|
|
482
232
|
* @returns Deserialized `Data`
|
|
483
233
|
*/
|
|
484
|
-
get<Param extends SimpleDict = SimpleDict, Query extends
|
|
234
|
+
get<Param extends SimpleDict = SimpleDict, Query extends QueryDict = QueryDict, Response extends AnyType = Data>(args: CallArgs<Param, Query, never>, cfg?: GetCallConfig<Response, Data>): Promise<Data>;
|
|
485
235
|
/**
|
|
486
236
|
* POST request.
|
|
487
237
|
*
|
|
@@ -489,7 +239,7 @@ declare class ResourceStore<Data> {
|
|
|
489
239
|
* @param cfg Call settings (parseResponse, delay, delayMode, dedupe, promote)
|
|
490
240
|
* @returns API response (by default — as returned by the server)
|
|
491
241
|
*/
|
|
492
|
-
post<Param extends SimpleDict = SimpleDict, Payload extends PayloadData = PayloadData, Query extends
|
|
242
|
+
post<Param extends SimpleDict = SimpleDict, Payload extends PayloadData = PayloadData, Query extends QueryDict = QueryDict, Response extends AnyType = AnyType>(args: CallArgs<Param, Query, Payload>, cfg?: CallConfig<Response, Response>): Promise<Response>;
|
|
493
243
|
/**
|
|
494
244
|
* PUT request (full resource update).
|
|
495
245
|
*
|
|
@@ -497,7 +247,7 @@ declare class ResourceStore<Data> {
|
|
|
497
247
|
* @param cfg Call settings (parseResponse, delay, delayMode, dedupe, promote)
|
|
498
248
|
* @returns API response (by default — as returned by the server)
|
|
499
249
|
*/
|
|
500
|
-
put<Param extends SimpleDict = SimpleDict, Payload extends PayloadData = PayloadData, Query extends
|
|
250
|
+
put<Param extends SimpleDict = SimpleDict, Payload extends PayloadData = PayloadData, Query extends QueryDict = QueryDict, Response extends AnyType = AnyType>(args: CallArgs<Param, Query, Partial<Payload>>, cfg?: CallConfig<Response, Response>): Promise<Response>;
|
|
501
251
|
/**
|
|
502
252
|
* PATCH request (partial update).
|
|
503
253
|
*
|
|
@@ -505,7 +255,7 @@ declare class ResourceStore<Data> {
|
|
|
505
255
|
* @param cfg Call settings (parseResponse, delay, delayMode, dedupe, promote)
|
|
506
256
|
* @returns API response (by default — as returned by the server)
|
|
507
257
|
*/
|
|
508
|
-
patch<Param extends SimpleDict = SimpleDict, Payload extends PayloadData = PayloadData, Query extends
|
|
258
|
+
patch<Param extends SimpleDict = SimpleDict, Payload extends PayloadData = PayloadData, Query extends QueryDict = QueryDict, Response extends AnyType = AnyType>(args: CallArgs<Param, Query, Partial<Payload>>, cfg?: CallConfig<Response, Response>): Promise<Response>;
|
|
509
259
|
/**
|
|
510
260
|
* DELETE request.
|
|
511
261
|
*
|
|
@@ -513,7 +263,7 @@ declare class ResourceStore<Data> {
|
|
|
513
263
|
* @param cfg Call settings (parseResponse, delay, delayMode, dedupe, promote)
|
|
514
264
|
* @returns API response (by default — as returned by the server)
|
|
515
265
|
*/
|
|
516
|
-
delete<Param extends SimpleDict = SimpleDict, Payload extends PayloadData = PayloadData, Query extends
|
|
266
|
+
delete<Param extends SimpleDict = SimpleDict, Payload extends PayloadData = PayloadData, Query extends QueryDict = QueryDict, Response extends AnyType = AnyType>(args: CallArgs<Param, Query, Payload>, cfg?: CallConfig<Response, Response>): Promise<Response>;
|
|
517
267
|
/**
|
|
518
268
|
* Cancel scheduled/running requests for a specific call.
|
|
519
269
|
*
|
|
@@ -521,7 +271,7 @@ declare class ResourceStore<Data> {
|
|
|
521
271
|
* @param args Arguments used to build the URL (params, query)
|
|
522
272
|
* @param reason Cancellation reason (optional)
|
|
523
273
|
*/
|
|
524
|
-
abort<Param extends SimpleDict = SimpleDict, Query extends
|
|
274
|
+
abort<Param extends SimpleDict = SimpleDict, Query extends QueryDict = QueryDict>(method: RestMethods, args: CallArgs<Param, Query>, reason?: string | Error): void;
|
|
525
275
|
/**
|
|
526
276
|
* Cancel all scheduled/running requests for this store.
|
|
527
277
|
*
|
|
@@ -645,13 +395,16 @@ type SetRouteParamsOptions = {
|
|
|
645
395
|
abort?: boolean;
|
|
646
396
|
};
|
|
647
397
|
|
|
398
|
+
type BivariantCallback<Args, Return> = {
|
|
399
|
+
bivarianceHack(data: Args): Return;
|
|
400
|
+
}['bivarianceHack'];
|
|
648
401
|
/**
|
|
649
402
|
* Configuration for the paginated data store.
|
|
650
403
|
*
|
|
651
404
|
* Controls request method, page cache, debounce delay, concurrency policy, and
|
|
652
405
|
* request/response transformations.
|
|
653
406
|
*/
|
|
654
|
-
type PagedQueryStoreConfig<ItemsType extends object, FilterType =
|
|
407
|
+
type PagedQueryStoreConfig<ItemsType extends object, FilterType extends AnyDict = AnyDict> = {
|
|
655
408
|
/** Optional base URL prepended to the route before the request is sent. */
|
|
656
409
|
baseUrl?: string;
|
|
657
410
|
/** Transport HTTP method: `GET`/`POST`/`PATCH`/`PUT`/`DELETE`. Defaults to global config or `POST`. */
|
|
@@ -666,9 +419,9 @@ type PagedQueryStoreConfig<ItemsType extends object, FilterType = unknown> = {
|
|
|
666
419
|
debounceTime?: number;
|
|
667
420
|
/** Concurrency policy for overlapping requests. Defaults to `latest-wins`. */
|
|
668
421
|
concurrency?: PagedQueryConcurrency;
|
|
669
|
-
/** Initial pagination params. `page`
|
|
422
|
+
/** Initial pagination params. Omitted `page` defaults to `0`. */
|
|
670
423
|
presetQuery?: {
|
|
671
|
-
page
|
|
424
|
+
page?: number;
|
|
672
425
|
pageSize?: number;
|
|
673
426
|
};
|
|
674
427
|
/** Initial filters. Will be sent with the first request. */
|
|
@@ -680,7 +433,7 @@ type PagedQueryStoreConfig<ItemsType extends object, FilterType = unknown> = {
|
|
|
680
433
|
* Useful for mapping `page/pageSize` and selected filter fields to API-specific query keys.
|
|
681
434
|
* Returned object can contain nullable values; they are filtered before the transport call.
|
|
682
435
|
*/
|
|
683
|
-
parseRequest?:
|
|
436
|
+
parseRequest?: BivariantCallback<PageableRequest & Partial<FilterType> & AnyDict, AnyDict>;
|
|
684
437
|
/**
|
|
685
438
|
* Custom parser of API response into unified `PageableResponse<ItemsType>`.
|
|
686
439
|
* Use if the server returns an array or a non-standard structure.
|
|
@@ -733,7 +486,7 @@ type PagedQueryStoreProviderConfig = {
|
|
|
733
486
|
* effect(() => console.log(ds.items(), ds.loading()));
|
|
734
487
|
* ```
|
|
735
488
|
*/
|
|
736
|
-
declare class PagedQueryStore<ItemsType extends AnyDict, FilterType = AnyDict> {
|
|
489
|
+
declare class PagedQueryStore<ItemsType extends AnyDict, FilterType extends AnyDict = AnyDict> {
|
|
737
490
|
#private;
|
|
738
491
|
private route;
|
|
739
492
|
config: PagedQueryStoreConfig<ItemsType, FilterType>;
|
|
@@ -774,29 +527,10 @@ declare class PagedQueryStore<ItemsType extends AnyDict, FilterType = AnyDict> {
|
|
|
774
527
|
get totalElements(): number;
|
|
775
528
|
/** Current sort rules. */
|
|
776
529
|
get sort(): QuerySortRule[];
|
|
777
|
-
/**
|
|
778
|
-
* @deprecated Prefer `fetch(...)`, `refetchWith(...)`, or a dedicated setter method.
|
|
779
|
-
* Direct state mutation bypasses request semantics and should be treated as legacy.
|
|
780
|
-
*/
|
|
781
530
|
set filters(value: Partial<FilterType>);
|
|
782
|
-
/**
|
|
783
|
-
* @deprecated Prefer `fetch(...)`, `refetchWith(...)`, or a dedicated setter method.
|
|
784
|
-
* Direct state mutation bypasses request semantics and should be treated as legacy.
|
|
785
|
-
*/
|
|
786
531
|
set query(value: AnyDict);
|
|
787
|
-
/**
|
|
788
|
-
* @deprecated Prefer `updatePage(...)`, `fetch(...)`, or `refetchWith(...)`.
|
|
789
|
-
* Direct state mutation bypasses request semantics and should be treated as legacy.
|
|
790
|
-
*/
|
|
791
532
|
set page(value: number);
|
|
792
|
-
/**
|
|
793
|
-
* @deprecated Prefer `updatePageSize(...)`.
|
|
794
|
-
* Direct state mutation bypasses request semantics and should be treated as legacy.
|
|
795
|
-
*/
|
|
796
533
|
set pageSize(value: number);
|
|
797
|
-
/**
|
|
798
|
-
* @deprecated Managed by transport responses. Direct assignment should be treated as legacy.
|
|
799
|
-
*/
|
|
800
534
|
set totalElements(value: number);
|
|
801
535
|
/**
|
|
802
536
|
* Fetch data with explicit filters and query params from the first page.
|
|
@@ -1215,6 +949,6 @@ type StatumConfig = PagedQueryProviderConfig & SerializerProviderConfig & DictPr
|
|
|
1215
949
|
declare const STATUM_CONFIG: InjectionToken<StatumConfig>;
|
|
1216
950
|
declare const provideStatum: (config: StatumConfig) => EnvironmentProviders;
|
|
1217
951
|
|
|
1218
|
-
export { AbortError, CacheMissError, DictLocalStore, DictStore, EntityStore,
|
|
1219
|
-
export type {
|
|
952
|
+
export { AbortError, CacheMissError, DictLocalStore, DictStore, EntityStore, PagedQueryStore, RESOURCE_PROFILES, ResourceStore, STATUM_CONFIG, createBodySerializer, createQuerySerializer, createResourceProfile, createStrictSerializer, isAbort, provideStatum };
|
|
953
|
+
export type { DictLocalConfig, DictStoreConfig, DictStoreProviderConfig, EntityId, EntityStoreConfig, FetchInput, FetchParams, OffsetPaginationType, PagedQueryStoreConfig, PagedQueryStoreProviderConfig, QuerySortInput, QuerySortOrder, QuerySortRule, RefetchWithInput, ResourceProfileName, ResourceRoutesMap, ResourceStatus, ResourceStoreOptions, ResourceTraceEvent, RetryConfig, SetRouteParamsOptions, StatumConfig, UpdateByOffsetOptions, UpdatePageInput, UpdatePageOptions };
|
|
1220
954
|
//# sourceMappingURL=reforgium-statum.d.ts.map
|