@vielzeug/sourcerer 26.11.5 → 26.11.6
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/dist/asyncSource.js +1 -2
- package/dist/cursorSource.cjs +1 -1
- package/dist/cursorSource.cjs.map +1 -1
- package/dist/cursorSource.js +6 -7
- package/dist/errors.js +1 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/infiniteSource.cjs +1 -1
- package/dist/infiniteSource.cjs.map +1 -1
- package/dist/infiniteSource.js +6 -7
- package/dist/infiniteSource.js.map +1 -1
- package/dist/localSource.cjs +1 -1
- package/dist/localSource.cjs.map +1 -1
- package/dist/localSource.js +11 -12
- package/dist/localSource.js.map +1 -1
- package/dist/pageSource.cjs +1 -1
- package/dist/pageSource.cjs.map +1 -1
- package/dist/pageSource.js +7 -8
- package/dist/pageSource.js.map +1 -1
- package/dist/pagination.js +1 -2
- package/dist/requestController.js +1 -2
- package/dist/resourceSource.cjs +1 -1
- package/dist/resourceSource.cjs.map +1 -1
- package/dist/resourceSource.js +5 -6
- package/dist/sourceStore.js +1 -2
- 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 +14 -24
- package/dist/sourcerer.js.map +1 -1
- package/package.json +8 -8
package/dist/sourcerer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { abortError as e, isEqual as t } from "@vielzeug/arsenal";
|
|
2
|
-
|
|
2
|
+
// src/errors.ts
|
|
3
3
|
var SourcererError = class extends Error {
|
|
4
4
|
constructor(e, t) {
|
|
5
5
|
super(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);
|
|
@@ -9,8 +9,7 @@ var SourcererError = class extends Error {
|
|
|
9
9
|
super(e);
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
//#region src/requestController.ts
|
|
12
|
+
// src/requestController.ts
|
|
14
13
|
function createRequestController() {
|
|
15
14
|
let e, t = 0;
|
|
16
15
|
return {
|
|
@@ -37,8 +36,7 @@ function toError(e) {
|
|
|
37
36
|
let t = typeof e == "string" && e.length > 0 ? e : "Source request failed";
|
|
38
37
|
return Error(t, { cause: e });
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
//#region src/sourceStore.ts
|
|
39
|
+
// src/sourceStore.ts
|
|
42
40
|
function createSourceStore(e) {
|
|
43
41
|
let t = new AbortController(), n = /* @__PURE__ */ new Set(), r = !1, i = e, dispose = () => {
|
|
44
42
|
r || (r = !0, n.clear(), t.abort());
|
|
@@ -72,8 +70,7 @@ function createSourceStore(e) {
|
|
|
72
70
|
}
|
|
73
71
|
};
|
|
74
72
|
}
|
|
75
|
-
|
|
76
|
-
//#region src/asyncSource.ts
|
|
73
|
+
// src/asyncSource.ts
|
|
77
74
|
var loadWithSignal = (t, n) => new Promise((r, i) => {
|
|
78
75
|
let abort = () => i(e(n, "The operation was aborted."));
|
|
79
76
|
if (n.aborted) {
|
|
@@ -129,8 +126,7 @@ function createAsyncSource(e) {
|
|
|
129
126
|
subscribe: t.subscribe
|
|
130
127
|
};
|
|
131
128
|
}
|
|
132
|
-
|
|
133
|
-
//#region src/pagination.ts
|
|
129
|
+
// src/pagination.ts
|
|
134
130
|
function positiveInteger(e, t) {
|
|
135
131
|
if (!Number.isInteger(e) || e < 1) throw new SourcererConfigurationError(`${t} must be a positive integer`);
|
|
136
132
|
return e;
|
|
@@ -150,8 +146,7 @@ function createPagePagination(e, t, n) {
|
|
|
150
146
|
totalItems: n
|
|
151
147
|
};
|
|
152
148
|
}
|
|
153
|
-
|
|
154
|
-
//#region src/cursorSource.ts
|
|
149
|
+
// src/cursorSource.ts
|
|
155
150
|
var createPagination$1 = (e, t) => ({
|
|
156
151
|
...t?.nextCursor !== void 0 && { nextCursor: t.nextCursor },
|
|
157
152
|
pageSize: e,
|
|
@@ -253,8 +248,7 @@ function createCursorSource(e) {
|
|
|
253
248
|
};
|
|
254
249
|
return r;
|
|
255
250
|
}
|
|
256
|
-
|
|
257
|
-
//#region src/infiniteSource.ts
|
|
251
|
+
// src/infiniteSource.ts
|
|
258
252
|
var createPagination = (e, t, n) => ({
|
|
259
253
|
hasMore: e < n,
|
|
260
254
|
loadedItems: e,
|
|
@@ -317,7 +311,7 @@ function createInfiniteSource(e) {
|
|
|
317
311
|
return i.disposed;
|
|
318
312
|
},
|
|
319
313
|
async loadMore() {
|
|
320
|
-
assertLive(),
|
|
314
|
+
assertLive(), i.state.loading || (!r || !Object.is(t.params, i.state.params) ? await reload() : i.state.pagination.hasMore && await fetch(t, n, !0));
|
|
321
315
|
},
|
|
322
316
|
reload,
|
|
323
317
|
async setPageSize(e) {
|
|
@@ -347,8 +341,7 @@ function createInfiniteSource(e) {
|
|
|
347
341
|
};
|
|
348
342
|
return a;
|
|
349
343
|
}
|
|
350
|
-
|
|
351
|
-
//#region src/localSource.ts
|
|
344
|
+
// src/localSource.ts
|
|
352
345
|
function createLocalSource(e, t = {}) {
|
|
353
346
|
let n = e, r = 1, i = positiveInteger(t.pageSize ?? 20, "pageSize"), a = t.params, buildState = () => {
|
|
354
347
|
let e = t.filter ? n.filter((e) => t.filter?.(e, a)) : n, o = createPagePagination(r, i, e.length);
|
|
@@ -400,7 +393,7 @@ function createLocalSource(e, t = {}) {
|
|
|
400
393
|
t !== i && (r = 1, i = t, commit());
|
|
401
394
|
},
|
|
402
395
|
setParams(e) {
|
|
403
|
-
assertLive(),
|
|
396
|
+
assertLive(), Object.is(e, a) || (r = 1, a = e, commit());
|
|
404
397
|
},
|
|
405
398
|
get state() {
|
|
406
399
|
return o.value;
|
|
@@ -412,8 +405,7 @@ function createLocalSource(e, t = {}) {
|
|
|
412
405
|
};
|
|
413
406
|
return s;
|
|
414
407
|
}
|
|
415
|
-
|
|
416
|
-
//#region src/pageSource.ts
|
|
408
|
+
// src/pageSource.ts
|
|
417
409
|
function createPageSource(e) {
|
|
418
410
|
let n = {
|
|
419
411
|
page: 1,
|
|
@@ -457,7 +449,7 @@ function createPageSource(e) {
|
|
|
457
449
|
}), normalizePage = (e) => r ? Math.min(positiveInteger(e, "page"), i.state.pagination.pageCount) : positiveInteger(e, "page"), goTo = async (e) => {
|
|
458
450
|
assertLive();
|
|
459
451
|
let t = normalizePage(e);
|
|
460
|
-
t === n.page ?
|
|
452
|
+
t === n.page ? i.state.loading || r && isCommitted(n) || await fetch(n) : (n = {
|
|
461
453
|
...n,
|
|
462
454
|
page: t
|
|
463
455
|
}, await fetch(n));
|
|
@@ -465,7 +457,7 @@ function createPageSource(e) {
|
|
|
465
457
|
async apply(e) {
|
|
466
458
|
assertLive();
|
|
467
459
|
let a = e.params === void 0 ? n.params : e.params;
|
|
468
|
-
t(a, n.params) ? e.page === void 0 ?
|
|
460
|
+
t(a, n.params) ? e.page === void 0 ? i.state.loading || r && isCommitted(n) || await fetch(n) : await goTo(e.page) : (n = {
|
|
469
461
|
...n,
|
|
470
462
|
page: e.page === void 0 ? 1 : positiveInteger(e.page, "page"),
|
|
471
463
|
params: a
|
|
@@ -520,8 +512,7 @@ function createPageSource(e) {
|
|
|
520
512
|
};
|
|
521
513
|
return a;
|
|
522
514
|
}
|
|
523
|
-
|
|
524
|
-
//#region src/resourceSource.ts
|
|
515
|
+
// src/resourceSource.ts
|
|
525
516
|
var initialResourceState = (e) => ({
|
|
526
517
|
data: void 0,
|
|
527
518
|
error: null,
|
|
@@ -566,7 +557,6 @@ function createResource(e) {
|
|
|
566
557
|
};
|
|
567
558
|
return t && fetchResource().catch(() => void 0), r;
|
|
568
559
|
}
|
|
569
|
-
//#endregion
|
|
570
560
|
export { SourcererConfigurationError, SourcererDisposedError, SourcererError, createCursorSource, createInfiniteSource, createLocalSource, createPageSource, createResource };
|
|
571
561
|
|
|
572
562
|
//# sourceMappingURL=sourcerer.js.map
|
package/dist/sourcerer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sourcerer.js","names":["createPagination","message","opts","active","sequence","controller","requestSequence","reason","listeners","disposed","value","initialValue","nextValue","listener","error","reject","abortError","signal","result","load","resolve","store","initial","requests","request","previous","options","state","name","pageCount","total","pageSize","page","config","requested","asyncSource","source","cursor","normalized","params","loadedItems","nextPage","hasLoaded","append","items","allItems","filtered","item","pagination","start","left","key","right","next","current","sameItems","index","nextItems","nextPageSize","nextParams","update","isEqual"],"sources":["../src/errors.ts","../src/requestController.ts","../src/sourceStore.ts","../src/asyncSource.ts","../src/pagination.ts","../src/cursorSource.ts","../src/infiniteSource.ts","../src/localSource.ts","../src/pageSource.ts","../src/resourceSource.ts"],"sourcesContent":["/** Base class for all sourcerer errors. Use `instanceof SourcererError` to catch any sourcerer-originated error. */\nexport class SourcererError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a source is configured or queried with invalid arguments. */\nexport class SourcererConfigurationError extends SourcererError {}\n\nexport class SourcererDisposedError extends SourcererError {\n constructor(message = 'Sourcerer source disposed') {\n super(message);\n }\n}\n","export type RequestHandle = Readonly<{\n finish(): void;\n isCurrent(): boolean;\n signal: AbortSignal;\n}>;\n\nexport type RequestController = Readonly<{\n begin(): RequestHandle;\n dispose(): void;\n}>;\n\n/** A source owns one active request: newer query state always supersedes older work. */\nexport function createRequestController(): RequestController {\n let active: AbortController | undefined;\n let sequence = 0;\n\n return {\n begin() {\n active?.abort();\n\n const controller = new AbortController();\n const requestSequence = ++sequence;\n\n active = controller;\n\n return {\n finish() {\n if (requestSequence === sequence) active = undefined;\n },\n\n isCurrent() {\n return requestSequence === sequence;\n },\n\n signal: controller.signal,\n };\n },\n\n dispose() {\n active?.abort();\n active = undefined;\n sequence++;\n },\n };\n}\n\nexport function toError(reason: unknown): Error {\n if (reason instanceof Error) return reason;\n\n const message = typeof reason === 'string' && reason.length > 0 ? reason : 'Source request failed';\n\n return new Error(message, { cause: reason });\n}\n","type SourceStore<T> = {\n [Symbol.dispose](): void;\n readonly disposalSignal: AbortSignal;\n dispose(): void;\n readonly disposed: boolean;\n set(value: T): void;\n subscribe(listener: (value: T) => void): () => void;\n readonly value: T;\n};\n\n/** Store commits source state before notifying; observer failures cannot rewrite committed state. */\nexport function createSourceStore<T>(initialValue: T): SourceStore<T> {\n const controller = new AbortController();\n const listeners = new Set<(value: T) => void>();\n let disposed = false;\n let value = initialValue;\n\n const dispose = (): void => {\n if (disposed) return;\n\n disposed = true;\n listeners.clear();\n controller.abort();\n };\n\n return {\n get disposalSignal() {\n return controller.signal;\n },\n\n dispose,\n\n get disposed() {\n return disposed;\n },\n\n set(nextValue) {\n if (disposed) return;\n\n value = nextValue;\n\n for (const listener of listeners) {\n try {\n listener(value);\n } catch (error) {\n queueMicrotask(() => {\n throw error;\n });\n }\n }\n },\n\n subscribe(listener) {\n if (disposed) return () => {};\n\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n },\n\n [Symbol.dispose]: dispose,\n\n get value() {\n return value;\n },\n };\n}\n","import { abortError } from '@vielzeug/arsenal';\n\nimport { SourcererDisposedError } from './errors';\nimport { createRequestController, toError } from './requestController';\nimport { createSourceStore } from './sourceStore';\n\nconst loadWithSignal = <T>(load: (signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T> =>\n new Promise((resolve, reject) => {\n const abort = (): void => reject(abortError(signal, 'The operation was aborted.'));\n if (signal.aborted) {\n abort();\n return;\n }\n\n signal.addEventListener('abort', abort, { once: true });\n let result: Promise<T>;\n try {\n result = load(signal);\n } catch (error) {\n signal.removeEventListener('abort', abort);\n reject(error);\n return;\n }\n\n result.then(\n (value) => {\n signal.removeEventListener('abort', abort);\n resolve(value);\n },\n (error: unknown) => {\n signal.removeEventListener('abort', abort);\n reject(error);\n },\n );\n });\n\ntype FetchOptions<TState, TResult> = {\n load(signal: AbortSignal): Promise<TResult>;\n success(result: TResult): TState;\n commit?(state: TState, result: TResult): void;\n pending(previous: TState): TState;\n failure(previous: TState, error: Error): TState;\n};\n\ntype AsyncSource<TState> = Readonly<{\n readonly disposalSignal: AbortSignal;\n dispose(): void;\n readonly disposed: boolean;\n fetch<TResult>(options: FetchOptions<TState, TResult>): Promise<void>;\n readonly state: TState;\n subscribe(listener: (state: TState) => void): () => void;\n}>;\n\n/** Only the current request may commit; superseded work settles without changing source state. */\nexport function createAsyncSource<TState>(initial: TState): AsyncSource<TState> {\n const store = createSourceStore(initial);\n const requests = createRequestController();\n\n return {\n get disposalSignal() {\n return store.disposalSignal;\n },\n\n dispose() {\n requests.dispose();\n store.dispose();\n },\n\n get disposed() {\n return store.disposed;\n },\n\n async fetch(options) {\n if (store.disposed) throw new SourcererDisposedError();\n\n const request = requests.begin();\n const previous = store.value;\n store.set(options.pending(previous));\n\n try {\n const result = await loadWithSignal(options.load, request.signal);\n if (!request.isCurrent() || store.disposed) return;\n\n const state = options.success(result);\n options.commit?.(state, result);\n store.set(state);\n } catch (reason: unknown) {\n if (!request.isCurrent() || store.disposed) return;\n\n const error = toError(reason);\n store.set(options.failure(previous, error));\n throw error;\n } finally {\n request.finish();\n }\n },\n\n get state() {\n return store.value;\n },\n\n subscribe: store.subscribe,\n };\n}\n","import { SourcererConfigurationError } from './errors';\nimport type { PagePagination } from './types';\n\nexport function positiveInteger(value: number, name: string): number {\n if (!Number.isInteger(value) || value < 1)\n throw new SourcererConfigurationError(`${name} must be a positive integer`);\n\n return value;\n}\n\nexport function totalItems(value: number): number {\n if (!Number.isInteger(value) || value < 0)\n throw new SourcererConfigurationError('totalItems must be a non-negative integer');\n\n return value;\n}\n\nexport function createPagePagination(page: number, pageSize: number, total: number): PagePagination {\n const pageCount = Math.max(1, Math.ceil(total / pageSize));\n\n return {\n hasNext: page < pageCount,\n hasPrevious: page > 1,\n page,\n pageCount,\n pageSize,\n totalItems: total,\n };\n}\n","import { createAsyncSource } from './asyncSource';\nimport { SourcererConfigurationError, SourcererDisposedError } from './errors';\nimport { positiveInteger, totalItems } from './pagination';\nimport type { CursorPagination, CursorResult, CursorSource, CursorSourceConfig, CursorSourceState } from './types';\n\ntype Request<TParams, TCursor> = Readonly<{\n after?: TCursor;\n before?: TCursor;\n pageSize: number;\n params: TParams;\n}>;\n\nconst createPagination = <TCursor>(\n pageSize: number,\n result?: CursorResult<unknown, TCursor>,\n): CursorPagination<TCursor> => ({\n ...(result?.nextCursor !== undefined && { nextCursor: result.nextCursor }),\n pageSize,\n ...(result?.previousCursor !== undefined && { previousCursor: result.previousCursor }),\n ...(result?.totalItems !== undefined && { totalItems: totalItems(result.totalItems) }),\n});\n\n/** Cursor sources retain committed items and cursors while replacement work is pending. */\nexport function createCursorSource<T, TParams = undefined, TCursor = string>(\n config: CursorSourceConfig<T, TParams, TCursor>,\n): CursorSource<T, TParams, TCursor> {\n if (config.after !== undefined && config.before !== undefined) {\n throw new SourcererConfigurationError('Cursor source cannot start with both after and before');\n }\n\n let requested: Request<TParams, TCursor> = {\n ...(config.after !== undefined && { after: config.after }),\n ...(config.before !== undefined && { before: config.before }),\n pageSize: positiveInteger(config.pageSize ?? 20, 'pageSize'),\n params: config.params as TParams,\n };\n const asyncSource = createAsyncSource<CursorSourceState<T, TParams, TCursor>>({\n error: null,\n items: [],\n loading: false,\n pagination: createPagination(requested.pageSize),\n params: requested.params,\n });\n const assertLive = (): void => {\n if (asyncSource.disposed) throw new SourcererDisposedError();\n };\n\n const fetch = (request: Request<TParams, TCursor>): Promise<void> =>\n asyncSource.fetch({\n failure: (previous, error) => ({ ...previous, error, loading: false, pendingParams: undefined }),\n load: (signal) => config.load({ ...request, signal }),\n pending: (previous) => ({\n ...previous,\n error: null,\n loading: true,\n ...(Object.is(request.params, previous.params) ? {} : { pendingParams: request.params }),\n }),\n success: (result) => ({\n error: null,\n items: [...result.items],\n loading: false,\n pagination: createPagination(request.pageSize, result),\n params: request.params,\n }),\n });\n\n const source: CursorSource<T, TParams, TCursor> = {\n get disposalSignal() {\n return asyncSource.disposalSignal;\n },\n\n dispose: asyncSource.dispose,\n\n get disposed() {\n return asyncSource.disposed;\n },\n\n async next() {\n assertLive();\n const cursor = asyncSource.state.pagination.nextCursor;\n if (asyncSource.state.loading || cursor === undefined) return;\n requested = { after: cursor, pageSize: requested.pageSize, params: requested.params };\n await fetch(requested);\n },\n\n async previous() {\n assertLive();\n const cursor = asyncSource.state.pagination.previousCursor;\n if (asyncSource.state.loading || cursor === undefined) return;\n requested = { before: cursor, pageSize: requested.pageSize, params: requested.params };\n await fetch(requested);\n },\n\n reload() {\n return fetch(requested);\n },\n\n async setPageSize(pageSize) {\n assertLive();\n const normalized = positiveInteger(pageSize, 'pageSize');\n if (normalized === requested.pageSize && requested.after === undefined && requested.before === undefined) {\n if (\n asyncSource.state.loading ||\n (asyncSource.state.pagination.pageSize === normalized &&\n Object.is(asyncSource.state.params, requested.params))\n )\n return;\n await fetch(requested);\n return;\n }\n requested = { pageSize: normalized, params: requested.params };\n await fetch(requested);\n },\n\n async setParams(params) {\n assertLive();\n if (Object.is(params, requested.params)) {\n if (!asyncSource.state.loading && !Object.is(params, asyncSource.state.params)) await fetch(requested);\n return;\n }\n requested = { pageSize: requested.pageSize, params };\n await fetch(requested);\n },\n\n get state() {\n return asyncSource.state;\n },\n\n subscribe: asyncSource.subscribe,\n\n [Symbol.dispose]() {\n source.dispose();\n },\n };\n\n return source;\n}\n","import { createAsyncSource } from './asyncSource';\nimport { SourcererDisposedError } from './errors';\nimport { positiveInteger, totalItems } from './pagination';\nimport type { InfinitePagination, InfiniteSource, InfiniteSourceConfig, InfiniteSourceState } from './types';\n\ntype Request<TParams> = Readonly<{ pageSize: number; params: TParams }>;\n\nconst createPagination = (loadedItems: number, pageSize: number, total: number): InfinitePagination => ({\n hasMore: loadedItems < total,\n loadedItems,\n pageSize,\n totalItems: total,\n});\n\n/** Infinite sources retain committed items while replacement work is pending. */\nexport function createInfiniteSource<T, TParams = undefined>(\n config: InfiniteSourceConfig<T, TParams>,\n): InfiniteSource<T, TParams> {\n let requested: Request<TParams> = {\n pageSize: positiveInteger(config.pageSize ?? 20, 'pageSize'),\n params: config.params as TParams,\n };\n let nextPage = 1;\n let hasLoaded = false;\n const asyncSource = createAsyncSource<InfiniteSourceState<T, TParams>>({\n error: null,\n items: [],\n loading: false,\n pagination: createPagination(0, requested.pageSize, 0),\n params: requested.params,\n });\n const assertLive = (): void => {\n if (asyncSource.disposed) throw new SourcererDisposedError();\n };\n\n const fetch = (request: Request<TParams>, page: number, append: boolean): Promise<void> => {\n const loadedItems = asyncSource.state.items;\n\n return asyncSource.fetch({\n commit: () => {\n hasLoaded = true;\n nextPage = page + 1;\n requested = request;\n },\n failure: (previous, error) => ({ ...previous, error, loading: false, pendingParams: undefined }),\n load: (signal) => config.load({ page, pageSize: request.pageSize, params: request.params, signal }),\n pending: (previous) => ({\n ...previous,\n error: null,\n loading: true,\n ...(append || Object.is(request.params, previous.params) ? {} : { pendingParams: request.params }),\n }),\n success: (result) => {\n const items = append ? [...loadedItems, ...result.items] : [...result.items];\n return {\n error: null,\n items,\n loading: false,\n pagination: createPagination(items.length, request.pageSize, totalItems(result.totalItems)),\n params: request.params,\n };\n },\n });\n };\n\n const reload = (): Promise<void> => fetch(requested, 1, false);\n\n const source: InfiniteSource<T, TParams> = {\n get disposalSignal() {\n return asyncSource.disposalSignal;\n },\n\n dispose: asyncSource.dispose,\n\n get disposed() {\n return asyncSource.disposed;\n },\n\n async loadMore() {\n assertLive();\n if (asyncSource.state.loading) return;\n if (!hasLoaded || !Object.is(requested.params, asyncSource.state.params)) {\n await reload();\n return;\n }\n if (asyncSource.state.pagination.hasMore) await fetch(requested, nextPage, true);\n },\n\n reload,\n\n async setPageSize(pageSize) {\n assertLive();\n const normalized = positiveInteger(pageSize, 'pageSize');\n if (normalized === requested.pageSize) {\n if (asyncSource.state.loading || asyncSource.state.pagination.pageSize === normalized) return;\n await reload();\n return;\n }\n requested = { ...requested, pageSize: normalized };\n nextPage = 1;\n await reload();\n },\n\n async setParams(params) {\n assertLive();\n if (Object.is(params, requested.params)) {\n if (!asyncSource.state.loading && !Object.is(params, asyncSource.state.params)) await reload();\n return;\n }\n requested = { ...requested, params };\n nextPage = 1;\n await reload();\n },\n\n get state() {\n return asyncSource.state;\n },\n\n subscribe: asyncSource.subscribe,\n\n [Symbol.dispose]() {\n source.dispose();\n },\n };\n\n return source;\n}\n","import { SourcererDisposedError } from './errors';\nimport { createPagePagination, positiveInteger } from './pagination';\nimport { createSourceStore } from './sourceStore';\nimport type { LocalSource, LocalSourceConfig, LocalSourceState, PagePagination } from './types';\n\n/** Local sources filter and paginate an in-memory collection synchronously. */\nexport function createLocalSource<T>(items: readonly T[]): LocalSource<T>;\nexport function createLocalSource<T, TParams = undefined>(\n items: readonly T[],\n config: LocalSourceConfig<T, TParams>,\n): LocalSource<T, TParams>;\nexport function createLocalSource<T, TParams = undefined>(\n items: readonly T[],\n config: LocalSourceConfig<T, TParams> = {} as LocalSourceConfig<T, TParams>,\n): LocalSource<T, TParams> {\n let allItems = items;\n let page = 1;\n let pageSize = positiveInteger(config.pageSize ?? 20, 'pageSize');\n let params = config.params as TParams;\n\n const buildState = (): LocalSourceState<T, TParams> => {\n const filtered = config.filter ? allItems.filter((item) => config.filter?.(item, params)) : allItems;\n const pagination = createPagePagination(page, pageSize, filtered.length);\n if (page > pagination.pageCount) {\n page = pagination.pageCount;\n return buildState();\n }\n const start = (page - 1) * pageSize;\n\n return {\n error: null,\n items: filtered.slice(start, start + pageSize),\n loading: false,\n pagination,\n params,\n };\n };\n\n const store = createSourceStore(buildState());\n const assertLive = (): void => {\n if (store.disposed) throw new SourcererDisposedError();\n };\n const samePagination = (left: PagePagination, right: PagePagination): boolean =>\n Object.keys(left).every((key) => left[key as keyof PagePagination] === right[key as keyof PagePagination]);\n const commit = (): void => {\n const next = buildState();\n const current = store.value;\n const sameItems =\n next.items.length === current.items.length &&\n next.items.every((item, index) => Object.is(item, current.items[index]));\n\n if (Object.is(next.params, current.params) && sameItems && samePagination(next.pagination, current.pagination))\n return;\n store.set(next);\n };\n const goTo = (nextPage: number): void => {\n assertLive();\n const normalized = Math.min(positiveInteger(nextPage, 'page'), store.value.pagination.pageCount);\n if (normalized === page) return;\n page = normalized;\n commit();\n };\n\n const source: LocalSource<T, TParams> = {\n get disposalSignal() {\n return store.disposalSignal;\n },\n\n dispose: store.dispose,\n\n get disposed() {\n return store.disposed;\n },\n\n first() {\n goTo(1);\n },\n\n goTo,\n\n last() {\n goTo(store.value.pagination.pageCount);\n },\n\n next() {\n if (store.value.pagination.hasNext) goTo(page + 1);\n else assertLive();\n },\n\n previous() {\n if (store.value.pagination.hasPrevious) goTo(page - 1);\n else assertLive();\n },\n\n setItems(nextItems) {\n assertLive();\n if (nextItems === allItems) return;\n allItems = nextItems;\n commit();\n },\n\n setPageSize(nextPageSize) {\n assertLive();\n const normalized = positiveInteger(nextPageSize, 'pageSize');\n if (normalized === pageSize) return;\n page = 1;\n pageSize = normalized;\n commit();\n },\n\n setParams(nextParams) {\n assertLive();\n if (Object.is(nextParams, params)) return;\n page = 1;\n params = nextParams;\n commit();\n },\n\n get state() {\n return store.value;\n },\n\n subscribe: store.subscribe,\n\n [Symbol.dispose]() {\n source.dispose();\n },\n };\n\n return source;\n}\n","import { isEqual } from '@vielzeug/arsenal';\n\nimport { createAsyncSource } from './asyncSource';\nimport { SourcererDisposedError } from './errors';\nimport { createPagePagination, positiveInteger, totalItems } from './pagination';\nimport type { PageSource, PageSourceConfig, PageSourceState } from './types';\n\ntype Request<TParams> = Readonly<{ page: number; pageSize: number; params: TParams }>;\n\n/** Page sources retain committed items while replacement work is pending. */\nexport function createPageSource<T, TParams = undefined>(config: PageSourceConfig<T, TParams>): PageSource<T, TParams> {\n let requested: Request<TParams> = {\n page: 1,\n pageSize: positiveInteger(config.pageSize ?? 20, 'pageSize'),\n params: config.params as TParams,\n };\n let hasLoaded = false;\n const asyncSource = createAsyncSource<PageSourceState<T, TParams>>({\n error: null,\n items: [],\n loading: false,\n pagination: createPagePagination(requested.page, requested.pageSize, 0),\n params: requested.params,\n });\n const assertLive = (): void => {\n if (asyncSource.disposed) throw new SourcererDisposedError();\n };\n const isCommitted = (request: Request<TParams>): boolean =>\n asyncSource.state.pagination.page === request.page &&\n asyncSource.state.pagination.pageSize === request.pageSize &&\n Object.is(asyncSource.state.params, request.params);\n\n const fetch = (request: Request<TParams>): Promise<void> =>\n asyncSource.fetch({\n commit: () => {\n hasLoaded = true;\n requested = request;\n },\n failure: (previous, error) => ({ ...previous, error, loading: false, pendingParams: undefined }),\n load: (signal) => config.load({ ...request, signal }),\n pending: (previous) => ({\n ...previous,\n error: null,\n loading: true,\n ...(Object.is(request.params, previous.params) ? {} : { pendingParams: request.params }),\n }),\n success: (result) => ({\n error: null,\n items: [...result.items],\n loading: false,\n pagination: createPagePagination(request.page, request.pageSize, totalItems(result.totalItems)),\n params: request.params,\n }),\n });\n\n const normalizePage = (page: number): number =>\n hasLoaded\n ? Math.min(positiveInteger(page, 'page'), asyncSource.state.pagination.pageCount)\n : positiveInteger(page, 'page');\n\n const goTo = async (page: number): Promise<void> => {\n assertLive();\n const normalized = normalizePage(page);\n if (normalized === requested.page) {\n if (!asyncSource.state.loading && (!hasLoaded || !isCommitted(requested))) await fetch(requested);\n return;\n }\n requested = { ...requested, page: normalized };\n await fetch(requested);\n };\n\n const source: PageSource<T, TParams> = {\n async apply(update) {\n assertLive();\n // An absent `params` means \"not part of this update\", which is how a source whose\n // TParams genuinely allows undefined keeps its params: use setParams for that.\n const params = update.params === undefined ? requested.params : update.params;\n\n if (!isEqual(params, requested.params)) {\n // The committed page count belongs to the previous params, so clamping here\n // would clamp to a stale bound. The requested page is validated and sent as\n // given; the response recomputes pagination from real totals.\n requested = {\n ...requested,\n page: update.page === undefined ? 1 : positiveInteger(update.page, 'page'),\n params,\n };\n await fetch(requested);\n return;\n }\n\n if (update.page !== undefined) {\n await goTo(update.page);\n return;\n }\n\n if (!asyncSource.state.loading && (!hasLoaded || !isCommitted(requested))) await fetch(requested);\n },\n\n get disposalSignal() {\n return asyncSource.disposalSignal;\n },\n\n dispose: asyncSource.dispose,\n\n get disposed() {\n return asyncSource.disposed;\n },\n\n first() {\n return goTo(1);\n },\n\n goTo,\n\n last() {\n return goTo(asyncSource.state.pagination.pageCount);\n },\n\n async next() {\n assertLive();\n if (!hasLoaded || requested.page < asyncSource.state.pagination.pageCount) await goTo(requested.page + 1);\n },\n\n async previous() {\n assertLive();\n if (requested.page > 1) await goTo(requested.page - 1);\n },\n\n reload() {\n return fetch(requested);\n },\n\n async setPageSize(pageSize) {\n assertLive();\n const normalized = positiveInteger(pageSize, 'pageSize');\n if (normalized === requested.pageSize && requested.page === 1) {\n if (!asyncSource.state.loading && !isCommitted(requested)) await fetch(requested);\n return;\n }\n requested = { ...requested, page: 1, pageSize: normalized };\n await fetch(requested);\n },\n\n async setParams(params) {\n assertLive();\n if (Object.is(params, requested.params)) {\n if (!asyncSource.state.loading && !isCommitted(requested)) await fetch(requested);\n return;\n }\n requested = { ...requested, page: 1, params };\n await fetch(requested);\n },\n\n get state() {\n return asyncSource.state;\n },\n\n subscribe: asyncSource.subscribe,\n\n [Symbol.dispose]() {\n source.dispose();\n },\n };\n\n return source;\n}\n","import { createAsyncSource } from './asyncSource';\nimport { SourcererDisposedError } from './errors';\nimport type { Resource, ResourceConfig, ResourceState } from './types';\n\nconst initialResourceState = <T>(start: boolean): ResourceState<T> => ({\n data: undefined,\n error: null,\n loading: start,\n});\n\n/**\n * Fetch one value, reactively. `load` receives a signal that aborts on disposal and on\n * the next `reload`, so a superseded response can never commit over a newer one.\n *\n * Unlike the paginated sources, a resource starts loading during construction — it\n * models a value that must exist rather than a window into a collection. Pass\n * `start: false` to trigger the first `reload()` yourself. A failed initial load is\n * reported through `state.error` rather than as an unhandled rejection; later `reload()`\n * calls reject so callers can await them directly.\n */\nexport function createResource<T>(config: ResourceConfig<T>): Resource<T> {\n const start = config.start ?? true;\n const asyncSource = createAsyncSource<ResourceState<T>>(initialResourceState<T>(start));\n\n const fetchResource = (): Promise<void> =>\n asyncSource.fetch({\n failure: (previous, error) => ({ ...previous, error, loading: false }),\n load: (signal) => config.load({ signal }),\n pending: (previous) => ({ ...previous, error: null, loading: true }),\n success: (data) => ({ data, error: null, loading: false }),\n });\n\n const source: Resource<T> = {\n get disposalSignal() {\n return asyncSource.disposalSignal;\n },\n\n dispose: asyncSource.dispose,\n\n get disposed() {\n return asyncSource.disposed;\n },\n\n reload() {\n if (asyncSource.disposed) return Promise.reject(new SourcererDisposedError());\n\n return fetchResource();\n },\n\n get state() {\n return asyncSource.state;\n },\n\n subscribe: asyncSource.subscribe,\n\n [Symbol.dispose]() {\n source.dispose();\n },\n };\n\n if (start) {\n // The initial load has no caller to reject to: failures surface via state.error.\n void fetchResource().catch(() => undefined);\n }\n\n return source;\n}\n"],"mappings":";;AACA,IAAa,iBAAb,cAAoC,MAAM;CACxC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAMC,GAASC,CAAI,GACnB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;AACF,GAGa,8BAAb,cAAiD,eAAe,CAAC,GAEpD,yBAAb,cAA4C,eAAe;CACzD,YAAY,IAAU,6BAA6B;EACjD,MAAMD,CAAO;CACf;AACF;;;ACJA,SAAgB,0BAA6C;CAC3D,IAAIE,GACAC,IAAW;CAEf,OAAO;EACL,QAAQ;GACN,GAAQ,MAAM;GAEd,IAAMC,IAAa,IAAI,gBAAgB,GACjCC,IAAkB,EAAEF;GAI1B,OAFA,IAASC,GAEF;IACL,SAAS;KACP,AAAIC,MAAoBF,MAAU,IAAS,KAAA;IAC7C;IAEA,YAAY;KACV,OAAOE,MAAoBF;IAC7B;IAEA,QAAQC,EAAW;GACrB;EACF;EAEA,UAAU;GAGR,AAFAF,GAAQ,MAAM,GACd,IAAS,KAAA,GACT;EACF;CACF;AACF;AAEA,SAAgB,QAAQ,GAAwB;CAC9C,IAAII,aAAkB,OAAO,OAAOA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mB,CAAC,CAAC,YAAY,KAAA,CAAS,GAGrCb;AACT"}
|
|
1
|
+
{"version":3,"file":"sourcerer.js","names":["createPagination","message","opts","active","sequence","controller","requestSequence","reason","listeners","disposed","value","initialValue","nextValue","listener","error","reject","abortError","signal","result","load","resolve","store","initial","requests","request","previous","options","state","name","pageCount","total","pageSize","page","config","requested","asyncSource","source","cursor","normalized","params","loadedItems","nextPage","hasLoaded","append","items","allItems","filtered","item","pagination","start","left","key","right","next","current","sameItems","index","nextItems","nextPageSize","nextParams","update","isEqual"],"sources":["../src/errors.ts","../src/requestController.ts","../src/sourceStore.ts","../src/asyncSource.ts","../src/pagination.ts","../src/cursorSource.ts","../src/infiniteSource.ts","../src/localSource.ts","../src/pageSource.ts","../src/resourceSource.ts"],"sourcesContent":["/** Base class for all sourcerer errors. Use `instanceof SourcererError` to catch any sourcerer-originated error. */\nexport class SourcererError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a source is configured or queried with invalid arguments. */\nexport class SourcererConfigurationError extends SourcererError {}\n\nexport class SourcererDisposedError extends SourcererError {\n constructor(message = 'Sourcerer source disposed') {\n super(message);\n }\n}\n","export type RequestHandle = Readonly<{\n finish(): void;\n isCurrent(): boolean;\n signal: AbortSignal;\n}>;\n\nexport type RequestController = Readonly<{\n begin(): RequestHandle;\n dispose(): void;\n}>;\n\n/** A source owns one active request: newer query state always supersedes older work. */\nexport function createRequestController(): RequestController {\n let active: AbortController | undefined;\n let sequence = 0;\n\n return {\n begin() {\n active?.abort();\n\n const controller = new AbortController();\n const requestSequence = ++sequence;\n\n active = controller;\n\n return {\n finish() {\n if (requestSequence === sequence) active = undefined;\n },\n\n isCurrent() {\n return requestSequence === sequence;\n },\n\n signal: controller.signal,\n };\n },\n\n dispose() {\n active?.abort();\n active = undefined;\n sequence++;\n },\n };\n}\n\nexport function toError(reason: unknown): Error {\n if (reason instanceof Error) return reason;\n\n const message = typeof reason === 'string' && reason.length > 0 ? reason : 'Source request failed';\n\n return new Error(message, { cause: reason });\n}\n","type SourceStore<T> = {\n [Symbol.dispose](): void;\n readonly disposalSignal: AbortSignal;\n dispose(): void;\n readonly disposed: boolean;\n set(value: T): void;\n subscribe(listener: (value: T) => void): () => void;\n readonly value: T;\n};\n\n/** Store commits source state before notifying; observer failures cannot rewrite committed state. */\nexport function createSourceStore<T>(initialValue: T): SourceStore<T> {\n const controller = new AbortController();\n const listeners = new Set<(value: T) => void>();\n let disposed = false;\n let value = initialValue;\n\n const dispose = (): void => {\n if (disposed) return;\n\n disposed = true;\n listeners.clear();\n controller.abort();\n };\n\n return {\n get disposalSignal() {\n return controller.signal;\n },\n\n dispose,\n\n get disposed() {\n return disposed;\n },\n\n set(nextValue) {\n if (disposed) return;\n\n value = nextValue;\n\n for (const listener of listeners) {\n try {\n listener(value);\n } catch (error) {\n queueMicrotask(() => {\n throw error;\n });\n }\n }\n },\n\n subscribe(listener) {\n if (disposed) return () => {};\n\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n },\n\n [Symbol.dispose]: dispose,\n\n get value() {\n return value;\n },\n };\n}\n","import { abortError } from '@vielzeug/arsenal';\n\nimport { SourcererDisposedError } from './errors';\nimport { createRequestController, toError } from './requestController';\nimport { createSourceStore } from './sourceStore';\n\nconst loadWithSignal = <T>(load: (signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T> =>\n new Promise((resolve, reject) => {\n const abort = (): void => reject(abortError(signal, 'The operation was aborted.'));\n if (signal.aborted) {\n abort();\n return;\n }\n\n signal.addEventListener('abort', abort, { once: true });\n let result: Promise<T>;\n try {\n result = load(signal);\n } catch (error) {\n signal.removeEventListener('abort', abort);\n reject(error);\n return;\n }\n\n result.then(\n (value) => {\n signal.removeEventListener('abort', abort);\n resolve(value);\n },\n (error: unknown) => {\n signal.removeEventListener('abort', abort);\n reject(error);\n },\n );\n });\n\ntype FetchOptions<TState, TResult> = {\n load(signal: AbortSignal): Promise<TResult>;\n success(result: TResult): TState;\n commit?(state: TState, result: TResult): void;\n pending(previous: TState): TState;\n failure(previous: TState, error: Error): TState;\n};\n\ntype AsyncSource<TState> = Readonly<{\n readonly disposalSignal: AbortSignal;\n dispose(): void;\n readonly disposed: boolean;\n fetch<TResult>(options: FetchOptions<TState, TResult>): Promise<void>;\n readonly state: TState;\n subscribe(listener: (state: TState) => void): () => void;\n}>;\n\n/** Only the current request may commit; superseded work settles without changing source state. */\nexport function createAsyncSource<TState>(initial: TState): AsyncSource<TState> {\n const store = createSourceStore(initial);\n const requests = createRequestController();\n\n return {\n get disposalSignal() {\n return store.disposalSignal;\n },\n\n dispose() {\n requests.dispose();\n store.dispose();\n },\n\n get disposed() {\n return store.disposed;\n },\n\n async fetch(options) {\n if (store.disposed) throw new SourcererDisposedError();\n\n const request = requests.begin();\n const previous = store.value;\n store.set(options.pending(previous));\n\n try {\n const result = await loadWithSignal(options.load, request.signal);\n if (!request.isCurrent() || store.disposed) return;\n\n const state = options.success(result);\n options.commit?.(state, result);\n store.set(state);\n } catch (reason: unknown) {\n if (!request.isCurrent() || store.disposed) return;\n\n const error = toError(reason);\n store.set(options.failure(previous, error));\n throw error;\n } finally {\n request.finish();\n }\n },\n\n get state() {\n return store.value;\n },\n\n subscribe: store.subscribe,\n };\n}\n","import { SourcererConfigurationError } from './errors';\nimport type { PagePagination } from './types';\n\nexport function positiveInteger(value: number, name: string): number {\n if (!Number.isInteger(value) || value < 1)\n throw new SourcererConfigurationError(`${name} must be a positive integer`);\n\n return value;\n}\n\nexport function totalItems(value: number): number {\n if (!Number.isInteger(value) || value < 0)\n throw new SourcererConfigurationError('totalItems must be a non-negative integer');\n\n return value;\n}\n\nexport function createPagePagination(page: number, pageSize: number, total: number): PagePagination {\n const pageCount = Math.max(1, Math.ceil(total / pageSize));\n\n return {\n hasNext: page < pageCount,\n hasPrevious: page > 1,\n page,\n pageCount,\n pageSize,\n totalItems: total,\n };\n}\n","import { createAsyncSource } from './asyncSource';\nimport { SourcererConfigurationError, SourcererDisposedError } from './errors';\nimport { positiveInteger, totalItems } from './pagination';\nimport type { CursorPagination, CursorResult, CursorSource, CursorSourceConfig, CursorSourceState } from './types';\n\ntype Request<TParams, TCursor> = Readonly<{\n after?: TCursor;\n before?: TCursor;\n pageSize: number;\n params: TParams;\n}>;\n\nconst createPagination = <TCursor>(\n pageSize: number,\n result?: CursorResult<unknown, TCursor>,\n): CursorPagination<TCursor> => ({\n ...(result?.nextCursor !== undefined && { nextCursor: result.nextCursor }),\n pageSize,\n ...(result?.previousCursor !== undefined && { previousCursor: result.previousCursor }),\n ...(result?.totalItems !== undefined && { totalItems: totalItems(result.totalItems) }),\n});\n\n/** Cursor sources retain committed items and cursors while replacement work is pending. */\nexport function createCursorSource<T, TParams = undefined, TCursor = string>(\n config: CursorSourceConfig<T, TParams, TCursor>,\n): CursorSource<T, TParams, TCursor> {\n if (config.after !== undefined && config.before !== undefined) {\n throw new SourcererConfigurationError('Cursor source cannot start with both after and before');\n }\n\n let requested: Request<TParams, TCursor> = {\n ...(config.after !== undefined && { after: config.after }),\n ...(config.before !== undefined && { before: config.before }),\n pageSize: positiveInteger(config.pageSize ?? 20, 'pageSize'),\n params: config.params as TParams,\n };\n const asyncSource = createAsyncSource<CursorSourceState<T, TParams, TCursor>>({\n error: null,\n items: [],\n loading: false,\n pagination: createPagination(requested.pageSize),\n params: requested.params,\n });\n const assertLive = (): void => {\n if (asyncSource.disposed) throw new SourcererDisposedError();\n };\n\n const fetch = (request: Request<TParams, TCursor>): Promise<void> =>\n asyncSource.fetch({\n failure: (previous, error) => ({ ...previous, error, loading: false, pendingParams: undefined }),\n load: (signal) => config.load({ ...request, signal }),\n pending: (previous) => ({\n ...previous,\n error: null,\n loading: true,\n ...(Object.is(request.params, previous.params) ? {} : { pendingParams: request.params }),\n }),\n success: (result) => ({\n error: null,\n items: [...result.items],\n loading: false,\n pagination: createPagination(request.pageSize, result),\n params: request.params,\n }),\n });\n\n const source: CursorSource<T, TParams, TCursor> = {\n get disposalSignal() {\n return asyncSource.disposalSignal;\n },\n\n dispose: asyncSource.dispose,\n\n get disposed() {\n return asyncSource.disposed;\n },\n\n async next() {\n assertLive();\n const cursor = asyncSource.state.pagination.nextCursor;\n if (asyncSource.state.loading || cursor === undefined) return;\n requested = { after: cursor, pageSize: requested.pageSize, params: requested.params };\n await fetch(requested);\n },\n\n async previous() {\n assertLive();\n const cursor = asyncSource.state.pagination.previousCursor;\n if (asyncSource.state.loading || cursor === undefined) return;\n requested = { before: cursor, pageSize: requested.pageSize, params: requested.params };\n await fetch(requested);\n },\n\n reload() {\n return fetch(requested);\n },\n\n async setPageSize(pageSize) {\n assertLive();\n const normalized = positiveInteger(pageSize, 'pageSize');\n if (normalized === requested.pageSize && requested.after === undefined && requested.before === undefined) {\n if (\n asyncSource.state.loading ||\n (asyncSource.state.pagination.pageSize === normalized &&\n Object.is(asyncSource.state.params, requested.params))\n )\n return;\n await fetch(requested);\n return;\n }\n requested = { pageSize: normalized, params: requested.params };\n await fetch(requested);\n },\n\n async setParams(params) {\n assertLive();\n if (Object.is(params, requested.params)) {\n if (!asyncSource.state.loading && !Object.is(params, asyncSource.state.params)) await fetch(requested);\n return;\n }\n requested = { pageSize: requested.pageSize, params };\n await fetch(requested);\n },\n\n get state() {\n return asyncSource.state;\n },\n\n subscribe: asyncSource.subscribe,\n\n [Symbol.dispose]() {\n source.dispose();\n },\n };\n\n return source;\n}\n","import { createAsyncSource } from './asyncSource';\nimport { SourcererDisposedError } from './errors';\nimport { positiveInteger, totalItems } from './pagination';\nimport type { InfinitePagination, InfiniteSource, InfiniteSourceConfig, InfiniteSourceState } from './types';\n\ntype Request<TParams> = Readonly<{ pageSize: number; params: TParams }>;\n\nconst createPagination = (loadedItems: number, pageSize: number, total: number): InfinitePagination => ({\n hasMore: loadedItems < total,\n loadedItems,\n pageSize,\n totalItems: total,\n});\n\n/** Infinite sources retain committed items while replacement work is pending. */\nexport function createInfiniteSource<T, TParams = undefined>(\n config: InfiniteSourceConfig<T, TParams>,\n): InfiniteSource<T, TParams> {\n let requested: Request<TParams> = {\n pageSize: positiveInteger(config.pageSize ?? 20, 'pageSize'),\n params: config.params as TParams,\n };\n let nextPage = 1;\n let hasLoaded = false;\n const asyncSource = createAsyncSource<InfiniteSourceState<T, TParams>>({\n error: null,\n items: [],\n loading: false,\n pagination: createPagination(0, requested.pageSize, 0),\n params: requested.params,\n });\n const assertLive = (): void => {\n if (asyncSource.disposed) throw new SourcererDisposedError();\n };\n\n const fetch = (request: Request<TParams>, page: number, append: boolean): Promise<void> => {\n const loadedItems = asyncSource.state.items;\n\n return asyncSource.fetch({\n commit: () => {\n hasLoaded = true;\n nextPage = page + 1;\n requested = request;\n },\n failure: (previous, error) => ({ ...previous, error, loading: false, pendingParams: undefined }),\n load: (signal) => config.load({ page, pageSize: request.pageSize, params: request.params, signal }),\n pending: (previous) => ({\n ...previous,\n error: null,\n loading: true,\n ...(append || Object.is(request.params, previous.params) ? {} : { pendingParams: request.params }),\n }),\n success: (result) => {\n const items = append ? [...loadedItems, ...result.items] : [...result.items];\n return {\n error: null,\n items,\n loading: false,\n pagination: createPagination(items.length, request.pageSize, totalItems(result.totalItems)),\n params: request.params,\n };\n },\n });\n };\n\n const reload = (): Promise<void> => fetch(requested, 1, false);\n\n const source: InfiniteSource<T, TParams> = {\n get disposalSignal() {\n return asyncSource.disposalSignal;\n },\n\n dispose: asyncSource.dispose,\n\n get disposed() {\n return asyncSource.disposed;\n },\n\n async loadMore() {\n assertLive();\n if (asyncSource.state.loading) return;\n if (!hasLoaded || !Object.is(requested.params, asyncSource.state.params)) {\n await reload();\n return;\n }\n if (asyncSource.state.pagination.hasMore) await fetch(requested, nextPage, true);\n },\n\n reload,\n\n async setPageSize(pageSize) {\n assertLive();\n const normalized = positiveInteger(pageSize, 'pageSize');\n if (normalized === requested.pageSize) {\n if (asyncSource.state.loading || asyncSource.state.pagination.pageSize === normalized) return;\n await reload();\n return;\n }\n requested = { ...requested, pageSize: normalized };\n nextPage = 1;\n await reload();\n },\n\n async setParams(params) {\n assertLive();\n if (Object.is(params, requested.params)) {\n if (!asyncSource.state.loading && !Object.is(params, asyncSource.state.params)) await reload();\n return;\n }\n requested = { ...requested, params };\n nextPage = 1;\n await reload();\n },\n\n get state() {\n return asyncSource.state;\n },\n\n subscribe: asyncSource.subscribe,\n\n [Symbol.dispose]() {\n source.dispose();\n },\n };\n\n return source;\n}\n","import { SourcererDisposedError } from './errors';\nimport { createPagePagination, positiveInteger } from './pagination';\nimport { createSourceStore } from './sourceStore';\nimport type { LocalSource, LocalSourceConfig, LocalSourceState, PagePagination } from './types';\n\n/** Local sources filter and paginate an in-memory collection synchronously. */\nexport function createLocalSource<T>(items: readonly T[]): LocalSource<T>;\nexport function createLocalSource<T, TParams = undefined>(\n items: readonly T[],\n config: LocalSourceConfig<T, TParams>,\n): LocalSource<T, TParams>;\nexport function createLocalSource<T, TParams = undefined>(\n items: readonly T[],\n config: LocalSourceConfig<T, TParams> = {} as LocalSourceConfig<T, TParams>,\n): LocalSource<T, TParams> {\n let allItems = items;\n let page = 1;\n let pageSize = positiveInteger(config.pageSize ?? 20, 'pageSize');\n let params = config.params as TParams;\n\n const buildState = (): LocalSourceState<T, TParams> => {\n const filtered = config.filter ? allItems.filter((item) => config.filter?.(item, params)) : allItems;\n const pagination = createPagePagination(page, pageSize, filtered.length);\n if (page > pagination.pageCount) {\n page = pagination.pageCount;\n return buildState();\n }\n const start = (page - 1) * pageSize;\n\n return {\n error: null,\n items: filtered.slice(start, start + pageSize),\n loading: false,\n pagination,\n params,\n };\n };\n\n const store = createSourceStore(buildState());\n const assertLive = (): void => {\n if (store.disposed) throw new SourcererDisposedError();\n };\n const samePagination = (left: PagePagination, right: PagePagination): boolean =>\n Object.keys(left).every((key) => left[key as keyof PagePagination] === right[key as keyof PagePagination]);\n const commit = (): void => {\n const next = buildState();\n const current = store.value;\n const sameItems =\n next.items.length === current.items.length &&\n next.items.every((item, index) => Object.is(item, current.items[index]));\n\n if (Object.is(next.params, current.params) && sameItems && samePagination(next.pagination, current.pagination))\n return;\n store.set(next);\n };\n const goTo = (nextPage: number): void => {\n assertLive();\n const normalized = Math.min(positiveInteger(nextPage, 'page'), store.value.pagination.pageCount);\n if (normalized === page) return;\n page = normalized;\n commit();\n };\n\n const source: LocalSource<T, TParams> = {\n get disposalSignal() {\n return store.disposalSignal;\n },\n\n dispose: store.dispose,\n\n get disposed() {\n return store.disposed;\n },\n\n first() {\n goTo(1);\n },\n\n goTo,\n\n last() {\n goTo(store.value.pagination.pageCount);\n },\n\n next() {\n if (store.value.pagination.hasNext) goTo(page + 1);\n else assertLive();\n },\n\n previous() {\n if (store.value.pagination.hasPrevious) goTo(page - 1);\n else assertLive();\n },\n\n setItems(nextItems) {\n assertLive();\n if (nextItems === allItems) return;\n allItems = nextItems;\n commit();\n },\n\n setPageSize(nextPageSize) {\n assertLive();\n const normalized = positiveInteger(nextPageSize, 'pageSize');\n if (normalized === pageSize) return;\n page = 1;\n pageSize = normalized;\n commit();\n },\n\n setParams(nextParams) {\n assertLive();\n if (Object.is(nextParams, params)) return;\n page = 1;\n params = nextParams;\n commit();\n },\n\n get state() {\n return store.value;\n },\n\n subscribe: store.subscribe,\n\n [Symbol.dispose]() {\n source.dispose();\n },\n };\n\n return source;\n}\n","import { isEqual } from '@vielzeug/arsenal';\n\nimport { createAsyncSource } from './asyncSource';\nimport { SourcererDisposedError } from './errors';\nimport { createPagePagination, positiveInteger, totalItems } from './pagination';\nimport type { PageSource, PageSourceConfig, PageSourceState } from './types';\n\ntype Request<TParams> = Readonly<{ page: number; pageSize: number; params: TParams }>;\n\n/** Page sources retain committed items while replacement work is pending. */\nexport function createPageSource<T, TParams = undefined>(config: PageSourceConfig<T, TParams>): PageSource<T, TParams> {\n let requested: Request<TParams> = {\n page: 1,\n pageSize: positiveInteger(config.pageSize ?? 20, 'pageSize'),\n params: config.params as TParams,\n };\n let hasLoaded = false;\n const asyncSource = createAsyncSource<PageSourceState<T, TParams>>({\n error: null,\n items: [],\n loading: false,\n pagination: createPagePagination(requested.page, requested.pageSize, 0),\n params: requested.params,\n });\n const assertLive = (): void => {\n if (asyncSource.disposed) throw new SourcererDisposedError();\n };\n const isCommitted = (request: Request<TParams>): boolean =>\n asyncSource.state.pagination.page === request.page &&\n asyncSource.state.pagination.pageSize === request.pageSize &&\n Object.is(asyncSource.state.params, request.params);\n\n const fetch = (request: Request<TParams>): Promise<void> =>\n asyncSource.fetch({\n commit: () => {\n hasLoaded = true;\n requested = request;\n },\n failure: (previous, error) => ({ ...previous, error, loading: false, pendingParams: undefined }),\n load: (signal) => config.load({ ...request, signal }),\n pending: (previous) => ({\n ...previous,\n error: null,\n loading: true,\n ...(Object.is(request.params, previous.params) ? {} : { pendingParams: request.params }),\n }),\n success: (result) => ({\n error: null,\n items: [...result.items],\n loading: false,\n pagination: createPagePagination(request.page, request.pageSize, totalItems(result.totalItems)),\n params: request.params,\n }),\n });\n\n const normalizePage = (page: number): number =>\n hasLoaded\n ? Math.min(positiveInteger(page, 'page'), asyncSource.state.pagination.pageCount)\n : positiveInteger(page, 'page');\n\n const goTo = async (page: number): Promise<void> => {\n assertLive();\n const normalized = normalizePage(page);\n if (normalized === requested.page) {\n if (!asyncSource.state.loading && (!hasLoaded || !isCommitted(requested))) await fetch(requested);\n return;\n }\n requested = { ...requested, page: normalized };\n await fetch(requested);\n };\n\n const source: PageSource<T, TParams> = {\n async apply(update) {\n assertLive();\n // An absent `params` means \"not part of this update\", which is how a source whose\n // TParams genuinely allows undefined keeps its params: use setParams for that.\n const params = update.params === undefined ? requested.params : update.params;\n\n if (!isEqual(params, requested.params)) {\n // The committed page count belongs to the previous params, so clamping here\n // would clamp to a stale bound. The requested page is validated and sent as\n // given; the response recomputes pagination from real totals.\n requested = {\n ...requested,\n page: update.page === undefined ? 1 : positiveInteger(update.page, 'page'),\n params,\n };\n await fetch(requested);\n return;\n }\n\n if (update.page !== undefined) {\n await goTo(update.page);\n return;\n }\n\n if (!asyncSource.state.loading && (!hasLoaded || !isCommitted(requested))) await fetch(requested);\n },\n\n get disposalSignal() {\n return asyncSource.disposalSignal;\n },\n\n dispose: asyncSource.dispose,\n\n get disposed() {\n return asyncSource.disposed;\n },\n\n first() {\n return goTo(1);\n },\n\n goTo,\n\n last() {\n return goTo(asyncSource.state.pagination.pageCount);\n },\n\n async next() {\n assertLive();\n if (!hasLoaded || requested.page < asyncSource.state.pagination.pageCount) await goTo(requested.page + 1);\n },\n\n async previous() {\n assertLive();\n if (requested.page > 1) await goTo(requested.page - 1);\n },\n\n reload() {\n return fetch(requested);\n },\n\n async setPageSize(pageSize) {\n assertLive();\n const normalized = positiveInteger(pageSize, 'pageSize');\n if (normalized === requested.pageSize && requested.page === 1) {\n if (!asyncSource.state.loading && !isCommitted(requested)) await fetch(requested);\n return;\n }\n requested = { ...requested, page: 1, pageSize: normalized };\n await fetch(requested);\n },\n\n async setParams(params) {\n assertLive();\n if (Object.is(params, requested.params)) {\n if (!asyncSource.state.loading && !isCommitted(requested)) await fetch(requested);\n return;\n }\n requested = { ...requested, page: 1, params };\n await fetch(requested);\n },\n\n get state() {\n return asyncSource.state;\n },\n\n subscribe: asyncSource.subscribe,\n\n [Symbol.dispose]() {\n source.dispose();\n },\n };\n\n return source;\n}\n","import { createAsyncSource } from './asyncSource';\nimport { SourcererDisposedError } from './errors';\nimport type { Resource, ResourceConfig, ResourceState } from './types';\n\nconst initialResourceState = <T>(start: boolean): ResourceState<T> => ({\n data: undefined,\n error: null,\n loading: start,\n});\n\n/**\n * Fetch one value, reactively. `load` receives a signal that aborts on disposal and on\n * the next `reload`, so a superseded response can never commit over a newer one.\n *\n * Unlike the paginated sources, a resource starts loading during construction — it\n * models a value that must exist rather than a window into a collection. Pass\n * `start: false` to trigger the first `reload()` yourself. A failed initial load is\n * reported through `state.error` rather than as an unhandled rejection; later `reload()`\n * calls reject so callers can await them directly.\n */\nexport function createResource<T>(config: ResourceConfig<T>): Resource<T> {\n const start = config.start ?? true;\n const asyncSource = createAsyncSource<ResourceState<T>>(initialResourceState<T>(start));\n\n const fetchResource = (): Promise<void> =>\n asyncSource.fetch({\n failure: (previous, error) => ({ ...previous, error, loading: false }),\n load: (signal) => config.load({ signal }),\n pending: (previous) => ({ ...previous, error: null, loading: true }),\n success: (data) => ({ data, error: null, loading: false }),\n });\n\n const source: Resource<T> = {\n get disposalSignal() {\n return asyncSource.disposalSignal;\n },\n\n dispose: asyncSource.dispose,\n\n get disposed() {\n return asyncSource.disposed;\n },\n\n reload() {\n if (asyncSource.disposed) return Promise.reject(new SourcererDisposedError());\n\n return fetchResource();\n },\n\n get state() {\n return asyncSource.state;\n },\n\n subscribe: asyncSource.subscribe,\n\n [Symbol.dispose]() {\n source.dispose();\n },\n };\n\n if (start) {\n // The initial load has no caller to reject to: failures surface via state.error.\n void fetchResource().catch(() => undefined);\n }\n\n return source;\n}\n"],"mappings":";;AACA,IAAa,iBAAb,cAAoC,MAAM;CACxC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAMC,GAASC,CAAI,GACnB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;AACF,GAGa,8BAAb,cAAiD,eAAe,CAAC,GAEpD,yBAAb,cAA4C,eAAe;CACzD,YAAY,IAAU,6BAA6B;EACjD,MAAMD,CAAO;CACf;AACF;;ACJA,SAAgB,0BAA6C;CAC3D,IAAIE,GACAC,IAAW;CAEf,OAAO;EACL,QAAQ;GACN,GAAQ,MAAM;GAEd,IAAMC,IAAa,IAAI,gBAAgB,GACjCC,IAAkB,EAAEF;GAI1B,OAFA,IAASC,GAEF;IACL,SAAS;KACP,AAAIC,MAAoBF,MAAU,IAAS,KAAA;IAC7C;IAEA,YAAY;KACV,OAAOE,MAAoBF;IAC7B;IAEA,QAAQC,EAAW;GACrB;EACF;EAEA,UAAU;GAGR,AAFAF,GAAQ,MAAM,GACd,IAAS,KAAA,GACT;EACF;CACF;AACF;AAEA,SAAg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AEF,cAAmB,CAAC,CAAC,YAAY,KAAA,CAAS,GAGrCb;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vielzeug/sourcerer",
|
|
3
|
-
"version": "26.11.
|
|
3
|
+
"version": "26.11.6",
|
|
4
4
|
"description": "Reactive collection sources with local, page, cursor, and infinite pagination",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,24 +31,24 @@
|
|
|
31
31
|
"registry": "https://registry.npmjs.org/"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
|
-
"build": "vite build &&
|
|
34
|
+
"build": "vite build && bun run --silent build:bundle && bun run --silent build:types && bun run --silent verify:exports",
|
|
35
35
|
"build:bundle": "vite build --config vite.bundle.config.ts",
|
|
36
36
|
"build:types": "tsc -p tsconfig.declarations.json",
|
|
37
37
|
"fix": "biome check --write src",
|
|
38
38
|
"lint": "biome ci src",
|
|
39
|
-
"prepublishOnly": "
|
|
39
|
+
"prepublishOnly": "bun run --silent build",
|
|
40
40
|
"preview": "vite preview",
|
|
41
41
|
"test": "vitest",
|
|
42
42
|
"test:types": "tsc -p tsconfig.type-tests.json",
|
|
43
|
-
"verify:exports": "
|
|
43
|
+
"verify:exports": "bun verify-exports.mjs"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@vielzeug/arsenal": "26.11.
|
|
46
|
+
"@vielzeug/arsenal": "26.11.6"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@types/node": "^26.6.
|
|
49
|
+
"@types/node": "^26.6.6",
|
|
50
50
|
"typescript": "^6.0.3",
|
|
51
|
-
"vite": "^8.3.
|
|
52
|
-
"vitest": "^5.0
|
|
51
|
+
"vite": "^8.3.6",
|
|
52
|
+
"vitest": "^5.1.0"
|
|
53
53
|
}
|
|
54
54
|
}
|