@vielzeug/sourcerer 1.1.0 → 2.0.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/README.md +19 -74
- package/dist/_dev.cjs +1 -1
- package/dist/_dev.cjs.map +1 -1
- package/dist/_dev.js +2 -8
- package/dist/_dev.js.map +1 -1
- package/dist/asyncSource.cjs +1 -1
- package/dist/asyncSource.cjs.map +1 -1
- package/dist/asyncSource.d.ts +14 -58
- package/dist/asyncSource.d.ts.map +1 -1
- package/dist/asyncSource.js +28 -27
- package/dist/asyncSource.js.map +1 -1
- package/dist/cursorSource.cjs +1 -1
- package/dist/cursorSource.cjs.map +1 -1
- package/dist/cursorSource.d.ts +3 -3
- package/dist/cursorSource.d.ts.map +1 -1
- package/dist/cursorSource.js +76 -109
- package/dist/cursorSource.js.map +1 -1
- package/dist/devtools.cjs +1 -1
- package/dist/devtools.cjs.map +1 -1
- package/dist/devtools.d.ts +4 -50
- package/dist/devtools.d.ts.map +1 -1
- package/dist/devtools.js +3 -15
- package/dist/devtools.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -13
- package/dist/infiniteSource.cjs +1 -1
- package/dist/infiniteSource.cjs.map +1 -1
- package/dist/infiniteSource.d.ts +3 -3
- package/dist/infiniteSource.d.ts.map +1 -1
- package/dist/infiniteSource.js +71 -106
- package/dist/infiniteSource.js.map +1 -1
- package/dist/localSource.cjs +1 -1
- package/dist/localSource.cjs.map +1 -1
- package/dist/localSource.d.ts +2 -22
- package/dist/localSource.d.ts.map +1 -1
- package/dist/localSource.js +58 -104
- package/dist/localSource.js.map +1 -1
- package/dist/pageSource.cjs +2 -0
- package/dist/pageSource.cjs.map +1 -0
- package/dist/pageSource.d.ts +4 -0
- package/dist/pageSource.d.ts.map +1 -0
- package/dist/pageSource.js +96 -0
- package/dist/pageSource.js.map +1 -0
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.cjs.map +1 -1
- package/dist/pagination.d.ts +5 -30
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +21 -27
- package/dist/pagination.js.map +1 -1
- package/dist/requestController.cjs +2 -0
- package/dist/requestController.cjs.map +1 -0
- package/dist/requestController.d.ts +13 -0
- package/dist/requestController.d.ts.map +1 -0
- package/dist/requestController.js +29 -0
- package/dist/requestController.js.map +1 -0
- package/dist/sourceStore.cjs +2 -0
- package/dist/sourceStore.cjs.map +1 -0
- package/dist/sourceStore.d.ts +10 -0
- package/dist/sourceStore.d.ts.map +1 -0
- package/dist/sourceStore.js +38 -0
- package/dist/sourceStore.js.map +1 -0
- package/dist/sourcerer.cjs +1 -1
- package/dist/sourcerer.cjs.map +1 -1
- package/dist/sourcerer.iife.js +1 -1
- package/dist/sourcerer.iife.js.map +1 -1
- package/dist/sourcerer.js +1 -1
- package/dist/sourcerer.js.map +1 -1
- package/dist/types.d.ts +128 -355
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -9
- package/dist/_utils.cjs +0 -2
- package/dist/_utils.cjs.map +0 -1
- package/dist/_utils.d.ts +0 -28
- package/dist/_utils.d.ts.map +0 -1
- package/dist/_utils.js +0 -20
- package/dist/_utils.js.map +0 -1
- package/dist/asyncSearch.cjs +0 -2
- package/dist/asyncSearch.cjs.map +0 -1
- package/dist/asyncSearch.d.ts +0 -13
- package/dist/asyncSearch.d.ts.map +0 -1
- package/dist/asyncSearch.js +0 -28
- package/dist/asyncSearch.js.map +0 -1
- package/dist/codecs.cjs +0 -2
- package/dist/codecs.cjs.map +0 -1
- package/dist/codecs.d.ts +0 -30
- package/dist/codecs.d.ts.map +0 -1
- package/dist/codecs.js +0 -38
- package/dist/codecs.js.map +0 -1
- package/dist/core.cjs +0 -2
- package/dist/core.cjs.map +0 -1
- package/dist/core.d.ts +0 -71
- package/dist/core.d.ts.map +0 -1
- package/dist/core.js +0 -59
- package/dist/core.js.map +0 -1
- package/dist/derive.cjs +0 -2
- package/dist/derive.cjs.map +0 -1
- package/dist/derive.d.ts +0 -29
- package/dist/derive.d.ts.map +0 -1
- package/dist/derive.js +0 -38
- package/dist/derive.js.map +0 -1
- package/dist/errors.cjs +0 -2
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.ts +0 -62
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -29
- package/dist/errors.js.map +0 -1
- package/dist/fetchManager.cjs +0 -2
- package/dist/fetchManager.cjs.map +0 -1
- package/dist/fetchManager.d.ts +0 -40
- package/dist/fetchManager.d.ts.map +0 -1
- package/dist/fetchManager.js +0 -41
- package/dist/fetchManager.js.map +0 -1
- package/dist/merge.cjs +0 -2
- package/dist/merge.cjs.map +0 -1
- package/dist/merge.d.ts +0 -35
- package/dist/merge.d.ts.map +0 -1
- package/dist/merge.js +0 -41
- package/dist/merge.js.map +0 -1
- package/dist/prefetch.cjs +0 -2
- package/dist/prefetch.cjs.map +0 -1
- package/dist/prefetch.d.ts +0 -32
- package/dist/prefetch.d.ts.map +0 -1
- package/dist/prefetch.js +0 -38
- package/dist/prefetch.js.map +0 -1
- package/dist/presets.cjs +0 -2
- package/dist/presets.cjs.map +0 -1
- package/dist/presets.d.ts +0 -17
- package/dist/presets.d.ts.map +0 -1
- package/dist/presets.js +0 -43
- package/dist/presets.js.map +0 -1
- package/dist/remoteSource.cjs +0 -2
- package/dist/remoteSource.cjs.map +0 -1
- package/dist/remoteSource.d.ts +0 -4
- package/dist/remoteSource.d.ts.map +0 -1
- package/dist/remoteSource.js +0 -165
- package/dist/remoteSource.js.map +0 -1
- package/dist/state.cjs +0 -2
- package/dist/state.cjs.map +0 -1
- package/dist/state.d.ts +0 -23
- package/dist/state.d.ts.map +0 -1
- package/dist/state.js +0 -14
- package/dist/state.js.map +0 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,384 +1,157 @@
|
|
|
1
|
-
|
|
2
|
-
export type
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
attempts?: number;
|
|
18
|
-
/** Returns the delay in ms before the nth retry (1-indexed). Default: exponential backoff. */
|
|
19
|
-
delay?: (attempt: number) => number;
|
|
20
|
-
}>;
|
|
21
|
-
export type SourceQuery = Readonly<{
|
|
22
|
-
limit: number;
|
|
23
|
-
page: number;
|
|
24
|
-
/**
|
|
25
|
-
* The active search string. Absent (or empty string) when no search is active.
|
|
26
|
-
* Both representations are equivalent — treat `''` and `undefined` identically.
|
|
27
|
-
* `encodeQuery` omits this field when falsy; `decodeQuery` returns it only when present in the URL.
|
|
28
|
-
*/
|
|
29
|
-
search?: string;
|
|
1
|
+
export type Predicate<T> = (value: T, index: number, values: readonly T[]) => boolean;
|
|
2
|
+
export type Sorter<T> = (left: T, right: T) => number;
|
|
3
|
+
export type Disposable = {
|
|
4
|
+
[Symbol.dispose](): void;
|
|
5
|
+
readonly disposalSignal: AbortSignal;
|
|
6
|
+
dispose(): void;
|
|
7
|
+
readonly disposed: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type PagePagination = Readonly<{
|
|
10
|
+
count: number;
|
|
11
|
+
hasNext: boolean;
|
|
12
|
+
hasPrevious: boolean;
|
|
13
|
+
index: number;
|
|
14
|
+
kind: 'page';
|
|
15
|
+
size: number;
|
|
16
|
+
total: number;
|
|
30
17
|
}>;
|
|
31
|
-
export type
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
export type CursorPagination<TCursor = string> = Readonly<{
|
|
19
|
+
hasNext: boolean;
|
|
20
|
+
hasPrevious: boolean;
|
|
21
|
+
kind: 'cursor';
|
|
22
|
+
nextCursor?: TCursor;
|
|
23
|
+
previousCursor?: TCursor;
|
|
24
|
+
total?: number;
|
|
37
25
|
}>;
|
|
38
|
-
export type
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export type InfiniteSourceQuery = Readonly<{
|
|
45
|
-
limit: number;
|
|
46
|
-
page: number;
|
|
47
|
-
search?: string;
|
|
26
|
+
export type InfinitePagination = Readonly<{
|
|
27
|
+
hasMore: boolean;
|
|
28
|
+
isLoadingMore: boolean;
|
|
29
|
+
kind: 'infinite';
|
|
30
|
+
loaded: number;
|
|
31
|
+
total: number;
|
|
48
32
|
}>;
|
|
49
|
-
export
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
durationMs: number;
|
|
58
|
-
/** Structured error when `status` is `'error'`. */
|
|
59
|
-
error?: SourcererError;
|
|
60
|
-
/** The query object that was fetched. */
|
|
33
|
+
export type AnyPagination = CursorPagination<unknown> | InfinitePagination | PagePagination;
|
|
34
|
+
/** Loaded state remains internally consistent while pendingQuery describes newer work. */
|
|
35
|
+
export type SourceSnapshot<T, TQuery, TPagination extends AnyPagination = AnyPagination> = Readonly<{
|
|
36
|
+
data: readonly T[];
|
|
37
|
+
error: Error | null;
|
|
38
|
+
isFetching: boolean;
|
|
39
|
+
pagination: TPagination;
|
|
40
|
+
pendingQuery?: TQuery;
|
|
61
41
|
query: TQuery;
|
|
62
|
-
status: 'error' | 'success';
|
|
63
42
|
}>;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
export type
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
isLoading: boolean;
|
|
72
|
-
isSearchPending: boolean;
|
|
73
|
-
pageCount: number;
|
|
74
|
-
pageNumber: number;
|
|
43
|
+
export type Source<T, TQuery, TPagination extends AnyPagination = AnyPagination> = Disposable & {
|
|
44
|
+
readonly snapshot: SourceSnapshot<T, TQuery, TPagination>;
|
|
45
|
+
subscribe(listener: (snapshot: SourceSnapshot<T, TQuery, TPagination>) => void): () => void;
|
|
46
|
+
};
|
|
47
|
+
export type PageQuery<TFilter = unknown, TSort = unknown> = Readonly<{
|
|
48
|
+
filter?: TFilter;
|
|
49
|
+
page: number;
|
|
75
50
|
pageSize: number;
|
|
76
|
-
|
|
51
|
+
search: string;
|
|
52
|
+
sort?: TSort;
|
|
77
53
|
}>;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
* Safe to embed in HTML or pass over the network.
|
|
81
|
-
*/
|
|
82
|
-
export type SourceSnapshot<T> = Readonly<{
|
|
83
|
-
items: readonly T[];
|
|
54
|
+
export type PageQueryPatch<TFilter = unknown, TSort = unknown> = Readonly<{
|
|
55
|
+
filter?: TFilter | undefined;
|
|
84
56
|
page?: number;
|
|
57
|
+
pageSize?: number;
|
|
85
58
|
search?: string;
|
|
59
|
+
sort?: TSort | undefined;
|
|
60
|
+
}>;
|
|
61
|
+
export type PageResult<T> = Readonly<{
|
|
62
|
+
data: readonly T[];
|
|
86
63
|
total: number;
|
|
87
64
|
}>;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
readonly error: SourcererError;
|
|
102
|
-
readonly status: 'error';
|
|
103
|
-
} | {
|
|
104
|
-
readonly items: readonly T[];
|
|
105
|
-
readonly status: 'success';
|
|
106
|
-
} | {
|
|
107
|
-
readonly status: 'loading';
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Minimal observable interface shared by all source and derived source types.
|
|
111
|
-
* Framework adapters should target this interface for maximum portability.
|
|
112
|
-
*/
|
|
113
|
-
export type ReactiveSource<T, TMeta = SourceMeta> = {
|
|
114
|
-
[Symbol.dispose](): void;
|
|
115
|
-
readonly current: readonly T[];
|
|
116
|
-
readonly disposalSignal: AbortSignal;
|
|
117
|
-
dispose(): void;
|
|
118
|
-
readonly disposed: boolean;
|
|
119
|
-
readonly meta: TMeta;
|
|
120
|
-
subscribe(listener: () => void): () => void;
|
|
121
|
-
};
|
|
122
|
-
/**
|
|
123
|
-
* Read-only reactive projection derived from a parent source.
|
|
124
|
-
* Returned by `deriveSource()`.
|
|
125
|
-
*/
|
|
126
|
-
export type DerivedSource<T, TMeta = SourceMeta> = ReactiveSource<T, TMeta>;
|
|
127
|
-
/**
|
|
128
|
-
* Read-only reactive view combining multiple sources.
|
|
129
|
-
* Returned by `mergeSource()` when sources have incompatible meta shapes.
|
|
130
|
-
*/
|
|
131
|
-
export type MergedSource<T> = {
|
|
132
|
-
[Symbol.dispose](): void;
|
|
133
|
-
readonly current: readonly T[];
|
|
134
|
-
readonly disposalSignal: AbortSignal;
|
|
135
|
-
dispose(): void;
|
|
136
|
-
readonly disposed: boolean;
|
|
137
|
-
subscribe(listener: () => void): () => void;
|
|
65
|
+
export type PageLoadContext<TQuery> = Readonly<{
|
|
66
|
+
query: TQuery;
|
|
67
|
+
signal: AbortSignal;
|
|
68
|
+
}>;
|
|
69
|
+
export type PageSource<T, TFilter = unknown, TSort = unknown> = Source<T, PageQuery<TFilter, TSort>, PagePagination> & {
|
|
70
|
+
readonly page: Readonly<{
|
|
71
|
+
go(index: number): Promise<void>;
|
|
72
|
+
last(): Promise<void>;
|
|
73
|
+
next(): Promise<void>;
|
|
74
|
+
previous(): Promise<void>;
|
|
75
|
+
}>;
|
|
76
|
+
reload(): Promise<void>;
|
|
77
|
+
setQuery(changes: PageQueryPatch<TFilter, TSort>): Promise<void>;
|
|
138
78
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
79
|
+
export type PageSourceConfig<T, TFilter = unknown, TSort = unknown> = Readonly<{
|
|
80
|
+
autoStart?: boolean;
|
|
81
|
+
initialQuery?: PageQueryPatch<TFilter, TSort>;
|
|
82
|
+
load(context: PageLoadContext<PageQuery<TFilter, TSort>>): Promise<PageResult<T>>;
|
|
143
83
|
}>;
|
|
144
|
-
|
|
145
|
-
export type PageNavigator<T> = ReactiveSource<T, SourceMeta> & {
|
|
146
|
-
goTo(page: number): Promise<void>;
|
|
147
|
-
goToLast(): Promise<void>;
|
|
148
|
-
next(): Promise<void>;
|
|
149
|
-
/**
|
|
150
|
-
* Applies one or more query changes atomically — a single fetch for any combination
|
|
151
|
-
* of limit, page, and search updates.
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* ```ts
|
|
155
|
-
* // Change limit and search in one fetch
|
|
156
|
-
* await source.patch({ limit: 20, search: 'hello' });
|
|
157
|
-
* ```
|
|
158
|
-
*/
|
|
159
|
-
patch(changes: Partial<SourceQuery>): Promise<void>;
|
|
160
|
-
prev(): Promise<void>;
|
|
161
|
-
/**
|
|
162
|
-
* The current query state — limit, page, and optional search string.
|
|
163
|
-
* Use `encodeQuery(source.query)` to serialize to URL params.
|
|
164
|
-
*/
|
|
165
|
-
readonly query: SourceQuery;
|
|
166
|
-
/**
|
|
167
|
-
* Resolves when the source is idle (no pending async computation).
|
|
168
|
-
* Rejects with `SourcererTimeoutError` after `timeout` ms if still busy.
|
|
169
|
-
*/
|
|
170
|
-
ready(timeout?: number): Promise<void>;
|
|
171
|
-
reset(): Promise<void>;
|
|
172
|
-
/**
|
|
173
|
-
* Updates the search query. Debounced by default.
|
|
174
|
-
* Always returns a `Promise<void>` that resolves when the triggered fetch completes.
|
|
175
|
-
* Pass `{ immediate: true }` to skip the debounce window.
|
|
176
|
-
*/
|
|
177
|
-
search(query: string, opts?: SearchOptions): Promise<void>;
|
|
178
|
-
};
|
|
179
|
-
/** Full set of fields patchable in one atomic recompute on a local source. */
|
|
180
|
-
export type LocalSourceQuery<T> = Partial<{
|
|
181
|
-
filter: Predicate<T> | undefined;
|
|
182
|
-
limit: number;
|
|
84
|
+
export type LocalQuery = Readonly<{
|
|
183
85
|
page: number;
|
|
86
|
+
pageSize: number;
|
|
184
87
|
search: string;
|
|
185
|
-
sort: Sorter<T> | undefined;
|
|
186
88
|
}>;
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
export type LocalSource<T> =
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
* ```
|
|
202
|
-
*/
|
|
203
|
-
patch(changes: LocalSourceQuery<T>): Promise<void>;
|
|
204
|
-
setData(data: readonly T[]): Promise<void>;
|
|
205
|
-
};
|
|
206
|
-
/**
|
|
207
|
-
* Full interface for remote page-based sources.
|
|
208
|
-
* `optimisticUpdate(mutator)` throws if a concurrent update is already pending.
|
|
209
|
-
*/
|
|
210
|
-
export type RemoteSource<T, TFilter = unknown, TSort = unknown> = Omit<PageNavigator<T>, 'patch' | 'query'> & {
|
|
211
|
-
/**
|
|
212
|
-
* Applies an optimistic update immediately before a fetch settles.
|
|
213
|
-
* Returns a rollback function. The optimistic state is automatically cleared
|
|
214
|
-
* on the next successful fetch, or rolled back on failure.
|
|
215
|
-
*
|
|
216
|
-
* @throws {Error} If an optimistic update is already active.
|
|
217
|
-
*/
|
|
218
|
-
optimisticUpdate(mutator: (current: readonly T[]) => readonly T[], options?: {
|
|
219
|
-
total?: number;
|
|
220
|
-
}): () => void;
|
|
221
|
-
/**
|
|
222
|
-
* Applies one or more query changes atomically — a single fetch for any combination
|
|
223
|
-
* of limit, page, search, filter, and sort updates.
|
|
224
|
-
*/
|
|
225
|
-
patch(changes: Partial<RemoteSourceQuery<TFilter, TSort>>): Promise<void>;
|
|
226
|
-
/**
|
|
227
|
-
* The current query state. Use `encodeQuery(source.query)` to serialize to URL params.
|
|
228
|
-
*/
|
|
229
|
-
readonly query: RemoteSourceQuery<TFilter, TSort>;
|
|
230
|
-
ready(timeout?: number): Promise<void>;
|
|
231
|
-
refresh(): Promise<void>;
|
|
89
|
+
export type LocalQueryPatch = Readonly<{
|
|
90
|
+
page?: number;
|
|
91
|
+
pageSize?: number;
|
|
92
|
+
search?: string;
|
|
93
|
+
}>;
|
|
94
|
+
export type LocalSource<T> = Source<T, LocalQuery, PagePagination> & {
|
|
95
|
+
readonly page: Readonly<{
|
|
96
|
+
go(index: number): boolean;
|
|
97
|
+
last(): boolean;
|
|
98
|
+
next(): boolean;
|
|
99
|
+
previous(): boolean;
|
|
100
|
+
}>;
|
|
101
|
+
setData(data: readonly T[]): boolean;
|
|
102
|
+
setQuery(changes: LocalQueryPatch): boolean;
|
|
232
103
|
};
|
|
233
104
|
export type LocalSourceConfig<T> = Readonly<{
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Async filter applied after the sync `filter`, enabling Web Worker offloading
|
|
238
|
-
* via `@vielzeug/familiar`. Sets `meta.isLoading` to `true` during computation.
|
|
239
|
-
* The signal is aborted when a new computation supersedes this one.
|
|
240
|
-
*/
|
|
241
|
-
filterAsync?: (items: readonly T[], signal: AbortSignal) => Promise<readonly T[]>;
|
|
242
|
-
/** Initial data to populate the source. When provided, pass `[]` as the first arg. */
|
|
243
|
-
initialData?: readonly T[];
|
|
244
|
-
limit?: number;
|
|
245
|
-
/**
|
|
246
|
-
* Custom search function. Default: case-insensitive JSON substring match.
|
|
247
|
-
* Provide a domain-specific function for better relevance on large datasets.
|
|
248
|
-
*/
|
|
249
|
-
searchFn?: (items: readonly T[], query: string) => readonly T[];
|
|
250
|
-
sort?: Sorter<T>;
|
|
251
|
-
/**
|
|
252
|
-
* Async sort applied after the sync `sort`. Sets `meta.isLoading` to `true`
|
|
253
|
-
* during computation, enabling Web Worker offloading.
|
|
254
|
-
*/
|
|
255
|
-
sortAsync?: (items: readonly T[], signal: AbortSignal) => Promise<readonly T[]>;
|
|
256
|
-
}>;
|
|
257
|
-
export type RemoteConfig<T, TFilter = unknown, TSort = unknown> = Readonly<{
|
|
258
|
-
/** Automatically fetch on construction. Default: `true`. */
|
|
259
|
-
autoFetch?: boolean;
|
|
260
|
-
/** Debounce delay in ms for `search()` calls. Default: `300`. */
|
|
261
|
-
debounceMs?: number;
|
|
262
|
-
fetch: (q: RemoteSourceQuery<TFilter, TSort>, signal: AbortSignal) => Promise<Readonly<{
|
|
263
|
-
items: readonly T[];
|
|
264
|
-
total: number;
|
|
265
|
-
}>>;
|
|
266
|
-
filter?: TFilter;
|
|
267
|
-
limit?: number;
|
|
268
|
-
/**
|
|
269
|
-
* Called after each fetch attempt settles (success or failure).
|
|
270
|
-
* Useful for logging, telemetry, and debugging.
|
|
271
|
-
*/
|
|
272
|
-
onFetch?: (event: FetchEvent<RemoteSourceQuery<TFilter, TSort>>) => void;
|
|
273
|
-
queryKey?: (q: RemoteSourceQuery<TFilter, TSort>) => string;
|
|
274
|
-
/**
|
|
275
|
-
* Automatically re-fetch at this interval in ms. The timer is cancelled on `dispose()`.
|
|
276
|
-
* Useful for live dashboards and real-time data displays.
|
|
277
|
-
*/
|
|
278
|
-
refreshInterval?: number;
|
|
279
|
-
retry?: RetryConfig;
|
|
280
|
-
/**
|
|
281
|
-
* Pre-populate the source with server-fetched data (SSR / prefetch).
|
|
282
|
-
* The source starts in a loaded state — no initial loading flash.
|
|
283
|
-
* Set `autoFetch: false` to suppress the background re-fetch when the snapshot is fresh.
|
|
284
|
-
*/
|
|
285
|
-
snapshot?: SourceSnapshot<T>;
|
|
286
|
-
sort?: TSort;
|
|
287
|
-
/**
|
|
288
|
-
* Skip re-fetching if the last successful fetch was within this many ms.
|
|
289
|
-
* Returns cached data immediately. Combine with `refreshInterval` for
|
|
290
|
-
* stale-while-revalidate behaviour.
|
|
291
|
-
* Default: `0` (always re-fetch).
|
|
292
|
-
*/
|
|
293
|
-
staleTime?: number;
|
|
105
|
+
initialQuery?: LocalQueryPatch;
|
|
106
|
+
match?: (item: T, search: string) => boolean;
|
|
294
107
|
}>;
|
|
295
|
-
export type
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
hasPrevPage: boolean;
|
|
299
|
-
isLoading: boolean;
|
|
300
|
-
isSearchPending: boolean;
|
|
108
|
+
export type CursorQuery<TCursor = string> = Readonly<{
|
|
109
|
+
after?: TCursor;
|
|
110
|
+
before?: TCursor;
|
|
301
111
|
pageSize: number;
|
|
302
|
-
|
|
112
|
+
search: string;
|
|
303
113
|
}>;
|
|
304
|
-
export type
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
114
|
+
export type CursorQueryPatch<TCursor = string> = Readonly<{
|
|
115
|
+
after?: TCursor | undefined;
|
|
116
|
+
before?: TCursor | undefined;
|
|
117
|
+
pageSize?: number;
|
|
118
|
+
search?: string;
|
|
119
|
+
}>;
|
|
120
|
+
export type CursorResult<T, TCursor = string> = Readonly<{
|
|
121
|
+
data: readonly T[];
|
|
122
|
+
nextCursor?: TCursor;
|
|
123
|
+
previousCursor?: TCursor;
|
|
124
|
+
total?: number;
|
|
125
|
+
}>;
|
|
126
|
+
export type CursorSource<T, TCursor = string> = Source<T, CursorQuery<TCursor>, CursorPagination<TCursor>> & {
|
|
127
|
+
readonly page: Readonly<{
|
|
128
|
+
next(): Promise<void>;
|
|
129
|
+
previous(): Promise<void>;
|
|
130
|
+
}>;
|
|
131
|
+
reload(): Promise<void>;
|
|
132
|
+
setQuery(changes: CursorQueryPatch<TCursor>): Promise<void>;
|
|
319
133
|
};
|
|
320
|
-
export type
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
items: readonly T[];
|
|
325
|
-
nextCursor?: TCursor;
|
|
326
|
-
prevCursor?: TCursor;
|
|
327
|
-
total?: number;
|
|
328
|
-
}>>;
|
|
329
|
-
limit?: number;
|
|
330
|
-
/** Called after each fetch attempt settles. Useful for logging and telemetry. */
|
|
331
|
-
onFetch?: (event: FetchEvent<CursorSourceQuery<TCursor>>) => void;
|
|
332
|
-
queryKey?: (q: CursorSourceQuery<TCursor>) => string;
|
|
333
|
-
/** Automatically re-fetch at this interval in ms. Cancelled on `dispose()`. */
|
|
334
|
-
refreshInterval?: number;
|
|
335
|
-
retry?: RetryConfig;
|
|
134
|
+
export type CursorSourceConfig<T, TCursor = string> = Readonly<{
|
|
135
|
+
autoStart?: boolean;
|
|
136
|
+
initialQuery?: CursorQueryPatch<TCursor>;
|
|
137
|
+
load(context: PageLoadContext<CursorQuery<TCursor>>): Promise<CursorResult<T, TCursor>>;
|
|
336
138
|
}>;
|
|
337
|
-
export type
|
|
338
|
-
error: SourcererError | null;
|
|
339
|
-
hasMore: boolean;
|
|
340
|
-
isLoading: boolean;
|
|
341
|
-
/** `true` only during `loadMore()` fetches — distinct from the initial load. */
|
|
342
|
-
isLoadingMore: boolean;
|
|
343
|
-
isSearchPending: boolean;
|
|
344
|
-
/** Number of pages appended so far. Resets to 0 on `reset()` or `search()`. */
|
|
345
|
-
loadedPages: number;
|
|
139
|
+
export type InfiniteQuery = Readonly<{
|
|
346
140
|
pageSize: number;
|
|
347
|
-
|
|
141
|
+
search: string;
|
|
142
|
+
}>;
|
|
143
|
+
export type InfiniteQueryPatch = Readonly<{
|
|
144
|
+
pageSize?: number;
|
|
145
|
+
search?: string;
|
|
348
146
|
}>;
|
|
349
|
-
export type InfiniteSource<T> =
|
|
350
|
-
/** Appends the next page of results to `current`. No-op when `meta.hasMore` is false. */
|
|
147
|
+
export type InfiniteSource<T> = Source<T, InfiniteQuery, InfinitePagination> & {
|
|
351
148
|
loadMore(): Promise<void>;
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
* of limit and search updates. Resets accumulated pages. No `page` field — infinite
|
|
355
|
-
* scroll has no page-number concept to patch; use `loadMore()` to append pages.
|
|
356
|
-
*/
|
|
357
|
-
patch(changes: Partial<Pick<InfiniteSourceQuery, 'limit' | 'search'>>): Promise<void>;
|
|
358
|
-
/** The current query state. Use `encodeQuery(source.query)` to serialize to URL params. */
|
|
359
|
-
readonly query: InfiniteSourceQuery;
|
|
360
|
-
/**
|
|
361
|
-
* Resolves when no fetch is in progress (including `loadMore` fetches).
|
|
362
|
-
* Rejects after `timeout` ms if still loading.
|
|
363
|
-
*/
|
|
364
|
-
ready(timeout?: number): Promise<void>;
|
|
365
|
-
reset(): Promise<void>;
|
|
366
|
-
search(query: string, opts?: SearchOptions): Promise<void>;
|
|
149
|
+
reload(): Promise<void>;
|
|
150
|
+
setQuery(changes: InfiniteQueryPatch): Promise<void>;
|
|
367
151
|
};
|
|
368
|
-
export type
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
items: readonly T[];
|
|
373
|
-
total: number;
|
|
374
|
-
}>>;
|
|
375
|
-
limit?: number;
|
|
376
|
-
/** Called after each fetch attempt settles. Useful for logging and telemetry. */
|
|
377
|
-
onFetch?: (event: FetchEvent<InfiniteSourceQuery>) => void;
|
|
378
|
-
/** Custom cache key function. Used to deduplicate in-flight requests. Default: stable JSON stringify. */
|
|
379
|
-
queryKey?: (q: InfiniteSourceQuery) => string;
|
|
380
|
-
/** Automatically re-fetch (reset to page 1) at this interval in ms. Cancelled on `dispose()`. */
|
|
381
|
-
refreshInterval?: number;
|
|
382
|
-
retry?: RetryConfig;
|
|
152
|
+
export type InfiniteSourceConfig<T> = Readonly<{
|
|
153
|
+
autoStart?: boolean;
|
|
154
|
+
initialQuery?: InfiniteQueryPatch;
|
|
155
|
+
load(context: PageLoadContext<PageQuery>): Promise<PageResult<T>>;
|
|
383
156
|
}>;
|
|
384
157
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,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eAAe,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;CACzF,CAAC,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC,CAAC;AAEH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,aAAa,EAAE,kBAAkB,CAAC,GAAG;IAC7E,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,QAAQ,CAAC;IAC7C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;CACnE,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vielzeug/sourcerer",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Framework-agnostic reactive collection sources with local, page, cursor, and infinite pagination",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -11,13 +11,11 @@
|
|
|
11
11
|
"types": "dist/index.d.ts",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
-
"source": "./src/index.ts",
|
|
15
14
|
"types": "./dist/index.d.ts",
|
|
16
15
|
"import": "./dist/index.js",
|
|
17
16
|
"require": "./dist/index.cjs"
|
|
18
17
|
},
|
|
19
18
|
"./devtools": {
|
|
20
|
-
"source": "./src/devtools.ts",
|
|
21
19
|
"types": "./dist/devtools.d.ts",
|
|
22
20
|
"import": "./dist/devtools.js",
|
|
23
21
|
"require": "./dist/devtools.cjs"
|
|
@@ -40,13 +38,17 @@
|
|
|
40
38
|
"engines": {
|
|
41
39
|
"node": ">=22"
|
|
42
40
|
},
|
|
43
|
-
"dependencies": {
|
|
44
|
-
"@vielzeug/arsenal": "1.1.2"
|
|
45
|
-
},
|
|
46
41
|
"devDependencies": {
|
|
47
|
-
"@types/node": "^26.1.
|
|
42
|
+
"@types/node": "^26.1.2",
|
|
48
43
|
"typescript": "^6.0.3",
|
|
49
|
-
"vite": "^8.
|
|
44
|
+
"vite": "^8.2.0",
|
|
50
45
|
"vitest": "^4.1.10"
|
|
46
|
+
},
|
|
47
|
+
"typesVersions": {
|
|
48
|
+
"*": {
|
|
49
|
+
"devtools": [
|
|
50
|
+
"dist/devtools.d.ts"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
51
53
|
}
|
|
52
54
|
}
|
package/dist/_utils.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("./_dev.cjs");let t=require("@vielzeug/arsenal");var n=t.hash,r=e=>e instanceof Error?e.message:typeof e==`string`&&e.length>0?e:`Request failed`,i=e=>(0,t.backoff)(e);function a(e,t=200){return e.replace(/\p{C}/gu,`?`).slice(0,t)}var o=new Set;function s(t,n,r){let i=Number.isFinite(t)?Math.max(1,Math.trunc(t)):1;if(!Number.isFinite(t)||t<1){let a=`${n}:${r}`;o.has(a)||(o.add(a),e.devOnly(()=>e.warn(`${n}: ${r} ${t} is invalid — clamped to ${i}. Must be a positive integer.`)))}return i}exports.clampPositiveInt=s,exports.defaultKeyOf=n,exports.defaultRetryDelay=i,exports.extractError=r,exports.sanitizeForLog=a;
|
|
2
|
-
//# sourceMappingURL=_utils.cjs.map
|
package/dist/_utils.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_utils.cjs","names":[],"sources":["../src/_utils.ts"],"sourcesContent":["import { backoff, hash, retry } from '@vielzeug/arsenal';\n\nimport { devOnly, warn } from './_dev';\n\nexport { retry };\n\n// Internal stable-key helper — used by source factories, not exposed as public API.\nexport const defaultKeyOf = hash;\n\n/** Extracts a user-facing error message from a caught exception. */\nexport const extractError = (reason: unknown): string => {\n if (reason instanceof Error) return reason.message;\n\n if (typeof reason === 'string' && reason.length > 0) return reason;\n\n return 'Request failed';\n};\n\n/** Default exponential backoff: 1 s, 2 s, 4 s, … capped at 30 s. Receives a 0-indexed failure count. */\nexport const defaultRetryDelay = (attempt: number): number => backoff(attempt);\n\n/**\n * Strips control characters (which could otherwise inject terminal escape sequences into\n * `console.warn`/`console.debug` output) and caps length before interpolating caller- or\n * user-controlled text into a dev warning. Same approach as `@vielzeug/forge`'s\n * `sanitizeForLog` — duplicated rather than shared, per this repo's zero-cross-package-utility\n * convention for internal-only helpers.\n */\nexport function sanitizeForLog(text: string, maxLength = 200): string {\n return text.replace(/\\p{C}/gu, '?').slice(0, maxLength);\n}\n\nconst warnedClamps = new Set<string>();\n\n/**\n * Coerces a user-supplied `limit`/`page`/target value to a positive integer, warning once per\n * `(apiLabel, fieldName)` call site in dev when the raw input needed clamping (negative, zero,\n * or non-finite) — every source factory previously did `Math.max(1, Math.trunc(value))`\n * silently, so a typo'd or miscalculated config value (e.g. `limit: -1`) produced no signal at\n * all. The once-per-call-site de-dup matters here specifically because `limit`/`page` reach this\n * function via `patch()`, which realistically sits behind live UI (a numeric input, a stepper) —\n * without it, a single persistently-invalid bound value would re-warn on every keystroke.\n * Fractional inputs (e.g. `2.5`) are truncated without a warning — that's a harmless\n * normalization, not a likely mistake.\n */\nexport function clampPositiveInt(value: number, apiLabel: string, fieldName: string): number {\n const clamped = Number.isFinite(value) ? Math.max(1, Math.trunc(value)) : 1;\n\n if (!Number.isFinite(value) || value < 1) {\n const key = `${apiLabel}:${fieldName}`;\n\n if (!warnedClamps.has(key)) {\n warnedClamps.add(key);\n devOnly(() =>\n warn(`${apiLabel}: ${fieldName} ${value} is invalid — clamped to ${clamped}. Must be a positive integer.`),\n );\n }\n }\n\n return clamped;\n}\n"],"mappings":"iEAOA,IAAa,EAAe,EAAA,KAGf,EAAgB,GACvB,aAAkB,MAAc,EAAO,QAEvC,OAAO,GAAW,UAAY,EAAO,OAAS,EAAU,EAErD,iBAII,EAAqB,IAAA,EAAA,EAAA,QAAA,CAAoC,CAAO,EAS7E,SAAgB,EAAe,EAAc,EAAY,IAAa,CACpE,OAAO,EAAK,QAAQ,UAAW,GAAG,CAAC,CAAC,MAAM,EAAG,CAAS,CACxD,CAEA,IAAM,EAAe,IAAI,IAazB,SAAgB,EAAiB,EAAe,EAAkB,EAA2B,CAC3F,IAAM,EAAU,OAAO,SAAS,CAAK,EAAI,KAAK,IAAI,EAAG,KAAK,MAAM,CAAK,CAAC,EAAI,EAE1E,GAAI,CAAC,OAAO,SAAS,CAAK,GAAK,EAAQ,EAAG,CACxC,IAAM,EAAM,GAAG,EAAS,GAAG,IAEtB,EAAa,IAAI,CAAG,IACvB,EAAa,IAAI,CAAG,EACpB,EAAA,YACE,EAAA,KAAK,GAAG,EAAS,IAAI,EAAU,GAAG,EAAM,2BAA2B,EAAQ,8BAA8B,CAC3G,EAEJ,CAEA,OAAO,CACT"}
|