@vielzeug/sourcerer 2.3.0 → 26.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -18
- package/dist/asyncSource.cjs +1 -1
- package/dist/asyncSource.cjs.map +1 -1
- package/dist/asyncSource.d.ts +11 -12
- package/dist/asyncSource.d.ts.map +1 -1
- package/dist/asyncSource.js +1 -50
- package/dist/asyncSource.js.map +1 -1
- package/dist/cursorSource.cjs +1 -1
- package/dist/cursorSource.cjs.map +1 -1
- package/dist/cursorSource.d.ts +2 -2
- package/dist/cursorSource.d.ts.map +1 -1
- package/dist/cursorSource.js +1 -81
- package/dist/cursorSource.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +3 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -9
- package/dist/errors.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -6
- package/dist/infiniteSource.cjs +1 -1
- package/dist/infiniteSource.cjs.map +1 -1
- package/dist/infiniteSource.d.ts +2 -2
- package/dist/infiniteSource.d.ts.map +1 -1
- package/dist/infiniteSource.js +1 -83
- package/dist/infiniteSource.js.map +1 -1
- package/dist/localSource.cjs +1 -1
- package/dist/localSource.cjs.map +1 -1
- package/dist/localSource.d.ts +3 -2
- package/dist/localSource.d.ts.map +1 -1
- package/dist/localSource.js +1 -73
- package/dist/localSource.js.map +1 -1
- package/dist/pageSource.cjs +1 -1
- package/dist/pageSource.cjs.map +1 -1
- package/dist/pageSource.d.ts +2 -2
- package/dist/pageSource.d.ts.map +1 -1
- package/dist/pageSource.js +1 -84
- package/dist/pageSource.js.map +1 -1
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.cjs.map +1 -1
- package/dist/pagination.d.ts +1 -2
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +1 -28
- package/dist/pagination.js.map +1 -1
- package/dist/requestController.cjs +1 -1
- package/dist/requestController.cjs.map +1 -1
- package/dist/requestController.js +1 -30
- package/dist/requestController.js.map +1 -1
- package/dist/sourceStore.cjs +1 -1
- package/dist/sourceStore.cjs.map +1 -1
- package/dist/sourceStore.d.ts +5 -2
- package/dist/sourceStore.d.ts.map +1 -1
- package/dist/sourceStore.js +1 -37
- package/dist/sourceStore.js.map +1 -1
- package/dist/sourcerer.cjs +1 -1
- package/dist/sourcerer.cjs.map +1 -1
- package/dist/sourcerer.iife.js +1 -1
- package/dist/sourcerer.iife.js.map +1 -1
- package/dist/sourcerer.js +1 -1
- package/dist/sourcerer.js.map +1 -1
- package/dist/types.d.ts +130 -117
- package/dist/types.d.ts.map +1 -1
- package/package.json +12 -8
- package/dist/_dev.cjs +0 -2
- package/dist/_dev.cjs.map +0 -1
- package/dist/_dev.d.ts +0 -2
- package/dist/_dev.d.ts.map +0 -1
- package/dist/_dev.js +0 -6
- package/dist/_dev.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infiniteSource.cjs","names":[],"sources":["../src/infiniteSource.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"infiniteSource.cjs","names":[],"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 },\n };\n\n return source;\n}\n"],"mappings":"6FAOA,IAAM,kBAAoB,EAAqB,EAAkB,KAAuC,CACtG,QAAS,EAAc,EACvB,cACA,WACA,WAAY,CACd,GAGA,SAAgB,qBACd,EAC4B,CAC5B,IAAI,EAA8B,CAChC,SAAU,EAAA,gBAAgB,EAAO,UAAY,GAAI,UAAU,EAC3D,OAAQ,EAAO,MACjB,EACI,EAAW,EACX,EAAY,GACV,EAAc,EAAA,kBAAmD,CACrE,MAAO,KACP,MAAO,CAAC,EACR,QAAS,GACT,WAAY,iBAAiB,EAAG,EAAU,SAAU,CAAC,EACrD,OAAQ,EAAU,MACpB,CAAC,EACK,eAAyB,CAC7B,GAAI,EAAY,SAAU,MAAM,IAAI,EAAA,sBACtC,EAEM,OAAS,EAA2B,EAAc,IAAmC,CACzF,IAAM,EAAc,EAAY,MAAM,MAEtC,OAAO,EAAY,MAAM,CACvB,WAAc,CACZ,EAAY,GACZ,EAAW,EAAO,EAClB,EAAY,CACd,EACA,SAAU,EAAU,KAAW,CAAE,GAAG,EAAU,QAAO,QAAS,GAAO,cAAe,IAAA,EAAU,GAC9F,KAAO,GAAW,EAAO,KAAK,CAAE,OAAM,SAAU,EAAQ,SAAU,OAAQ,EAAQ,OAAQ,QAAO,CAAC,EAClG,QAAU,IAAc,CACtB,GAAG,EACH,MAAO,KACP,QAAS,GACT,GAAI,GAAU,OAAO,GAAG,EAAQ,OAAQ,EAAS,MAAM,EAAI,CAAC,EAAI,CAAE,cAAe,EAAQ,MAAO,CAClG,GACA,QAAU,GAAW,CACnB,IAAM,EAAQ,EAAS,CAAC,GAAG,EAAa,GAAG,EAAO,KAAK,EAAI,CAAC,GAAG,EAAO,KAAK,EAC3E,MAAO,CACL,M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-1,4 +1,4 @@
|
|
|
1
1
|
import type { InfiniteSource, InfiniteSourceConfig } from './types';
|
|
2
|
-
/** Infinite sources
|
|
3
|
-
export declare function createInfiniteSource<T>(config: InfiniteSourceConfig<T>): InfiniteSource<T>;
|
|
2
|
+
/** Infinite sources retain committed items while replacement work is pending. */
|
|
3
|
+
export declare function createInfiniteSource<T, TParams = undefined>(config: InfiniteSourceConfig<T, TParams>): InfiniteSource<T, TParams>;
|
|
4
4
|
//# sourceMappingURL=infiniteSource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infiniteSource.d.ts","sourceRoot":"","sources":["../src/infiniteSource.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"infiniteSource.d.ts","sourceRoot":"","sources":["../src/infiniteSource.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAsB,cAAc,EAAE,oBAAoB,EAAuB,MAAM,SAAS,CAAC;AAW7G,iFAAiF;AACjF,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS,EACzD,MAAM,EAAE,oBAAoB,CAAC,CAAC,EAAE,OAAO,CAAC,GACvC,cAAc,CAAC,CAAC,EAAE,OAAO,CAAC,CA6G5B"}
|
package/dist/infiniteSource.js
CHANGED
|
@@ -1,84 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createAsyncSource as t } from "./asyncSource.js";
|
|
3
|
-
import { positiveInteger as n, sameQuery as r, totalItems as i } from "./pagination.js";
|
|
4
|
-
//#region src/infiniteSource.ts
|
|
5
|
-
var a = (e, t) => ({
|
|
6
|
-
hasMore: e < t,
|
|
7
|
-
kind: "infinite",
|
|
8
|
-
loaded: e,
|
|
9
|
-
total: t
|
|
10
|
-
}), o = (e, t = {}) => ({
|
|
11
|
-
pageSize: n(t.pageSize ?? e.pageSize, "pageSize"),
|
|
12
|
-
search: t.search ?? e.search
|
|
13
|
-
});
|
|
14
|
-
function s(n) {
|
|
15
|
-
let s = o({
|
|
16
|
-
pageSize: 20,
|
|
17
|
-
search: ""
|
|
18
|
-
}, n.initialQuery), c = 1, l = t({
|
|
19
|
-
data: [],
|
|
20
|
-
error: null,
|
|
21
|
-
isFetching: !1,
|
|
22
|
-
pagination: a(0, 0),
|
|
23
|
-
query: s
|
|
24
|
-
}), u = (e, t, r) => {
|
|
25
|
-
let o = l.snapshot.data;
|
|
26
|
-
return l.fetch({
|
|
27
|
-
load: (r) => n.load({
|
|
28
|
-
query: {
|
|
29
|
-
page: t,
|
|
30
|
-
pageSize: e.pageSize,
|
|
31
|
-
search: e.search
|
|
32
|
-
},
|
|
33
|
-
signal: r
|
|
34
|
-
}),
|
|
35
|
-
pending: (t) => ({
|
|
36
|
-
...t,
|
|
37
|
-
error: null,
|
|
38
|
-
isFetching: !0,
|
|
39
|
-
pagination: a(t.data.length, t.pagination.total),
|
|
40
|
-
...r ? {} : { pendingQuery: e }
|
|
41
|
-
}),
|
|
42
|
-
query: e,
|
|
43
|
-
success: (n) => {
|
|
44
|
-
let s = i(n.total), l = r ? [...o, ...n.data] : n.data;
|
|
45
|
-
return c = t + 1, {
|
|
46
|
-
data: l,
|
|
47
|
-
error: null,
|
|
48
|
-
isFetching: !1,
|
|
49
|
-
pagination: a(l.length, s),
|
|
50
|
-
query: e
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}, d = () => (c = 1, u(s, 1, !1)), f = {
|
|
55
|
-
get disposalSignal() {
|
|
56
|
-
return l.disposalSignal;
|
|
57
|
-
},
|
|
58
|
-
dispose: l.dispose,
|
|
59
|
-
get disposed() {
|
|
60
|
-
return l.disposed;
|
|
61
|
-
},
|
|
62
|
-
loadMore() {
|
|
63
|
-
let { isFetching: e, pagination: t } = l.snapshot;
|
|
64
|
-
return e || l.snapshot.data.length > 0 && !t.hasMore ? Promise.resolve() : u(s, c, !0);
|
|
65
|
-
},
|
|
66
|
-
reload: d,
|
|
67
|
-
setQuery: async (e) => {
|
|
68
|
-
let t = o(l.snapshot.pendingQuery ?? l.snapshot.query, e);
|
|
69
|
-
r(t, s) || (s = t, c = 1, await u(t, 1, !1));
|
|
70
|
-
},
|
|
71
|
-
get snapshot() {
|
|
72
|
-
return l.snapshot;
|
|
73
|
-
},
|
|
74
|
-
subscribe: l.subscribe,
|
|
75
|
-
[Symbol.dispose]() {
|
|
76
|
-
f.dispose();
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
return n.autoStart !== !1 && d().catch(() => /* @__PURE__ */ e("Initial load failed. Inspect source.snapshot.error.")), f;
|
|
80
|
-
}
|
|
81
|
-
//#endregion
|
|
82
|
-
export { s as createInfiniteSource };
|
|
83
|
-
|
|
1
|
+
import{SourcererDisposedError as e}from"./errors.js";import{createAsyncSource as t}from"./asyncSource.js";import{positiveInteger as n,totalItems as r}from"./pagination.js";var createPagination=(e,t,n)=>({hasMore:e<n,loadedItems:e,pageSize:t,totalItems:n});function createInfiniteSource(i){let a={pageSize:n(i.pageSize??20,`pageSize`),params:i.params},o=1,s=!1,c=t({error:null,items:[],loading:!1,pagination:createPagination(0,a.pageSize,0),params:a.params}),assertLive=()=>{if(c.disposed)throw new e},fetch=(e,t,n)=>{let l=c.state.items;return c.fetch({commit:()=>{s=!0,o=t+1,a=e},failure:(e,t)=>({...e,error:t,loading:!1,pendingParams:void 0}),load:n=>i.load({page:t,pageSize:e.pageSize,params:e.params,signal:n}),pending:t=>({...t,error:null,loading:!0,...n||Object.is(e.params,t.params)?{}:{pendingParams:e.params}}),success:t=>{let i=n?[...l,...t.items]:[...t.items];return{error:null,items:i,loading:!1,pagination:createPagination(i.length,e.pageSize,r(t.totalItems)),params:e.params}}})},reload=()=>fetch(a,1,!1),l={get disposalSignal(){return c.disposalSignal},dispose:c.dispose,get disposed(){return c.disposed},async loadMore(){if(assertLive(),!c.state.loading){if(!s||!Object.is(a.params,c.state.params)){await reload();return}c.state.pagination.hasMore&&await fetch(a,o,!0)}},reload,async setPageSize(e){assertLive();let t=n(e,`pageSize`);if(t===a.pageSize){if(c.state.loading||c.state.pagination.pageSize===t)return;await reload();return}a={...a,pageSize:t},o=1,await reload()},async setParams(e){if(assertLive(),Object.is(e,a.params)){!c.state.loading&&!Object.is(e,c.state.params)&&await reload();return}a={...a,params:e},o=1,await reload()},get state(){return c.state},subscribe:c.subscribe,[Symbol.dispose](){l.dispose()}};return l}export{createInfiniteSource};
|
|
84
2
|
//# sourceMappingURL=infiniteSource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infiniteSource.js","names":[],"sources":["../src/infiniteSource.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"infiniteSource.js","names":[],"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 },\n };\n\n return source;\n}\n"],"mappings":"4KAOA,IAAM,kBAAoB,EAAqB,EAAkB,KAAuC,CACtG,QAAS,EAAc,EACvB,cACA,WACA,WAAY,CACd,GAGA,SAAgB,qBACd,EAC4B,CAC5B,IAAI,EAA8B,CAChC,SAAU,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a,CAAC,OAAO,GAAG,EAAU,OAAQ,EAAY,MAAM,MAAM,EAAG,CACxE,MAAM,OAAO,EACb,MACF,CACI,EAAY,MAAM,WAAW,SAAS,MAAM,MAAM,EAAW,EAAU,EAAI,CAD/E,CAEF,EAEA,OAEA,MAAM,YAAY,EAAU,CAC1B,WAAW,EACX,IAAM,EAAa,EAAgB,EAAU,UAAU,EACvD,GAAI,IAAe,EAAU,SAAU,CACrC,GAAI,EAAY,MAAM,SAAW,EAAY,MAAM,WAAW,WAAa,EAAY,OACvF,MAAM,OAAO,EACb,MACF,CACA,EAAY,CAAE,GAAG,EAAW,SAAU,CAAW,EACjD,EAAW,EACX,MAAM,OAAO,CACf,EAEA,MAAM,UAAU,EAAQ,CAEtB,GADA,WAAW,EACP,OAAO,GAAG,EAAQ,EAAU,MAAM,EAAG,CACnC,CAAC,EAAY,MAAM,SAAW,CAAC,OAAO,GAAG,EAAQ,EAAY,MAAM,MAAM,GAAG,MAAM,OAAO,EAC7F,MACF,CACA,EAAY,CAAE,GAAG,EAAW,QAAO,EACnC,EAAW,EACX,MAAM,OAAO,CACf,EAEA,IAAI,OAAQ,CACV,OAAO,EAAY,KACrB,EAEA,UAAW,EAAY,UAEvB,CAAC,OAAO,UAAW,CACjB,EAAO,QAAQ,CACjB,CACF,EAEA,OAAO,CACT"}
|
package/dist/localSource.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./
|
|
1
|
+
const e=require("./errors.cjs"),t=require("./sourceStore.cjs"),n=require("./pagination.cjs");function createLocalSource(r,i={}){let a=r,o=1,s=n.positiveInteger(i.pageSize??20,`pageSize`),c=i.params,buildState=()=>{let e=i.filter?a.filter(e=>i.filter?.(e,c)):a,t=n.createPagePagination(o,s,e.length);if(o>t.pageCount)return o=t.pageCount,buildState();let r=(o-1)*s;return{error:null,items:e.slice(r,r+s),loading:!1,pagination:t,params:c}},l=t.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 t=Math.min(n.positiveInteger(e,`page`),l.value.pagination.pageCount);t!==o&&(o=t,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 t=n.positiveInteger(e,`pageSize`);t!==s&&(o=1,s=t,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;
|
|
2
2
|
//# sourceMappingURL=localSource.cjs.map
|
package/dist/localSource.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localSource.cjs","names":[],"sources":["../src/localSource.ts"],"sourcesContent":["import { createPagePagination, positiveInteger
|
|
1
|
+
{"version":3,"file":"localSource.cjs","names":[],"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":"6FAWA,SAAgB,kBACd,EACA,EAAwC,CAAC,EAChB,CACzB,IAAI,EAAW,EACX,EAAO,EACP,EAAW,EAAA,gBAAgB,EAAO,UAAY,GAAI,UAAU,EAC5D,EAAS,EAAO,OAEd,eAAiD,CACrD,IAAM,EAAW,EAAO,OAAS,EAAS,OAAQ,GAAS,EAAO,SAAS,EAAM,CAAM,CAAC,EAAI,EACtF,EAAa,EAAA,qBAAqB,EAAM,EAAU,EAAS,MAAM,EACvE,GAAI,EAAO,EAAW,UAEpB,MADA,GAAO,EAAW,UACX,WAAW,EAEpB,IAAM,GAAS,EAAO,GAAK,EAE3B,MAAO,CACL,MAAO,KACP,MAAO,EAAS,MAAM,EAAO,EAAQ,CAAQ,EAC7C,QAAS,GACT,aACA,QACF,CACF,EAEM,EAAQ,EAAA,kBAAkB,WAAW,CAAC,EACtC,eAAyB,CAC7B,GAAI,EAAM,SAAU,MAAM,IAAI,EAAA,sBAChC,EACM,gBAAkB,EAAsB,IAC5C,OAAO,KAAK,CAAI,CAAC,CAAC,MAAO,GAAQ,EAAK,KAAiC,EAAM,EAA4B,EACrG,WAAqB,CACzB,IAAM,EAAO,WAAW,EAClB,EAAU,EAAM,MAChB,EACJ,EAAK,MAAM,SAAW,EAAQ,MAAM,QACpC,EAAK,MAAM,OAAO,EAAM,IAAU,OAAO,GAAG,EAAM,EAAQ,MAAM,EAAM,CAAC,EAErE,OAAO,GAAG,EAAK,OAAQ,EAAQ,MAAM,GAAK,GAAa,eAAe,EAAK,WAAY,EAAQ,UAAU,GAE7G,EAAM,IAAI,CAAI,CAChB,EACM,KAAQ,GAA2B,CACvC,WAAW,EACX,IAAM,EAAa,KAAK,IAAI,EAAA,gBAAgB,EAAU,MAAM,EAAG,EAAM,MAAM,WAAW,SAAS,EAC3F,IAAe,IACnB,EAAO,EACP,OAAO,EACT,EAEM,EAAkC,CACtC,IAAI,gBAAiB,CACnB,OAAO,EAAM,cACf,EAEA,QAAS,EAAM,QAEf,IAAI,UAAW,CACb,OAAO,EAAM,QACf,EAEA,OAAQ,CACN,KAAK,CAAC,CACR,EAEA,KAEA,MAAO,CACL,KAAK,EAAM,MAAM,WAAW,SAAS,CACvC,EAEA,MAAO,CACD,EAAM,MAAM,WAAW,QAAS,KAAK,EAAO,CAAC,EAC5C,WAAW,CAClB,EAEA,UAAW,CACL,EAAM,MAAM,WAAW,YAAa,KAAK,EAAO,CAAC,EAChD,WAAW,CAClB,EAEA,SAAS,EAAW,CAClB,WAAW,EACP,IAAc,IAClB,EAAW,EACX,OAAO,EACT,EAEA,YAAY,EAAc,CACxB,WAAW,EACX,IAAM,EAAa,EAAA,gBAAgB,EAAc,UAAU,EACvD,IAAe,IACnB,EAAO,EACP,EAAW,EACX,OAAO,EACT,EAEA,UAAU,EAAY,CACpB,WAAW,EACP,QAAO,GAAG,EAAY,CAAM,IAChC,EAAO,EACP,EAAS,EACT,OAAO,EACT,EAEA,IAAI,OAAQ,CACV,OAAO,EAAM,KACf,EAEA,UAAW,EAAM,UAEjB,CAAC,OAAO,UAAW,CACjB,EAAO,QAAQ,CACjB,CACF,EAEA,OAAO,CACT"}
|
package/dist/localSource.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { LocalSource, LocalSourceConfig } from './types';
|
|
2
|
-
/** Local sources
|
|
3
|
-
export declare function createLocalSource<T>(
|
|
2
|
+
/** Local sources filter and paginate an in-memory collection synchronously. */
|
|
3
|
+
export declare function createLocalSource<T>(items: readonly T[]): LocalSource<T>;
|
|
4
|
+
export declare function createLocalSource<T, TParams = undefined>(items: readonly T[], config: LocalSourceConfig<T, TParams>): LocalSource<T, TParams>;
|
|
4
5
|
//# sourceMappingURL=localSource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localSource.d.ts","sourceRoot":"","sources":["../src/localSource.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/localSource.js
CHANGED
|
@@ -1,74 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createPagePagination as t, positiveInteger as n, sameQuery as r, totalItems as i } from "./pagination.js";
|
|
3
|
-
//#region src/localSource.ts
|
|
4
|
-
var a = (e, t = {}, r) => {
|
|
5
|
-
let i = t.page ?? e.page, a = t.pageSize ?? e.pageSize, o = t.search ?? e.search, s = t.pageSize !== void 0 || t.search !== void 0, c = t.page ?? (s ? 1 : i);
|
|
6
|
-
return {
|
|
7
|
-
page: r === void 0 ? n(c, "page") : Math.min(n(c, "page"), r),
|
|
8
|
-
pageSize: n(a, "pageSize"),
|
|
9
|
-
search: o
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
function o(n, o = {}) {
|
|
13
|
-
let s = n, c = a({
|
|
14
|
-
page: 1,
|
|
15
|
-
pageSize: 20,
|
|
16
|
-
search: ""
|
|
17
|
-
}, o.initialQuery), l = () => {
|
|
18
|
-
let e = c.search.length > 0 && o.match ? s.filter((e) => o.match?.(e, c.search)) : s, n = i(e.length), r = t(c.page, c.pageSize, n), a = (r.index - 1) * r.size;
|
|
19
|
-
return c = {
|
|
20
|
-
...c,
|
|
21
|
-
page: r.index
|
|
22
|
-
}, {
|
|
23
|
-
data: e.slice(a, a + r.size),
|
|
24
|
-
error: null,
|
|
25
|
-
isFetching: !1,
|
|
26
|
-
pagination: r,
|
|
27
|
-
query: c
|
|
28
|
-
};
|
|
29
|
-
}, u = e(l()), d = () => {
|
|
30
|
-
let e = l();
|
|
31
|
-
return r(e.query, u.value.query) && e.data === u.value.data && e.pagination === u.value.pagination ? !1 : (u.set(e), !0);
|
|
32
|
-
}, f = (e) => {
|
|
33
|
-
let t = a(c, e, u.value.pagination.count);
|
|
34
|
-
r(t, c) || (c = t, d());
|
|
35
|
-
}, p = {
|
|
36
|
-
get disposalSignal() {
|
|
37
|
-
return u.disposalSignal;
|
|
38
|
-
},
|
|
39
|
-
dispose: u.dispose,
|
|
40
|
-
get disposed() {
|
|
41
|
-
return u.disposed;
|
|
42
|
-
},
|
|
43
|
-
page: {
|
|
44
|
-
go(e) {
|
|
45
|
-
f({ page: e });
|
|
46
|
-
},
|
|
47
|
-
last() {
|
|
48
|
-
f({ page: u.value.pagination.count });
|
|
49
|
-
},
|
|
50
|
-
next() {
|
|
51
|
-
u.value.pagination.hasNext && f({ page: u.value.pagination.index + 1 });
|
|
52
|
-
},
|
|
53
|
-
previous() {
|
|
54
|
-
u.value.pagination.hasPrevious && f({ page: u.value.pagination.index - 1 });
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
setData(e) {
|
|
58
|
-
e !== s && (s = e, d());
|
|
59
|
-
},
|
|
60
|
-
setQuery: f,
|
|
61
|
-
get snapshot() {
|
|
62
|
-
return u.value;
|
|
63
|
-
},
|
|
64
|
-
subscribe: u.subscribe,
|
|
65
|
-
[Symbol.dispose]() {
|
|
66
|
-
p.dispose();
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
return p;
|
|
70
|
-
}
|
|
71
|
-
//#endregion
|
|
72
|
-
export { o as createLocalSource };
|
|
73
|
-
|
|
1
|
+
import{SourcererDisposedError as e}from"./errors.js";import{createSourceStore as t}from"./sourceStore.js";import{createPagePagination as n,positiveInteger as r}from"./pagination.js";function createLocalSource(i,a={}){let o=i,s=1,c=r(a.pageSize??20,`pageSize`),l=a.params,buildState=()=>{let e=a.filter?o.filter(e=>a.filter?.(e,l)):o,t=n(s,c,e.length);if(s>t.pageCount)return s=t.pageCount,buildState();let r=(s-1)*c;return{error:null,items:e.slice(r,r+c),loading:!1,pagination:t,params:l}},u=t(buildState()),assertLive=()=>{if(u.disposed)throw new e},samePagination=(e,t)=>Object.keys(e).every(n=>e[n]===t[n]),commit=()=>{let e=buildState(),t=u.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)||u.set(e)},goTo=e=>{assertLive();let t=Math.min(r(e,`page`),u.value.pagination.pageCount);t!==s&&(s=t,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 t=r(e,`pageSize`);t!==c&&(s=1,c=t,commit())},setParams(e){assertLive(),!Object.is(e,l)&&(s=1,l=e,commit())},get state(){return u.value},subscribe:u.subscribe,[Symbol.dispose](){d.dispose()}};return d}export{createLocalSource};
|
|
74
2
|
//# sourceMappingURL=localSource.js.map
|
package/dist/localSource.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localSource.js","names":[],"sources":["../src/localSource.ts"],"sourcesContent":["import { createPagePagination, positiveInteger
|
|
1
|
+
{"version":3,"file":"localSource.js","names":[],"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":"sLAWA,SAAgB,kBACd,EACA,EAAwC,CAAC,EAChB,CACzB,IAAI,EAAW,EACX,EAAO,EACP,EAAW,EAAgB,EAAO,UAAY,GAAI,UAAU,EAC5D,EAAS,EAAO,OAEd,eAAiD,CACrD,IAAM,EAAW,EAAO,OAAS,EAAS,OAAQ,GAAS,EAAO,SAAS,EAAM,CAAM,CAAC,EAAI,EACtF,EAAa,EAAqB,EAAM,EAAU,EAAS,MAAM,EACvE,GAAI,EAAO,EAAW,UAEpB,MADA,GAAO,EAAW,UACX,WAAW,EAEpB,IAAM,GAAS,EAAO,GAAK,EAE3B,MAAO,CACL,MAAO,KACP,MAAO,EAAS,MAAM,EAAO,EAAQ,CAAQ,EAC7C,QAAS,GACT,aACA,QACF,CACF,EAEM,EAAQ,EAAkB,WAAW,CAAC,EACtC,eAAyB,CAC7B,GAAI,EAAM,SAAU,MAAM,IAAI,CAChC,EACM,gBAAkB,EAAsB,IAC5C,OAAO,KAAK,CAAI,CAAC,CAAC,MAAO,GAAQ,EAAK,KAAiC,EAAM,EAA4B,EACrG,WAAqB,CACzB,IAAM,EAA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1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./
|
|
1
|
+
const e=require("./errors.cjs"),t=require("./asyncSource.cjs"),n=require("./pagination.cjs");function createPageSource(r){let i={page:1,pageSize:n.positiveInteger(r.pageSize??20,`pageSize`),params:r.params},a=!1,o=t.createAsyncSource({error:null,items:[],loading:!1,pagination:n.createPagePagination(i.page,i.pageSize,0),params:i.params}),assertLive=()=>{if(o.disposed)throw new e.SourcererDisposedError},isCommitted=e=>o.state.pagination.page===e.page&&o.state.pagination.pageSize===e.pageSize&&Object.is(o.state.params,e.params),fetch=e=>o.fetch({commit:()=>{a=!0,i=e},failure:(e,t)=>({...e,error:t,loading:!1,pendingParams:void 0}),load:t=>r.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})}),goTo=async e=>{assertLive();let t=a?Math.min(n.positiveInteger(e,`page`),o.state.pagination.pageCount):n.positiveInteger(e,`page`);if(t===i.page){!o.state.loading&&(!a||!isCommitted(i))&&await fetch(i);return}i={...i,page:t},await fetch(i)},s={get disposalSignal(){return o.disposalSignal},dispose:o.dispose,get disposed(){return o.disposed},first(){return goTo(1)},goTo,last(){return goTo(o.state.pagination.pageCount)},async next(){assertLive(),(!a||i.page<o.state.pagination.pageCount)&&await goTo(i.page+1)},async previous(){assertLive(),i.page>1&&await goTo(i.page-1)},reload(){return fetch(i)},async setPageSize(e){assertLive();let t=n.positiveInteger(e,`pageSize`);if(t===i.pageSize&&i.page===1){!o.state.loading&&!isCommitted(i)&&await fetch(i);return}i={...i,page:1,pageSize:t},await fetch(i)},async setParams(e){if(assertLive(),Object.is(e,i.params)){!o.state.loading&&!isCommitted(i)&&await fetch(i);return}i={...i,page:1,params:e},await fetch(i)},get state(){return o.state},subscribe:o.subscribe,[Symbol.dispose](){s.dispose()}};return s}exports.createPageSource=createPageSource;
|
|
2
2
|
//# sourceMappingURL=pageSource.cjs.map
|
package/dist/pageSource.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pageSource.cjs","names":[],"sources":["../src/pageSource.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"pageSource.cjs","names":[],"sources":["../src/pageSource.ts"],"sourcesContent":["import { 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 goTo = async (page: number): Promise<void> => {\n assertLive();\n const normalized = hasLoaded\n ? Math.min(positiveInteger(page, 'page'), asyncSource.state.pagination.pageCount)\n : positiveInteger(page, '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 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":"6FAQA,SAAgB,iBAAyC,EAA8D,CACrH,IAAI,EAA8B,CAChC,KAAM,EACN,SAAU,EAAA,gBAAgB,EAAO,UAAY,GAAI,UAAU,EAC3D,OAAQ,EAAO,MACjB,EACI,EAAY,GACV,EAAc,EAAA,kBAA+C,CACjE,MAAO,KACP,MAAO,CAAC,EACR,QAAS,GACT,WAAY,EAAA,qBAAqB,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B,EAEA,QAAS,EAAY,QAErB,IAAI,UAAW,CACb,OAAO,EAAY,QACrB,EAEA,OAAQ,CACN,OAAO,KAAK,CAAC,CACf,EAEA,KAEA,MAAO,CACL,OAAO,KAAK,EAAY,MAAM,WAAW,SAAS,CACpD,EAEA,MAAM,MAAO,CACX,WAAW,GACP,CAAC,GAAa,EAAU,KAAO,EAAY,MAAM,WAAW,YAAW,MAAM,KAAK,EAAU,KAAO,CAAC,CAC1G,EAEA,MAAM,UAAW,CACf,WAAW,EACP,EAAU,KAAO,GAAG,MAAM,KAAK,EAAU,KAAO,CAAC,CACvD,EAEA,QAAS,CACP,OAAO,MAAM,CAAS,CACxB,EAEA,MAAM,YAAY,EAAU,CAC1B,WAAW,EACX,IAAM,EAAa,EAAA,gBAAgB,EAAU,UAAU,EACvD,GAAI,IAAe,EAAU,UAAY,EAAU,OAAS,EAAG,CACzD,CAAC,EAAY,MAAM,SAAW,CAAC,YAAY,CAAS,GAAG,MAAM,MAAM,CAAS,EAChF,MACF,CACA,EAAY,CAAE,GAAG,EAAW,KAAM,EAAG,SAAU,CAAW,EAC1D,MAAM,MAAM,CAAS,CACvB,EAEA,MAAM,UAAU,EAAQ,CAEtB,GADA,WAAW,EACP,OAAO,GAAG,EAAQ,EAAU,MAAM,EAAG,CACnC,CAAC,EAAY,MAAM,SAAW,CAAC,YAAY,CAAS,GAAG,MAAM,MAAM,CAAS,EAChF,MACF,CACA,EAAY,CAAE,GAAG,EAAW,KAAM,EAAG,QAAO,EAC5C,MAAM,MAAM,CAAS,CACvB,EAEA,IAAI,OAAQ,CACV,OAAO,EAAY,KACrB,EAEA,UAAW,EAAY,UAEvB,CAAC,OAAO,UAAW,CACjB,EAAO,QAAQ,CACjB,CACF,EAEA,OAAO,CACT"}
|
package/dist/pageSource.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { PageSource, PageSourceConfig } from './types';
|
|
2
|
-
/** Page sources retain
|
|
3
|
-
export declare function createPageSource<T,
|
|
2
|
+
/** Page sources retain committed items while replacement work is pending. */
|
|
3
|
+
export declare function createPageSource<T, TParams = undefined>(config: PageSourceConfig<T, TParams>): PageSource<T, TParams>;
|
|
4
4
|
//# sourceMappingURL=pageSource.d.ts.map
|
package/dist/pageSource.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pageSource.d.ts","sourceRoot":"","sources":["../src/pageSource.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
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,CA8HrH"}
|
package/dist/pageSource.js
CHANGED
|
@@ -1,85 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createAsyncSource as t } from "./asyncSource.js";
|
|
3
|
-
import { createPagePagination as n, positiveInteger as r, sameQuery as i, totalItems as a } from "./pagination.js";
|
|
4
|
-
//#region src/pageSource.ts
|
|
5
|
-
var o = (e, t = {}, n) => {
|
|
6
|
-
let i = t.page ?? e.page, a = t.pageSize ?? e.pageSize, o = t.search ?? e.search, s = "filter" in t || t.pageSize !== void 0 || t.search !== void 0 || "sort" in t, c = t.page ?? (s ? 1 : i);
|
|
7
|
-
return {
|
|
8
|
-
..."filter" in t ? t.filter !== void 0 && { filter: t.filter } : e.filter !== void 0 && { filter: e.filter },
|
|
9
|
-
..."sort" in t ? t.sort !== void 0 && { sort: t.sort } : e.sort !== void 0 && { sort: e.sort },
|
|
10
|
-
page: n === void 0 ? r(c, "page") : Math.min(r(c, "page"), n),
|
|
11
|
-
pageSize: r(a, "pageSize"),
|
|
12
|
-
search: o
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
function s(r) {
|
|
16
|
-
let s = o({
|
|
17
|
-
page: 1,
|
|
18
|
-
pageSize: 20,
|
|
19
|
-
search: ""
|
|
20
|
-
}, r.initialQuery), c = t({
|
|
21
|
-
data: [],
|
|
22
|
-
error: null,
|
|
23
|
-
isFetching: !1,
|
|
24
|
-
pagination: n(s.page, s.pageSize, 0),
|
|
25
|
-
query: s
|
|
26
|
-
}), l = (e) => c.fetch({
|
|
27
|
-
load: (t) => r.load({
|
|
28
|
-
query: e,
|
|
29
|
-
signal: t
|
|
30
|
-
}),
|
|
31
|
-
query: e,
|
|
32
|
-
success: (t) => {
|
|
33
|
-
let r = a(t.total), i = n(e.page, e.pageSize, r), o = {
|
|
34
|
-
...e,
|
|
35
|
-
page: i.index
|
|
36
|
-
};
|
|
37
|
-
return s = o, {
|
|
38
|
-
data: t.data,
|
|
39
|
-
error: null,
|
|
40
|
-
isFetching: !1,
|
|
41
|
-
pagination: i,
|
|
42
|
-
query: o
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
}), u = () => l(s), d = async (e) => {
|
|
46
|
-
let t = o(c.snapshot.pendingQuery ?? c.snapshot.query, e, c.snapshot.pagination.total > 0 ? c.snapshot.pagination.count : void 0);
|
|
47
|
-
i(t, s) || (s = t, await l(t));
|
|
48
|
-
}, f = {
|
|
49
|
-
get disposalSignal() {
|
|
50
|
-
return c.disposalSignal;
|
|
51
|
-
},
|
|
52
|
-
dispose: c.dispose,
|
|
53
|
-
get disposed() {
|
|
54
|
-
return c.disposed;
|
|
55
|
-
},
|
|
56
|
-
page: {
|
|
57
|
-
go(e) {
|
|
58
|
-
return c.snapshot.isFetching ? Promise.resolve() : d({ page: e });
|
|
59
|
-
},
|
|
60
|
-
last() {
|
|
61
|
-
return c.snapshot.isFetching ? Promise.resolve() : d({ page: c.snapshot.pagination.count });
|
|
62
|
-
},
|
|
63
|
-
next() {
|
|
64
|
-
return c.snapshot.isFetching || !c.snapshot.pagination.hasNext ? Promise.resolve() : d({ page: c.snapshot.pagination.index + 1 });
|
|
65
|
-
},
|
|
66
|
-
previous() {
|
|
67
|
-
return c.snapshot.isFetching || !c.snapshot.pagination.hasPrevious ? Promise.resolve() : d({ page: c.snapshot.pagination.index - 1 });
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
reload: u,
|
|
71
|
-
setQuery: d,
|
|
72
|
-
get snapshot() {
|
|
73
|
-
return c.snapshot;
|
|
74
|
-
},
|
|
75
|
-
subscribe: c.subscribe,
|
|
76
|
-
[Symbol.dispose]() {
|
|
77
|
-
f.dispose();
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
return r.autoStart !== !1 && u().catch(() => /* @__PURE__ */ e("Initial load failed. Inspect source.snapshot.error.")), f;
|
|
81
|
-
}
|
|
82
|
-
//#endregion
|
|
83
|
-
export { s as createPageSource };
|
|
84
|
-
|
|
1
|
+
import{SourcererDisposedError as e}from"./errors.js";import{createAsyncSource as t}from"./asyncSource.js";import{createPagePagination as n,positiveInteger as r,totalItems as i}from"./pagination.js";function createPageSource(a){let o={page:1,pageSize:r(a.pageSize??20,`pageSize`),params:a.params},s=!1,c=t({error:null,items:[],loading:!1,pagination:n(o.page,o.pageSize,0),params:o.params}),assertLive=()=>{if(c.disposed)throw new e},isCommitted=e=>c.state.pagination.page===e.page&&c.state.pagination.pageSize===e.pageSize&&Object.is(c.state.params,e.params),fetch=e=>c.fetch({commit:()=>{s=!0,o=e},failure:(e,t)=>({...e,error:t,loading:!1,pendingParams:void 0}),load:t=>a.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(e.page,e.pageSize,i(t.totalItems)),params:e.params})}),goTo=async e=>{assertLive();let t=s?Math.min(r(e,`page`),c.state.pagination.pageCount):r(e,`page`);if(t===o.page){!c.state.loading&&(!s||!isCommitted(o))&&await fetch(o);return}o={...o,page:t},await fetch(o)},l={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||o.page<c.state.pagination.pageCount)&&await goTo(o.page+1)},async previous(){assertLive(),o.page>1&&await goTo(o.page-1)},reload(){return fetch(o)},async setPageSize(e){assertLive();let t=r(e,`pageSize`);if(t===o.pageSize&&o.page===1){!c.state.loading&&!isCommitted(o)&&await fetch(o);return}o={...o,page:1,pageSize:t},await fetch(o)},async setParams(e){if(assertLive(),Object.is(e,o.params)){!c.state.loading&&!isCommitted(o)&&await fetch(o);return}o={...o,page:1,params:e},await fetch(o)},get state(){return c.state},subscribe:c.subscribe,[Symbol.dispose](){l.dispose()}};return l}export{createPageSource};
|
|
85
2
|
//# sourceMappingURL=pageSource.js.map
|