@vielzeug/sourcerer 26.11.12 → 26.11.13

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.
Files changed (44) hide show
  1. package/dist/asyncSource.cjs +1 -1
  2. package/dist/asyncSource.cjs.map +1 -1
  3. package/dist/asyncSource.d.ts +2 -1
  4. package/dist/asyncSource.d.ts.map +1 -1
  5. package/dist/asyncSource.js +17 -37
  6. package/dist/asyncSource.js.map +1 -1
  7. package/dist/cursorSource.cjs +1 -1
  8. package/dist/cursorSource.cjs.map +1 -1
  9. package/dist/cursorSource.d.ts.map +1 -1
  10. package/dist/cursorSource.js +48 -46
  11. package/dist/cursorSource.js.map +1 -1
  12. package/dist/infiniteSource.cjs +1 -1
  13. package/dist/infiniteSource.cjs.map +1 -1
  14. package/dist/infiniteSource.d.ts.map +1 -1
  15. package/dist/infiniteSource.js +57 -61
  16. package/dist/infiniteSource.js.map +1 -1
  17. package/dist/localSource.cjs +1 -1
  18. package/dist/localSource.cjs.map +1 -1
  19. package/dist/localSource.d.ts.map +1 -1
  20. package/dist/localSource.js +31 -30
  21. package/dist/localSource.js.map +1 -1
  22. package/dist/pageSource.cjs +1 -1
  23. package/dist/pageSource.cjs.map +1 -1
  24. package/dist/pageSource.d.ts.map +1 -1
  25. package/dist/pageSource.js +38 -37
  26. package/dist/pageSource.js.map +1 -1
  27. package/dist/pagination.cjs +1 -1
  28. package/dist/pagination.cjs.map +1 -1
  29. package/dist/pagination.d.ts +2 -0
  30. package/dist/pagination.d.ts.map +1 -1
  31. package/dist/pagination.js +5 -1
  32. package/dist/pagination.js.map +1 -1
  33. package/dist/resourceSource.cjs +1 -1
  34. package/dist/resourceSource.cjs.map +1 -1
  35. package/dist/resourceSource.d.ts.map +1 -1
  36. package/dist/resourceSource.js +12 -15
  37. package/dist/resourceSource.js.map +1 -1
  38. package/dist/sourcerer.cjs +1 -1
  39. package/dist/sourcerer.cjs.map +1 -1
  40. package/dist/sourcerer.iife.js +1 -1
  41. package/dist/sourcerer.iife.js.map +1 -1
  42. package/dist/sourcerer.js +173 -192
  43. package/dist/sourcerer.js.map +1 -1
  44. package/package.json +2 -2
@@ -1,6 +1,6 @@
1
1
  import { createAsyncSource as e } from "./asyncSource.js";
2
2
  import { SourcererDisposedError as t } from "./errors.js";
3
- import { positiveInteger as n, totalItems as r } from "./pagination.js";
3
+ import { positiveInteger as n, sameParams as r, totalItems as i } from "./pagination.js";
4
4
  // src/infiniteSource.ts
5
5
  var createPagination = (e, t, n) => ({
6
6
  hasMore: e < n,
@@ -8,91 +8,87 @@ var createPagination = (e, t, n) => ({
8
8
  pageSize: t,
9
9
  totalItems: n
10
10
  });
11
- function createInfiniteSource(i) {
12
- let a = {
13
- pageSize: n(i.pageSize ?? 20, "pageSize"),
14
- params: i.params
15
- }, o = 1, s = !1, c = e({
11
+ function createInfiniteSource(a) {
12
+ let o = {
13
+ pageSize: n(a.pageSize ?? 20, "pageSize"),
14
+ params: a.params
15
+ }, s = o, c = o, l = 1, u = 1, d = !1, f = e({
16
16
  error: null,
17
17
  items: [],
18
18
  loading: !1,
19
- pagination: createPagination(0, a.pageSize, 0),
20
- params: a.params
19
+ pagination: createPagination(0, s.pageSize, 0),
20
+ params: s.params
21
21
  }), assertLive = () => {
22
- if (c.disposed) throw new t();
23
- }, fetch = (e, t, n) => {
24
- let l = c.state.items;
25
- return c.fetch({
26
- commit: () => {
27
- s = !0, o = t + 1, a = e;
28
- },
29
- failure: (e, t) => ({
30
- ...e,
31
- error: t,
32
- loading: !1,
33
- pendingParams: void 0
34
- }),
35
- load: (n) => i.load({
36
- page: t,
37
- pageSize: e.pageSize,
38
- params: e.params,
39
- signal: n
40
- }),
41
- pending: (t) => ({
42
- ...t,
22
+ if (f.disposed) throw new t();
23
+ }, fetch = (e, t, n) => f.fetch({
24
+ commit: () => {
25
+ d = !0, c = e, u = t + 1, s = e, l = t + 1;
26
+ },
27
+ failure: (e, t) => (s = c, l = u, {
28
+ ...e,
29
+ error: t,
30
+ loading: !1,
31
+ pendingParams: void 0
32
+ }),
33
+ load: (n) => a.load({
34
+ page: t,
35
+ pageSize: e.pageSize,
36
+ params: e.params,
37
+ signal: n
38
+ }),
39
+ pending: (t) => ({
40
+ ...t,
41
+ error: null,
42
+ loading: !0,
43
+ ...n || r(e.params, t.params) ? {} : { pendingParams: e.params }
44
+ }),
45
+ success: (t) => {
46
+ let r = n ? [...f.state.items, ...t.items] : [...t.items];
47
+ return {
43
48
  error: null,
44
- loading: !0,
45
- ...n || Object.is(e.params, t.params) ? {} : { pendingParams: e.params }
46
- }),
47
- success: (t) => {
48
- let i = n ? [...l, ...t.items] : [...t.items];
49
- return {
50
- error: null,
51
- items: i,
52
- loading: !1,
53
- pagination: createPagination(i.length, e.pageSize, r(t.totalItems)),
54
- params: e.params
55
- };
56
- }
57
- });
58
- }, reload = () => fetch(a, 1, !1), l = {
49
+ items: r,
50
+ loading: !1,
51
+ pagination: createPagination(r.length, e.pageSize, i(t.totalItems)),
52
+ params: e.params
53
+ };
54
+ }
55
+ }), reload = () => fetch(s, 1, !1), ensureLoaded = async () => {
56
+ !f.state.loading && !d && await reload();
57
+ }, p = {
59
58
  get disposalSignal() {
60
- return c.disposalSignal;
59
+ return f.disposalSignal;
61
60
  },
62
- dispose: c.dispose,
61
+ dispose: f.dispose,
63
62
  get disposed() {
64
- return c.disposed;
63
+ return f.disposed;
65
64
  },
66
65
  async loadMore() {
67
- assertLive(), c.state.loading || (!s || !Object.is(a.params, c.state.params) ? await reload() : c.state.pagination.hasMore && await fetch(a, o, !0));
66
+ assertLive(), f.state.loading || (d ? f.state.pagination.hasMore && await fetch(s, l, !0) : await reload());
68
67
  },
69
68
  reload,
70
69
  async setPageSize(e) {
71
70
  assertLive();
72
71
  let t = n(e, "pageSize");
73
- if (t === a.pageSize) {
74
- if (c.state.loading || c.state.pagination.pageSize === t) return;
75
- await reload();
76
- } else a = {
77
- ...a,
72
+ t === s.pageSize ? await ensureLoaded() : (s = {
73
+ ...s,
78
74
  pageSize: t
79
- }, o = 1, await reload();
75
+ }, await reload());
80
76
  },
81
77
  async setParams(e) {
82
- assertLive(), Object.is(e, a.params) ? !c.state.loading && !Object.is(e, c.state.params) && await reload() : (a = {
83
- ...a,
78
+ assertLive(), r(e, s.params) ? await ensureLoaded() : (s = {
79
+ ...s,
84
80
  params: e
85
- }, o = 1, await reload());
81
+ }, await reload());
86
82
  },
87
83
  get state() {
88
- return c.state;
84
+ return f.state;
89
85
  },
90
- subscribe: c.subscribe,
86
+ subscribe: f.subscribe,
91
87
  [Symbol.dispose]() {
92
- l.dispose();
88
+ p.dispose();
93
89
  }
94
90
  };
95
- return l;
91
+ return p;
96
92
  }
97
93
  export { createInfiniteSource };
98
94
 
@@ -1 +1 @@
1
- {"version":3,"file":"infiniteSource.js","names":["loadedItems","total","requested","positiveInteger","config","nextPage","hasLoaded","asyncSource","createAsyncSource","SourcererDisposedError","page","request","previous","append","items","result","totalItems","source","normalized","pageSize","params"],"sources":["../src/infiniteSource.ts"],"sourcesContent":["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 },\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AC;CACH,GAEM,eAA8B,MAAMT,GAAW,GAAG,EAAK,GAEvDe,IAAqC;EACzC,IAAI,iBAAiB;GACnB,OAAOV,EAAY;EACrB;EAEA,SAASA,EAAY;EAErB,IAAI,WAAW;GACb,OAAOA,EAAY;EACrB;EAEA,MAAM,WAAW;GAEf,AADA,WAAW,GACPA,EAAY,MAAM,YAClB,CAACD,KAAa,CAAC,OAAO,GAAGJ,EAAU,QAAQK,EAAY,MAAM,MAAM,IACrE,MAAM,OAAO,IAGXA,EAAY,MAAM,WAAW,WAAS,MAAM,MAAML,GAAWG,GAAU,EAAI;EACjF;EAEA;EAEA,MAAM,YAAY,GAAU;GAC1B,WAAW;GACX,IAAMa,IAAaf,EAAgBgB,GAAU,UAAU;GACvD,IAAID,MAAehB,EAAU,UAAU;IACrC,IAAIK,EAAY,MAAM,WAAWA,EAAY,MAAM,WAAW,aAAaW,GAAY;IACvF,MAAM,OAAO;GAEf,OAGA,AAFA,IAAY;IAAE,GAAGhB;IAAW,UAAUgB;GAAW,GACjD,IAAW,GACX,MAAM,OAAO;EACf;EAEA,MAAM,UAAU,GAAQ;GAEtB,AADA,WAAW,GACP,OAAO,GAAGE,GAAQlB,EAAU,MAAM,IAChC,CAACK,EAAY,MAAM,WAAW,CAAC,OAAO,GAAGa,GAAQb,EAAY,MAAM,MAAM,KAAG,MAAM,OAAO,KAG/F,IAAY;IAAE,GAAGL;IAAW;GAAO,GACnC,IAAW,GACX,MAAM,OAAO;EACf;EAEA,IAAI,QAAQ;GACV,OAAOK,EAAY;EACrB;EAEA,WAAWA,EAAY;EAEvB,CAAC,OAAO,WAAW;GACjB,EAAO,QAAQ;EACjB;CACF;CAEA,OAAOU;AACT"}
1
+ {"version":3,"file":"infiniteSource.js","names":["loadedItems","total","initial","positiveInteger","config","requested","committed","nextPage","committedNextPage","hasLoaded","asyncSource","createAsyncSource","SourcererDisposedError","request","page","previous","append","sameParams","items","result","totalItems","source","normalized","pageSize","params"],"sources":["../src/infiniteSource.ts"],"sourcesContent":["import { createAsyncSource } from './asyncSource';\nimport { SourcererDisposedError } from './errors';\nimport { positiveInteger, sameParams, 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 const initial: Request<TParams> = {\n pageSize: positiveInteger(config.pageSize ?? 20, 'pageSize'),\n params: config.params as TParams,\n };\n let requested: Request<TParams> = initial;\n let committed: Request<TParams> = initial;\n let nextPage = 1;\n let committedNextPage = 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 asyncSource.fetch({\n commit: () => {\n hasLoaded = true;\n committed = request;\n committedNextPage = page + 1;\n requested = request;\n nextPage = page + 1;\n },\n // Only the current request reaches `failure` (superseded work settles silently),\n // so the desired request rolls back to what the published feed still shows.\n failure: (previous, error) => {\n requested = committed;\n nextPage = committedNextPage;\n return { ...previous, error, loading: false, pendingParams: undefined };\n },\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 || sameParams(request.params, previous.params) ? {} : { pendingParams: request.params }),\n }),\n success: (result) => {\n const items = append ? [...asyncSource.state.items, ...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 const reload = (): Promise<void> => fetch(requested, 1, false);\n\n const ensureLoaded = async (): Promise<void> => {\n // While idle, `requested` always matches the committed feed, so the only\n // missing work is the first load (which a failure rolls back to).\n if (!asyncSource.state.loading && !hasLoaded) await reload();\n };\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) {\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 await ensureLoaded();\n return;\n }\n requested = { ...requested, pageSize: normalized };\n await reload();\n },\n\n async setParams(params) {\n assertLive();\n if (sameParams(params, requested.params)) {\n await ensureLoaded();\n return;\n }\n requested = { ...requested, params };\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"],"mappings":";;;;AAOA,IAAM,oBAAoB,GAAqB,GAAkB,OAAuC;CACtG,SAASA,IAAcC;CACvB;CACA;CACA,YAAYA;AACd;AAGA,SAAgB,qBACd,GAC4B;CAC5B,IAAMC,IAA4B;EAChC,UAAUC,EAAgBC,EAAO,YAAY,IAAI,UAAU;EAC3D,QAAQA,EAAO;CACjB,GACIC,IAA8BH,GAC9BI,IAA8BJ,GAC9BK,IAAW,GACXC,IAAoB,GACpBC,IAAY,IACVC,IAAcC,EAAmD;EACrE,OAAO;EACP,OAAO,CAAC;EACR,SAAS;EACT,YAAY,iBAAiB,GAAGN,EAAU,UAAU,CAAC;EACrD,QAAQA,EAAU;CACpB,CAAC,GACK,mBAAyB;EAC7B,IAAIK,EAAY,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,MAAM,YAAY,GAAU;GAC1B,WAAW;GACX,IAAMe,IAAanB,EAAgBoB,GAAU,UAAU;GACvD,AAAID,MAAejB,EAAU,WAC3B,MAAM,aAAa,KAGrB,IAAY;IAAE,GAAGA;IAAW,UAAUiB;GAAW,GACjD,MAAM,OAAO;EACf;EAEA,MAAM,UAAU,GAAQ;GAEtB,AADA,WAAW,GACPL,EAAWO,GAAQnB,EAAU,MAAM,IACrC,MAAM,aAAa,KAGrB,IAAY;IAAE,GAAGA;IAAW;GAAO,GACnC,MAAM,OAAO;EACf;EAEA,IAAI,QAAQ;GACV,OAAOK,EAAY;EACrB;EAEA,WAAWA,EAAY;EAEvB,CAAC,OAAO,WAAW;GACjB,EAAO,QAAQ;EACjB;CACF;CAEA,OAAOW;AACT"}
@@ -1,2 +1,2 @@
1
- const e=require("./errors.cjs"),t=require("./pagination.cjs"),n=require("./sourceStore.cjs");function createLocalSource(r,i={}){let a=r,o=1,s=t.positiveInteger(i.pageSize??20,`pageSize`),c=i.params,buildState=()=>{let e=i.filter?a.filter(e=>i.filter?.(e,c)):a,n=t.createPagePagination(o,s,e.length);if(o>n.pageCount)return o=n.pageCount,buildState();let r=(o-1)*s;return{error:null,items:e.slice(r,r+s),loading:!1,pagination:n,params:c}},l=n.createSourceStore(buildState()),assertLive=()=>{if(l.disposed)throw new e.SourcererDisposedError},samePagination=(e,t)=>Object.keys(e).every(n=>e[n]===t[n]),commit=()=>{let e=buildState(),t=l.value,n=e.items.length===t.items.length&&e.items.every((e,n)=>Object.is(e,t.items[n]));Object.is(e.params,t.params)&&n&&samePagination(e.pagination,t.pagination)||l.set(e)},goTo=e=>{assertLive();let n=Math.min(t.positiveInteger(e,`page`),l.value.pagination.pageCount);n!==o&&(o=n,commit())},u={get disposalSignal(){return l.disposalSignal},dispose:l.dispose,get disposed(){return l.disposed},first(){goTo(1)},goTo,last(){goTo(l.value.pagination.pageCount)},next(){l.value.pagination.hasNext?goTo(o+1):assertLive()},previous(){l.value.pagination.hasPrevious?goTo(o-1):assertLive()},setItems(e){assertLive(),e!==a&&(a=e,commit())},setPageSize(e){assertLive();let n=t.positiveInteger(e,`pageSize`);n!==s&&(o=1,s=n,commit())},setParams(e){assertLive(),Object.is(e,c)||(o=1,c=e,commit())},get state(){return l.value},subscribe:l.subscribe,[Symbol.dispose](){u.dispose()}};return u}exports.createLocalSource=createLocalSource;
1
+ const e=require("./errors.cjs"),t=require("./pagination.cjs"),n=require("./sourceStore.cjs");let r=require("@vielzeug/arsenal");function createLocalSource(i,a={}){let o=i,s=1,c=t.positiveInteger(a.pageSize??20,`pageSize`),l=a.params,buildState=()=>{let e=a.filter?o.filter(e=>a.filter?.(e,l)):o,n=t.createPagePagination(s,c,e.length);if(s>n.pageCount)return s=n.pageCount,buildState();let r=(s-1)*c;return{error:null,items:e.slice(r,r+c),loading:!1,pagination:n,params:l}},u=n.createSourceStore(buildState()),assertLive=()=>{if(u.disposed)throw new e.SourcererDisposedError},commit=()=>{let e=buildState();(0,r.isEqual)(e,u.value)||u.set(e)},goTo=e=>{assertLive();let n=Math.min(t.positiveInteger(e,`page`),u.value.pagination.pageCount);n!==s&&(s=n,commit())},d={get disposalSignal(){return u.disposalSignal},dispose:u.dispose,get disposed(){return u.disposed},first(){goTo(1)},goTo,last(){goTo(u.value.pagination.pageCount)},next(){u.value.pagination.hasNext?goTo(s+1):assertLive()},previous(){u.value.pagination.hasPrevious?goTo(s-1):assertLive()},setItems(e){assertLive(),e!==o&&(o=e,commit())},setPageSize(e){assertLive();let n=t.positiveInteger(e,`pageSize`);n!==c&&(s=1,c=n,commit())},setParams(e){assertLive(),t.sameParams(e,l)||(s=1,l=e,commit())},get state(){return u.value},subscribe:u.subscribe,[Symbol.dispose](){d.dispose()}};return d}exports.createLocalSource=createLocalSource;
2
2
  //# sourceMappingURL=localSource.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"localSource.cjs","names":["positiveInteger","createPagePagination","createSourceStore","SourcererDisposedError","require_errors","require_pagination","require_sourceStore","allItems","items","page","pageSize","config","params","filtered","item","pagination","start","store","left","key","right","next","current","sameItems","index","normalized","nextPage","source","nextItems","nextPageSize","nextParams"],"sources":["../src/localSource.ts"],"sourcesContent":["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"],"mappings":"A,6FAWA,SAAgB,kBACd,EACA,EAAwC,CAAC,EAChB,CACzB,IAAIO,EAAWC,EACXC,EAAO,EACPC,EAAWV,EAAAA,gBAAgBW,EAAO,UAAY,GAAI,UAAU,EAC5DC,EAASD,EAAO,OAEd,eAAiD,CACrD,IAAME,EAAWF,EAAO,OAASJ,EAAS,OAAQ,GAASI,EAAO,SAASG,EAAMF,CAAM,CAAC,EAAIL,EACtFQ,EAAad,EAAAA,qBAAqBQ,EAAMC,EAAUG,EAAS,MAAM,EACvE,GAAIJ,EAAOM,EAAW,UAEpB,MADA,GAAOA,EAAW,UACX,WAAW,EAEpB,IAAMC,GAASP,EAAO,GAAKC,EAE3B,MAAO,CACL,MAAO,KACP,MAAOG,EAAS,MAAMG,EAAOA,EAAQN,CAAQ,EAC7C,QAAS,GACT,aACA,QACF,CACF,EAEMO,EAAQf,EAAAA,kBAAkB,WAAW,CAAC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EACT,EAEA,UAAU,EAAY,CACpB,WAAW,EACP,OAAO,GAAGK,EAAYlB,CAAM,IAChC,EAAO,EACP,EAASkB,EACT,OAAO,EACT,EAEA,IAAI,OAAQ,CACV,OAAOb,EAAM,KACf,EAEA,UAAWA,EAAM,UAEjB,CAAC,OAAO,UAAW,CACjBU,EAAO,QAAQ,CACjB,CACF,EAEA,OAAOA,CACT,C"}
1
+ {"version":3,"file":"localSource.cjs","names":["positiveInteger","createPagePagination","createSourceStore","SourcererDisposedError","isEqual","sameParams","require_errors","require_pagination","require_sourceStore","_vielzeug_arsenal","allItems","items","page","pageSize","config","params","filtered","item","pagination","start","store","next","normalized","nextPage","source","nextItems","nextPageSize","nextParams"],"sources":["../src/localSource.ts"],"sourcesContent":["import { isEqual } from '@vielzeug/arsenal';\n\nimport { SourcererDisposedError } from './errors';\nimport { createPagePagination, positiveInteger, sameParams } from './pagination';\nimport { createSourceStore } from './sourceStore';\nimport type { LocalSource, LocalSourceConfig, LocalSourceState } 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 commit = (): void => {\n const next = buildState();\n if (isEqual(next, store.value)) 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 (sameParams(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"],"mappings":"A,gIAaA,SAAgB,kBACd,EACA,EAAwC,CAAC,EAChB,CACzB,IAAIU,EAAWC,EACXC,EAAO,EACPC,EAAWb,EAAAA,gBAAgBc,EAAO,UAAY,GAAI,UAAU,EAC5DC,EAASD,EAAO,OAEd,eAAiD,CACrD,IAAME,EAAWF,EAAO,OAASJ,EAAS,OAAQ,GAASI,EAAO,SAASG,EAAMF,CAAM,CAAC,EAAIL,EACtFQ,EAAajB,EAAAA,qBAAqBW,EAAMC,EAAUG,EAAS,MAAM,EACvE,GAAIJ,EAAOM,EAAW,UAEpB,MADA,GAAOA,EAAW,UACX,WA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,EACT,EAEA,IAAI,OAAQ,CACV,OAAOP,EAAM,KACf,EAEA,UAAWA,EAAM,UAEjB,CAAC,OAAO,UAAW,CACjBI,EAAO,QAAQ,CACjB,CACF,EAEA,OAAOA,CACT,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"localSource.d.ts","sourceRoot":"","sources":["../src/localSource.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAoC,MAAM,SAAS,CAAC;AAEhG,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAC1E,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS,EACtD,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,MAAM,EAAE,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,GACpC,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"localSource.d.ts","sourceRoot":"","sources":["../src/localSource.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAoB,MAAM,SAAS,CAAC;AAEhF,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAC1E,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS,EACtD,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,MAAM,EAAE,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,GACpC,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC"}
@@ -1,69 +1,70 @@
1
1
  import { SourcererDisposedError as e } from "./errors.js";
2
- import { createPagePagination as t, positiveInteger as n } from "./pagination.js";
3
- import { createSourceStore as r } from "./sourceStore.js";
2
+ import { createPagePagination as t, positiveInteger as n, sameParams as r } from "./pagination.js";
3
+ import { createSourceStore as i } from "./sourceStore.js";
4
+ import { isEqual as a } from "@vielzeug/arsenal";
4
5
  // src/localSource.ts
5
- function createLocalSource(i, a = {}) {
6
- let o = i, s = 1, c = n(a.pageSize ?? 20, "pageSize"), l = a.params, buildState = () => {
7
- let e = a.filter ? o.filter((e) => a.filter?.(e, l)) : o, n = t(s, c, e.length);
8
- if (s > n.pageCount) return s = n.pageCount, buildState();
9
- let r = (s - 1) * c;
6
+ function createLocalSource(o, s = {}) {
7
+ let c = o, l = 1, u = n(s.pageSize ?? 20, "pageSize"), d = s.params, buildState = () => {
8
+ let e = s.filter ? c.filter((e) => s.filter?.(e, d)) : c, n = t(l, u, e.length);
9
+ if (l > n.pageCount) return l = n.pageCount, buildState();
10
+ let r = (l - 1) * u;
10
11
  return {
11
12
  error: null,
12
- items: e.slice(r, r + c),
13
+ items: e.slice(r, r + u),
13
14
  loading: !1,
14
15
  pagination: n,
15
- params: l
16
+ params: d
16
17
  };
17
- }, u = r(buildState()), assertLive = () => {
18
- if (u.disposed) throw new e();
19
- }, samePagination = (e, t) => Object.keys(e).every((n) => e[n] === t[n]), commit = () => {
20
- let e = buildState(), t = u.value, n = e.items.length === t.items.length && e.items.every((e, n) => Object.is(e, t.items[n]));
21
- Object.is(e.params, t.params) && n && samePagination(e.pagination, t.pagination) || u.set(e);
18
+ }, f = i(buildState()), assertLive = () => {
19
+ if (f.disposed) throw new e();
20
+ }, commit = () => {
21
+ let e = buildState();
22
+ a(e, f.value) || f.set(e);
22
23
  }, goTo = (e) => {
23
24
  assertLive();
24
- let t = Math.min(n(e, "page"), u.value.pagination.pageCount);
25
- t !== s && (s = t, commit());
26
- }, d = {
25
+ let t = Math.min(n(e, "page"), f.value.pagination.pageCount);
26
+ t !== l && (l = t, commit());
27
+ }, p = {
27
28
  get disposalSignal() {
28
- return u.disposalSignal;
29
+ return f.disposalSignal;
29
30
  },
30
- dispose: u.dispose,
31
+ dispose: f.dispose,
31
32
  get disposed() {
32
- return u.disposed;
33
+ return f.disposed;
33
34
  },
34
35
  first() {
35
36
  goTo(1);
36
37
  },
37
38
  goTo,
38
39
  last() {
39
- goTo(u.value.pagination.pageCount);
40
+ goTo(f.value.pagination.pageCount);
40
41
  },
41
42
  next() {
42
- u.value.pagination.hasNext ? goTo(s + 1) : assertLive();
43
+ f.value.pagination.hasNext ? goTo(l + 1) : assertLive();
43
44
  },
44
45
  previous() {
45
- u.value.pagination.hasPrevious ? goTo(s - 1) : assertLive();
46
+ f.value.pagination.hasPrevious ? goTo(l - 1) : assertLive();
46
47
  },
47
48
  setItems(e) {
48
- assertLive(), e !== o && (o = e, commit());
49
+ assertLive(), e !== c && (c = e, commit());
49
50
  },
50
51
  setPageSize(e) {
51
52
  assertLive();
52
53
  let t = n(e, "pageSize");
53
- t !== c && (s = 1, c = t, commit());
54
+ t !== u && (l = 1, u = t, commit());
54
55
  },
55
56
  setParams(e) {
56
- assertLive(), Object.is(e, l) || (s = 1, l = e, commit());
57
+ assertLive(), r(e, d) || (l = 1, d = e, commit());
57
58
  },
58
59
  get state() {
59
- return u.value;
60
+ return f.value;
60
61
  },
61
- subscribe: u.subscribe,
62
+ subscribe: f.subscribe,
62
63
  [Symbol.dispose]() {
63
- d.dispose();
64
+ p.dispose();
64
65
  }
65
66
  };
66
- return d;
67
+ return p;
67
68
  }
68
69
  export { createLocalSource };
69
70
 
@@ -1 +1 @@
1
- {"version":3,"file":"localSource.js","names":["allItems","items","page","pageSize","positiveInteger","config","params","filtered","item","pagination","createPagePagination","start","store","createSourceStore","SourcererDisposedError","left","key","right","next","current","sameItems","index","normalized","nextPage","source","nextItems","nextPageSize","nextParams"],"sources":["../src/localSource.ts"],"sourcesContent":["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"],"mappings":";;;;AAWA,SAAgB,kBACd,GACA,IAAwC,CAAC,GAChB;CACzB,IAAIA,IAAWC,GACXC,IAAO,GACPC,IAAWC,EAAgBC,EAAO,YAAY,IAAI,UAAU,GAC5DC,IAASD,EAAO,QAEd,mBAAiD;EACrD,IAAME,IAAWF,EAAO,SAASL,EAAS,QAAQ,MAASK,EAAO,SAASG,GAAMF,CAAM,CAAC,IAAIN,GACtFS,IAAaC,EAAqBR,GAAMC,GAAUI,EAAS,MAAM;EACvE,IAAIL,IAAOO,EAAW,WAEpB,OADA,IAAOA,EAAW,WACX,WAAW;EAEpB,IAAME,KAAST,IAAO,KAAKC;EAE3B,OAAO;GACL,OAAO;GACP,OAAOI,EAAS,MAAMI,GAAOA,IAAQR,CAAQ;GAC7C,SAAS;GACT;GACA;EACF;CACF,GAEMS,IAAQC,EAAkB,WAAW,CAAC,GACtC,mBAAyB;EAC7B,IAAID,EAAM,UAAU,MAAM,IAAIE,EAAuB;CACvD,GACM,kBAAkB,GAAsB,MAC5C,OAAO,KAAKC,CAAI,CAAC,CAAC,OAAO,MAAQA,EAAKC,OAAiCC,EAAMD,EAA4B,GACrG,eAAqB;EACzB,IAAME,IAAO,WAAW,GAClBC,IAAUP,EAAM,OAChBQ,IACJF,EAAK,MAAM,WAAWC,EAAQ,MAAM,UACpCD,EAAK,MAAM,OAAO,GAAM,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","page","pageSize","positiveInteger","config","params","filtered","item","pagination","createPagePagination","start","store","createSourceStore","SourcererDisposedError","next","isEqual","normalized","nextPage","source","nextItems","nextPageSize","sameParams","nextParams"],"sources":["../src/localSource.ts"],"sourcesContent":["import { isEqual } from '@vielzeug/arsenal';\n\nimport { SourcererDisposedError } from './errors';\nimport { createPagePagination, positiveInteger, sameParams } from './pagination';\nimport { createSourceStore } from './sourceStore';\nimport type { LocalSource, LocalSourceConfig, LocalSourceState } 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 commit = (): void => {\n const next = buildState();\n if (isEqual(next, store.value)) 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 (sameParams(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"],"mappings":";;;;;AAaA,SAAgB,kBACd,GACA,IAAwC,CAAC,GAChB;CACzB,IAAIA,IAAWC,GACXC,IAAO,GACPC,IAAWC,EAAgBC,EAAO,YAAY,IAAI,UAAU,GAC5DC,IAASD,EAAO,QAEd,mBAAiD;EACrD,IAAME,IAAWF,EAAO,SAASL,EAAS,QAAQ,MAASK,EAAO,SAASG,GAAMF,CAAM,CAAC,IAAIN,GACtFS,IAAaC,EAAqBR,GAAMC,GAAUI,EAAS,MAAM;EACvE,IAAIL,IAAOO,EAAW,WAEpB,OADA,IAAOA,EAAW,WACX,WAAW;EAEpB,IAAME,KAAST,IAAO,KAAKC;EAE3B,OAAO;GACL,OAAO;GACP,OAAOI,EAAS,MAAMI,GAAOA,IAAQR,CAAQ;GAC7C,SAAS;GACT;GACA;EACF;CACF,GAEMS,IAAQC,EAAkB,WAAW,CAAC,GACtC,mBAAyB;EAC7B,IAAID,EAAM,UAAU,MAAM,IAAIE,EAAuB;CACvD,GACM,eAAqB;EACzB,IAAMC,IAAO,WAAW;EACxB,AAAIC,EAAQD,GAAMH,EAAM,KAAK,KAC7BA,EAAM,IAAIG,CAAI;CAChB,GACM,QAAQ,MAA2B;EACvC,WAAW;EACX,IAAME,IAAa,KAAK,IAAIb,EAAgBc,GAAU,MAAM,GAAGN,EAAM,MAAM,WAAW,SAAS;EAC/F,AAAIK,MAAef,MACnB,IAAOe,GACP,OAAO;CACT,GAEME,IAAkC;EACtC,IAAI,iBAAiB;GACnB,OAAOP,EAAM;EACf;EAEA,SAASA,EAAM;EAEf,IAAI,WAAW;GACb,OAAOA,EAAM;EACf;EAEA,QAAQ;GACN,KAAK,CAAC;EACR;EAEA;EAEA,OAAO;GACL,KAAKA,EAAM,MAAM,WAAW,SAAS;EACvC;EAEA,OAAO;GACL,AAAIA,EAAM,MAAM,WAAW,UAAS,KAAKV,IAAO,CAAC,IAC5C,WAAW;EAClB;EAEA,WAAW;GACT,AAAIU,EAAM,MAAM,WAAW,cAAa,KAAKV,IAAO,CAAC,IAChD,WAAW;EAClB;EAEA,SAAS,GAAW;GAElB,AADA,WAAW,GACPkB,MAAcpB,MAClB,IAAWoB,GACX,OAAO;EACT;EAEA,YAAY,GAAc;GACxB,WAAW;GACX,IAAMH,IAAab,EAAgBiB,GAAc,UAAU;GAC3D,AAAIJ,MAAed,MACnB,IAAO,GACP,IAAWc,GACX,OAAO;EACT;EAEA,UAAU,GAAY;GAEpB,AADA,WAAW,GACPK,EAAWC,GAAYjB,CAAM,MACjC,IAAO,GACP,IAASiB,GACT,OAAO;EACT;EAEA,IAAI,QAAQ;GACV,OAAOX,EAAM;EACf;EAEA,WAAWA,EAAM;EAEjB,CAAC,OAAO,WAAW;GACjB,EAAO,QAAQ;EACjB;CACF;CAEA,OAAOO;AACT"}
@@ -1,2 +1,2 @@
1
- const e=require("./asyncSource.cjs"),t=require("./errors.cjs"),n=require("./pagination.cjs");let r=require("@vielzeug/arsenal");function createPageSource(i){let a={page:1,pageSize:n.positiveInteger(i.pageSize??20,`pageSize`),params:i.params},o=!1,s=e.createAsyncSource({error:null,items:[],loading:!1,pagination:n.createPagePagination(a.page,a.pageSize,0),params:a.params}),assertLive=()=>{if(s.disposed)throw new t.SourcererDisposedError},isCommitted=e=>s.state.pagination.page===e.page&&s.state.pagination.pageSize===e.pageSize&&Object.is(s.state.params,e.params),fetch=e=>s.fetch({commit:()=>{o=!0,a=e},failure:(e,t)=>({...e,error:t,loading:!1,pendingParams:void 0}),load:t=>i.load({...e,signal:t}),pending:t=>({...t,error:null,loading:!0,...Object.is(e.params,t.params)?{}:{pendingParams:e.params}}),success:t=>({error:null,items:[...t.items],loading:!1,pagination:n.createPagePagination(e.page,e.pageSize,n.totalItems(t.totalItems)),params:e.params})}),normalizePage=e=>o?Math.min(n.positiveInteger(e,`page`),s.state.pagination.pageCount):n.positiveInteger(e,`page`),goTo=async e=>{assertLive();let t=normalizePage(e);t===a.page?s.state.loading||o&&isCommitted(a)||await fetch(a):(a={...a,page:t},await fetch(a))},c={async apply(e){assertLive();let t=e.params===void 0?a.params:e.params;(0,r.isEqual)(t,a.params)?e.page===void 0?s.state.loading||o&&isCommitted(a)||await fetch(a):await goTo(e.page):(a={...a,page:e.page===void 0?1:n.positiveInteger(e.page,`page`),params:t},await fetch(a))},get disposalSignal(){return s.disposalSignal},dispose:s.dispose,get disposed(){return s.disposed},first(){return goTo(1)},goTo,last(){return goTo(s.state.pagination.pageCount)},async next(){assertLive(),(!o||a.page<s.state.pagination.pageCount)&&await goTo(a.page+1)},async previous(){assertLive(),a.page>1&&await goTo(a.page-1)},reload(){return fetch(a)},async setPageSize(e){assertLive();let t=n.positiveInteger(e,`pageSize`);t===a.pageSize&&a.page===1?!s.state.loading&&!isCommitted(a)&&await fetch(a):(a={...a,page:1,pageSize:t},await fetch(a))},async setParams(e){assertLive(),Object.is(e,a.params)?!s.state.loading&&!isCommitted(a)&&await fetch(a):(a={...a,page:1,params:e},await fetch(a))},get state(){return s.state},subscribe:s.subscribe,[Symbol.dispose](){c.dispose()}};return c}exports.createPageSource=createPageSource;
1
+ const e=require("./asyncSource.cjs"),t=require("./errors.cjs"),n=require("./pagination.cjs");function createPageSource(r){let i={page:1,pageSize:n.positiveInteger(r.pageSize??20,`pageSize`),params:r.params},a=i,o=i,s=!1,c=e.createAsyncSource({error:null,items:[],loading:!1,pagination:n.createPagePagination(a.page,a.pageSize,0),params:a.params}),assertLive=()=>{if(c.disposed)throw new t.SourcererDisposedError},ensureLoaded=async()=>{!c.state.loading&&!s&&await fetch(a)},fetch=e=>c.fetch({commit:()=>{s=!0,o=e,a=e},failure:(e,t)=>(a=o,{...e,error:t,loading:!1,pendingParams:void 0}),load:t=>r.load({...e,signal:t}),pending:t=>({...t,error:null,loading:!0,...n.sameParams(e.params,t.params)?{}:{pendingParams:e.params}}),success:t=>({error:null,items:[...t.items],loading:!1,pagination:n.createPagePagination(e.page,e.pageSize,n.totalItems(t.totalItems)),params:e.params})}),normalizePage=e=>s?Math.min(n.positiveInteger(e,`page`),c.state.pagination.pageCount):n.positiveInteger(e,`page`),goTo=async e=>{assertLive();let t=normalizePage(e);t===a.page?await ensureLoaded():(a={...a,page:t},await fetch(a))},l={async apply(e){assertLive();let t=e.params===void 0?a.params:e.params;n.sameParams(t,a.params)?e.page===void 0?await ensureLoaded():await goTo(e.page):(a={...a,page:e.page===void 0?1:n.positiveInteger(e.page,`page`),params:t},await fetch(a))},get disposalSignal(){return c.disposalSignal},dispose:c.dispose,get disposed(){return c.disposed},first(){return goTo(1)},goTo,last(){return goTo(c.state.pagination.pageCount)},async next(){assertLive(),s?a.page<c.state.pagination.pageCount&&await goTo(a.page+1):await goTo(1)},async previous(){assertLive(),a.page>1&&await goTo(a.page-1)},reload(){return fetch(a)},async setPageSize(e){assertLive();let t=n.positiveInteger(e,`pageSize`);t===a.pageSize&&a.page===1?await ensureLoaded():(a={...a,page:1,pageSize:t},await fetch(a))},async setParams(e){assertLive(),n.sameParams(e,a.params)?await ensureLoaded():(a={...a,page:1,params:e},await fetch(a))},get state(){return c.state},subscribe:c.subscribe,[Symbol.dispose](){l.dispose()}};return l}exports.createPageSource=createPageSource;
2
2
  //# sourceMappingURL=pageSource.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"pageSource.cjs","names":["positiveInteger","createAsyncSource","createPagePagination","SourcererDisposedError","totalItems","isEqual","require_asyncSource","require_errors","require_pagination","_vielzeug_arsenal","requested","config","hasLoaded","asyncSource","request","previous","result","page","normalized","source","params","update","pageSize"],"sources":["../src/pageSource.ts"],"sourcesContent":["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"],"mappings":"A,gIAUA,SAAgB,iBAAyC,EAA8D,CACrH,IAAIU,EAA8B,CAChC,KAAM,EACN,SAAUV,EAAAA,gBAAgBW,EAAO,UAAY,GAAI,UAAU,EAC3D,OAAQA,EAAO,MACjB,EACIC,EAAY,GACVC,EAAcZ,EAAAA,kBAA+C,CACjE,MAAO,KACP,MAAO,CAAC,EACR,QAAS,GACT,WAAYC,EAAAA,qBAAqBQ,EAAU,KAAMA,EAAU,SAAU,CAAC,EACtE,OAAQA,EAAU,MACpB,CAAC,EACK,eAAyB,CAC7B,GAAIG,EAAY,SAAU,MAAM,IAAIV,EAAAA,sBACtC,EACM,YAAe,GACnBU,EAAY,MAAM,WAAW,OAASC,EAAQ,MAC9CD,EAAY,MAAM,WAAW,WAAaC,EAAQ,UAClD,OAAO,GAAGD,EAAY,MAAM,OAAQC,EAAQ,MAAM,EAE9C,MAAS,GACbD,EAAY,MAAM,CAChB,WAAc,CACZ,EAAY,GACZ,EAAYC,CACd,EACA,SAAU,EAAU,KAAW,CAAE,GAAGC,EAAU,QAAO,QAAS,GAAO,cAAe,IAAA,EAAU,GAC9F,KAAO,GAAWJ,EAAO,KAAK,CAAE,GAAGG,EAAS,QAAO,CAAC,EACpD,QAAU,IAAc,CACtB,GAAGC,EACH,MAAO,KACP,QAAS,GACT,GAAI,OAAO,GAAGD,EAAQ,OAAQC,EAAS,MAAM,EAAI,CAAC,EAAI,CAAE,cAAeD,EAAQ,MAAO,CACxF,GACA,QAAU,IAAY,CACpB,MAAO,KACP,MAAO,CAAC,GAAGE,EAAO,KAAK,EACvB,QAAS,GACT,WAAYd,EAAAA,qBAAqB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AM,KAAKH,EAAU,KAAO,CAAC,CAC1G,EAEA,MAAM,UAAW,CACf,WAAW,EACPA,EAAU,KAAO,GAAG,MAAM,KAAKA,EAAU,KAAO,CAAC,CACvD,EAEA,QAAS,CACP,OAAO,MAAMA,CAAS,CACxB,EAEA,MAAM,YAAY,EAAU,CAC1B,WAAW,EACX,IAAMQ,EAAalB,EAAAA,gBAAgBsB,EAAU,UAAU,EACnDJ,IAAeR,EAAU,UAAYA,EAAU,OAAS,EACtD,CAACG,EAAY,MAAM,SAAW,CAAC,YAAYH,CAAS,GAAG,MAAM,MAAMA,CAAS,GAGlF,EAAY,CAAE,GAAGA,EAAW,KAAM,EAAG,SAAUQ,CAAW,EAC1D,MAAM,MAAMR,CAAS,EACvB,EAEA,MAAM,UAAU,EAAQ,CACtB,WAAW,EACP,OAAO,GAAGU,EAAQV,EAAU,MAAM,EAChC,CAACG,EAAY,MAAM,SAAW,CAAC,YAAYH,CAAS,GAAG,MAAM,MAAMA,CAAS,GAGlF,EAAY,CAAE,GAAGA,EAAW,KAAM,EAAG,QAAO,EAC5C,MAAM,MAAMA,CAAS,EACvB,EAEA,IAAI,OAAQ,CACV,OAAOG,EAAY,KACrB,EAEA,UAAWA,EAAY,UAEvB,CAAC,OAAO,UAAW,CACjBM,EAAO,QAAQ,CACjB,CACF,EAEA,OAAOA,CACT,C"}
1
+ {"version":3,"file":"pageSource.cjs","names":["positiveInteger","createAsyncSource","createPagePagination","SourcererDisposedError","sameParams","totalItems","require_asyncSource","require_errors","require_pagination","initial","config","requested","committed","hasLoaded","asyncSource","request","previous","result","page","normalized","source","params","update","pageSize"],"sources":["../src/pageSource.ts"],"sourcesContent":["import { createAsyncSource } from './asyncSource';\nimport { SourcererDisposedError } from './errors';\nimport { createPagePagination, positiveInteger, sameParams, 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 const initial: Request<TParams> = {\n page: 1,\n pageSize: positiveInteger(config.pageSize ?? 20, 'pageSize'),\n params: config.params as TParams,\n };\n let requested: Request<TParams> = initial;\n let committed: Request<TParams> = initial;\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 ensureLoaded = async (): Promise<void> => {\n // While idle, `requested` always matches the committed request, so the only\n // missing work is the first load (which a failure rolls back to).\n if (!asyncSource.state.loading && !hasLoaded) await fetch(requested);\n };\n\n const fetch = (request: Request<TParams>): Promise<void> =>\n asyncSource.fetch({\n commit: () => {\n hasLoaded = true;\n committed = request;\n requested = request;\n },\n // Only the current request reaches `failure` (superseded work settles silently),\n // so the desired request rolls back to what the published state still shows.\n failure: (previous, error) => {\n requested = committed;\n return { ...previous, error, loading: false, pendingParams: undefined };\n },\n load: (signal) => config.load({ ...request, signal }),\n pending: (previous) => ({\n ...previous,\n error: null,\n loading: true,\n ...(sameParams(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 await ensureLoaded();\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 (!sameParams(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 await ensureLoaded();\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) await goTo(1);\n else if (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 await ensureLoaded();\n return;\n }\n requested = { ...requested, page: 1, pageSize: normalized };\n await fetch(requested);\n },\n\n async setParams(params) {\n assertLive();\n if (sameParams(params, requested.params)) {\n await ensureLoaded();\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"],"mappings":"A,6FAQA,SAAgB,iBAAyC,EAA8D,CACrH,IAAMS,EAA4B,CAChC,KAAM,EACN,SAAUT,EAAAA,gBAAgBU,EAAO,UAAY,GAAI,UAAU,EAC3D,OAAQA,EAAO,MACjB,EACIC,EAA8BF,EAC9BG,EAA8BH,EAC9BI,EAAY,GACVC,EAAcb,EAAAA,kBAA+C,CACjE,MAAO,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MAAM,MAAMA,CAAS,EACvB,EAEA,IAAI,OAAQ,CACV,OAAOG,EAAY,KACrB,EAEA,UAAWA,EAAY,UAEvB,CAAC,OAAO,UAAW,CACjBM,EAAO,QAAQ,CACjB,CACF,EAEA,OAAOA,CACT,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"pageSource.d.ts","sourceRoot":"","sources":["../src/pageSource.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAmB,MAAM,SAAS,CAAC;AAI7E,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,CA4JrH"}
1
+ {"version":3,"file":"pageSource.d.ts","sourceRoot":"","sources":["../src/pageSource.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAmB,MAAM,SAAS,CAAC;AAI7E,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,CAsKrH"}
@@ -1,26 +1,27 @@
1
1
  import { createAsyncSource as e } from "./asyncSource.js";
2
2
  import { SourcererDisposedError as t } from "./errors.js";
3
- import { createPagePagination as n, positiveInteger as r, totalItems as i } from "./pagination.js";
4
- import { isEqual as a } from "@vielzeug/arsenal";
3
+ import { createPagePagination as n, positiveInteger as r, sameParams as i, totalItems as a } from "./pagination.js";
5
4
  // src/pageSource.ts
6
5
  function createPageSource(o) {
7
6
  let s = {
8
7
  page: 1,
9
8
  pageSize: r(o.pageSize ?? 20, "pageSize"),
10
9
  params: o.params
11
- }, c = !1, l = e({
10
+ }, c = s, l = s, u = !1, d = e({
12
11
  error: null,
13
12
  items: [],
14
13
  loading: !1,
15
- pagination: n(s.page, s.pageSize, 0),
16
- params: s.params
14
+ pagination: n(c.page, c.pageSize, 0),
15
+ params: c.params
17
16
  }), assertLive = () => {
18
- if (l.disposed) throw new t();
19
- }, isCommitted = (e) => l.state.pagination.page === e.page && l.state.pagination.pageSize === e.pageSize && Object.is(l.state.params, e.params), fetch = (e) => l.fetch({
17
+ if (d.disposed) throw new t();
18
+ }, ensureLoaded = async () => {
19
+ !d.state.loading && !u && await fetch(c);
20
+ }, fetch = (e) => d.fetch({
20
21
  commit: () => {
21
- c = !0, s = e;
22
+ u = !0, l = e, c = e;
22
23
  },
23
- failure: (e, t) => ({
24
+ failure: (e, t) => (c = l, {
24
25
  ...e,
25
26
  error: t,
26
27
  loading: !1,
@@ -34,80 +35,80 @@ function createPageSource(o) {
34
35
  ...t,
35
36
  error: null,
36
37
  loading: !0,
37
- ...Object.is(e.params, t.params) ? {} : { pendingParams: e.params }
38
+ ...i(e.params, t.params) ? {} : { pendingParams: e.params }
38
39
  }),
39
40
  success: (t) => ({
40
41
  error: null,
41
42
  items: [...t.items],
42
43
  loading: !1,
43
- pagination: n(e.page, e.pageSize, i(t.totalItems)),
44
+ pagination: n(e.page, e.pageSize, a(t.totalItems)),
44
45
  params: e.params
45
46
  })
46
- }), normalizePage = (e) => c ? Math.min(r(e, "page"), l.state.pagination.pageCount) : r(e, "page"), goTo = async (e) => {
47
+ }), normalizePage = (e) => u ? Math.min(r(e, "page"), d.state.pagination.pageCount) : r(e, "page"), goTo = async (e) => {
47
48
  assertLive();
48
49
  let t = normalizePage(e);
49
- t === s.page ? l.state.loading || c && isCommitted(s) || await fetch(s) : (s = {
50
- ...s,
50
+ t === c.page ? await ensureLoaded() : (c = {
51
+ ...c,
51
52
  page: t
52
- }, await fetch(s));
53
- }, u = {
53
+ }, await fetch(c));
54
+ }, f = {
54
55
  async apply(e) {
55
56
  assertLive();
56
- let t = e.params === void 0 ? s.params : e.params;
57
- a(t, s.params) ? e.page === void 0 ? l.state.loading || c && isCommitted(s) || await fetch(s) : await goTo(e.page) : (s = {
58
- ...s,
57
+ let t = e.params === void 0 ? c.params : e.params;
58
+ i(t, c.params) ? e.page === void 0 ? await ensureLoaded() : await goTo(e.page) : (c = {
59
+ ...c,
59
60
  page: e.page === void 0 ? 1 : r(e.page, "page"),
60
61
  params: t
61
- }, await fetch(s));
62
+ }, await fetch(c));
62
63
  },
63
64
  get disposalSignal() {
64
- return l.disposalSignal;
65
+ return d.disposalSignal;
65
66
  },
66
- dispose: l.dispose,
67
+ dispose: d.dispose,
67
68
  get disposed() {
68
- return l.disposed;
69
+ return d.disposed;
69
70
  },
70
71
  first() {
71
72
  return goTo(1);
72
73
  },
73
74
  goTo,
74
75
  last() {
75
- return goTo(l.state.pagination.pageCount);
76
+ return goTo(d.state.pagination.pageCount);
76
77
  },
77
78
  async next() {
78
- assertLive(), (!c || s.page < l.state.pagination.pageCount) && await goTo(s.page + 1);
79
+ assertLive(), u ? c.page < d.state.pagination.pageCount && await goTo(c.page + 1) : await goTo(1);
79
80
  },
80
81
  async previous() {
81
- assertLive(), s.page > 1 && await goTo(s.page - 1);
82
+ assertLive(), c.page > 1 && await goTo(c.page - 1);
82
83
  },
83
84
  reload() {
84
- return fetch(s);
85
+ return fetch(c);
85
86
  },
86
87
  async setPageSize(e) {
87
88
  assertLive();
88
89
  let t = r(e, "pageSize");
89
- t === s.pageSize && s.page === 1 ? !l.state.loading && !isCommitted(s) && await fetch(s) : (s = {
90
- ...s,
90
+ t === c.pageSize && c.page === 1 ? await ensureLoaded() : (c = {
91
+ ...c,
91
92
  page: 1,
92
93
  pageSize: t
93
- }, await fetch(s));
94
+ }, await fetch(c));
94
95
  },
95
96
  async setParams(e) {
96
- assertLive(), Object.is(e, s.params) ? !l.state.loading && !isCommitted(s) && await fetch(s) : (s = {
97
- ...s,
97
+ assertLive(), i(e, c.params) ? await ensureLoaded() : (c = {
98
+ ...c,
98
99
  page: 1,
99
100
  params: e
100
- }, await fetch(s));
101
+ }, await fetch(c));
101
102
  },
102
103
  get state() {
103
- return l.state;
104
+ return d.state;
104
105
  },
105
- subscribe: l.subscribe,
106
+ subscribe: d.subscribe,
106
107
  [Symbol.dispose]() {
107
- u.dispose();
108
+ f.dispose();
108
109
  }
109
110
  };
110
- return u;
111
+ return f;
111
112
  }
112
113
  export { createPageSource };
113
114