@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
package/README.md
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
# @vielzeug/sourcerer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Reactive collection sources with local, page, cursor, and infinite pagination
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
4
6
|
|
|
5
7
|
```sh
|
|
6
8
|
pnpm add @vielzeug/sourcerer
|
|
9
|
+
npm install @vielzeug/sourcerer
|
|
10
|
+
yarn add @vielzeug/sourcerer
|
|
7
11
|
```
|
|
8
12
|
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
9
15
|
```ts
|
|
10
16
|
import { createPageSource } from '@vielzeug/sourcerer';
|
|
11
17
|
|
|
12
18
|
const users = createPageSource({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
load: async ({ page, pageSize }) => ({
|
|
20
|
+
items: [{ id: page, name: 'Ada' }].slice(0, pageSize),
|
|
21
|
+
totalItems: 1,
|
|
22
|
+
}),
|
|
23
|
+
pageSize: 20,
|
|
16
24
|
});
|
|
17
25
|
|
|
18
26
|
await users.reload();
|
|
19
|
-
console.log(users.
|
|
20
|
-
console.log(users.
|
|
27
|
+
console.log(users.state.items);
|
|
28
|
+
console.log(users.state.pagination.totalItems);
|
|
21
29
|
users.dispose();
|
|
22
30
|
```
|
|
23
31
|
|
|
24
|
-
Every source exposes an atomic `snapshot` and `subscribe(listener)`. `setQuery()` changes query fields; `page.*` changes page index. While newer work is active, `pendingQuery` records it without mixing it into loaded data. Page sources cancel superseded requests and preserve successful data on background refresh failures.
|
|
25
|
-
|
|
26
|
-
| Factory | Purpose |
|
|
27
|
-
| --- | --- |
|
|
28
|
-
| `createLocalSource()` | Synchronous in-memory collection |
|
|
29
|
-
| `createPageSource()` | Numbered async pages |
|
|
30
|
-
| `createCursorSource()` | Cursor-based async pages |
|
|
31
|
-
| `createInfiniteSource()` | Appended async pages |
|
|
32
|
-
|
|
33
|
-
Sourcerer manages collection state and request succession. Configure retries, cache, polling, URL serialization, and optimistic mutation with your transport or application layer.
|
|
34
|
-
|
|
35
32
|
## Documentation
|
|
36
33
|
|
|
37
34
|
- [Overview](https://vielzeug.dev/sourcerer/)
|
|
38
35
|
- [Usage Guide](https://vielzeug.dev/sourcerer/usage)
|
|
39
36
|
- [API Reference](https://vielzeug.dev/sourcerer/api)
|
|
37
|
+
- [Examples](https://vielzeug.dev/sourcerer/examples)
|
|
38
|
+
- [Migration Guide](https://vielzeug.dev/sourcerer/migration)
|
|
40
39
|
|
|
41
40
|
## License
|
|
42
41
|
|
|
43
|
-
MIT © Helmuth Saatkamp — part of Vielzeug.
|
|
42
|
+
MIT © [Helmuth Saatkamp](https://github.com/helmuthdu) — part of the [Vielzeug](https://github.com/helmuthdu/vielzeug) monorepo.
|
package/dist/asyncSource.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./
|
|
1
|
+
const e=require("./errors.cjs"),t=require("./requestController.cjs"),n=require("./sourceStore.cjs");let r=require("@vielzeug/arsenal");var loadWithSignal=(e,t)=>new Promise((n,i)=>{let abort=()=>i((0,r.abortError)(t,`The operation was aborted.`));if(t.aborted){abort();return}t.addEventListener(`abort`,abort,{once:!0});let a;try{a=e(t)}catch(e){t.removeEventListener(`abort`,abort),i(e);return}a.then(e=>{t.removeEventListener(`abort`,abort),n(e)},e=>{t.removeEventListener(`abort`,abort),i(e)})});function createAsyncSource(r){let i=n.createSourceStore(r),a=t.createRequestController();return{get disposalSignal(){return i.disposalSignal},dispose(){a.dispose(),i.dispose()},get disposed(){return i.disposed},async fetch(n){if(i.disposed)throw new e.SourcererDisposedError;let r=a.begin(),o=i.value;i.set(n.pending(o));try{let e=await loadWithSignal(n.load,r.signal);if(!r.isCurrent()||i.disposed)return;let t=n.success(e);n.commit?.(t,e),i.set(t)}catch(e){if(!r.isCurrent()||i.disposed)return;let a=t.toError(e);throw i.set(n.failure(o,a)),a}finally{r.finish()}},get state(){return i.value},subscribe:i.subscribe}}exports.createAsyncSource=createAsyncSource;
|
|
2
2
|
//# sourceMappingURL=asyncSource.cjs.map
|
package/dist/asyncSource.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asyncSource.cjs","names":[],"sources":["../src/asyncSource.ts"],"sourcesContent":["import { createRequestController, toError } from './requestController';\nimport { createSourceStore } from './sourceStore';\
|
|
1
|
+
{"version":3,"file":"asyncSource.cjs","names":[],"sources":["../src/asyncSource.ts"],"sourcesContent":["import { abortError } from '@vielzeug/arsenal';\n\nimport { SourcererDisposedError } from './errors';\nimport { createRequestController, toError } from './requestController';\nimport { createSourceStore } from './sourceStore';\n\nconst loadWithSignal = <T>(load: (signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T> =>\n new Promise((resolve, reject) => {\n const abort = (): void => reject(abortError(signal, 'The operation was aborted.'));\n if (signal.aborted) {\n abort();\n return;\n }\n\n signal.addEventListener('abort', abort, { once: true });\n let result: Promise<T>;\n try {\n result = load(signal);\n } catch (error) {\n signal.removeEventListener('abort', abort);\n reject(error);\n return;\n }\n\n result.then(\n (value) => {\n signal.removeEventListener('abort', abort);\n resolve(value);\n },\n (error: unknown) => {\n signal.removeEventListener('abort', abort);\n reject(error);\n },\n );\n });\n\ntype FetchOptions<TState, TResult> = {\n load(signal: AbortSignal): Promise<TResult>;\n success(result: TResult): TState;\n commit?(state: TState, result: TResult): void;\n pending(previous: TState): TState;\n failure(previous: TState, error: Error): TState;\n};\n\ntype AsyncSource<TState> = Readonly<{\n readonly disposalSignal: AbortSignal;\n dispose(): void;\n readonly disposed: boolean;\n fetch<TResult>(options: FetchOptions<TState, TResult>): Promise<void>;\n readonly state: TState;\n subscribe(listener: (state: TState) => void): () => void;\n}>;\n\n/** Only the current request may commit; superseded work settles without changing source state. */\nexport function createAsyncSource<TState>(initial: TState): AsyncSource<TState> {\n const store = createSourceStore(initial);\n const requests = createRequestController();\n\n return {\n get disposalSignal() {\n return store.disposalSignal;\n },\n\n dispose() {\n requests.dispose();\n store.dispose();\n },\n\n get disposed() {\n return store.disposed;\n },\n\n async fetch(options) {\n if (store.disposed) throw new SourcererDisposedError();\n\n const request = requests.begin();\n const previous = store.value;\n store.set(options.pending(previous));\n\n try {\n const result = await loadWithSignal(options.load, request.signal);\n if (!request.isCurrent() || store.disposed) return;\n\n const state = options.success(result);\n options.commit?.(state, result);\n store.set(state);\n } catch (reason: unknown) {\n if (!request.isCurrent() || store.disposed) return;\n\n const error = toError(reason);\n store.set(options.failure(previous, error));\n throw error;\n } finally {\n request.finish();\n }\n },\n\n get state() {\n return store.value;\n },\n\n subscribe: store.subscribe,\n };\n}\n"],"mappings":"uIAMA,IAAM,gBAAqB,EAA2C,IACpE,IAAI,SAAS,EAAS,IAAW,CAC/B,IAAM,UAAoB,GAAA,EAAO,EAAA,WAAA,CAAW,EAAQ,4BAA4B,CAAC,EACjF,GAAI,EAAO,QAAS,CAClB,MAAM,EACN,MACF,CAEA,EAAO,iBAAiB,QAAS,MAAO,CAAE,KAAM,EAAK,CAAC,EACtD,IAAI,EACJ,GAAI,CACF,EAAS,EAAK,CAAM,CACtB,OAAS,EAAO,CACd,EAAO,oBAAoB,QAAS,KAAK,EACzC,EAAO,CAAK,EACZ,MACF,CAEA,EAAO,KACJ,GAAU,CACT,EAAO,oBAAoB,QAAS,KAAK,EACzC,EAAQ,CAAK,CACf,EACC,GAAmB,CAClB,EAAO,oBAAoB,QAAS,KAAK,EACzC,EAAO,CAAK,CACd,CACF,CACF,CAAC,EAoBH,SAAgB,kBAA0B,EAAsC,CAC9E,IAAM,EAAQ,EAAA,kBAAkB,CAAO,EACjC,EAAW,EAAA,wBAAwB,EAEzC,MAAO,CACL,IAAI,gBAAiB,CACnB,OAAO,EAAM,cACf,EAEA,SAAU,CACR,EAAS,QAAQ,EACjB,EAAM,QAAQ,CAChB,EAEA,IAAI,UAAW,CACb,OAAO,EAAM,QACf,EAEA,MAAM,MAAM,EAAS,CACnB,GAAI,EAAM,SAAU,MAAM,IAAI,EAAA,uBAE9B,IAAM,EAAU,EAAS,MAAM,EACzB,EAAW,EAAM,MACvB,EAAM,IAAI,EAAQ,QAAQ,CAAQ,CAAC,EAEnC,GAAI,CACF,IAAM,EAAS,MAAM,eAAe,EAAQ,KAAM,EAAQ,MAAM,EAChE,GAAI,CAAC,EAAQ,UAAU,GAAK,EAAM,SAAU,OAE5C,IAAM,EAAQ,EAAQ,QAAQ,CAAM,EACpC,EAAQ,SAAS,EAAO,CAAM,EAC9B,EAAM,IAAI,CAAK,CACjB,OAAS,EAAiB,CACxB,GAAI,CAAC,EAAQ,UAAU,GAAK,EAAM,SAAU,OAE5C,IAAM,EAAQ,EAAA,QAAQ,CAAM,EAE5B,MADA,EAAM,IAAI,EAAQ,QAAQ,EAAU,CAAK,CAAC,EACpC,CACR,QAAU,CACR,EAAQ,OAAO,CACjB,CACF,EAEA,IAAI,OAAQ,CACV,OAAO,EAAM,KACf,EAEA,UAAW,EAAM,SACnB,CACF"}
|
package/dist/asyncSource.d.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
type FetchOptions<T, TQuery, TPagination extends AnyPagination, TResult> = {
|
|
3
|
-
query: TQuery;
|
|
1
|
+
type FetchOptions<TState, TResult> = {
|
|
4
2
|
load(signal: AbortSignal): Promise<TResult>;
|
|
5
|
-
success(result: TResult):
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
success(result: TResult): TState;
|
|
4
|
+
commit?(state: TState, result: TResult): void;
|
|
5
|
+
pending(previous: TState): TState;
|
|
6
|
+
failure(previous: TState, error: Error): TState;
|
|
8
7
|
};
|
|
9
|
-
type AsyncSource<
|
|
8
|
+
type AsyncSource<TState> = Readonly<{
|
|
10
9
|
readonly disposalSignal: AbortSignal;
|
|
11
10
|
dispose(): void;
|
|
12
11
|
readonly disposed: boolean;
|
|
13
|
-
fetch<TResult>(options: FetchOptions<
|
|
14
|
-
readonly
|
|
15
|
-
subscribe(listener: (
|
|
12
|
+
fetch<TResult>(options: FetchOptions<TState, TResult>): Promise<void>;
|
|
13
|
+
readonly state: TState;
|
|
14
|
+
subscribe(listener: (state: TState) => void): () => void;
|
|
16
15
|
}>;
|
|
17
|
-
/**
|
|
18
|
-
export declare function createAsyncSource<
|
|
16
|
+
/** Only the current request may commit; superseded work settles without changing source state. */
|
|
17
|
+
export declare function createAsyncSource<TState>(initial: TState): AsyncSource<TState>;
|
|
19
18
|
export {};
|
|
20
19
|
//# sourceMappingURL=asyncSource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asyncSource.d.ts","sourceRoot":"","sources":["../src/asyncSource.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"asyncSource.d.ts","sourceRoot":"","sources":["../src/asyncSource.ts"],"names":[],"mappings":"AAoCA,KAAK,YAAY,CAAC,MAAM,EAAE,OAAO,IAAI;IACnC,IAAI,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;IACjC,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9C,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;CACjD,CAAC;AAEF,KAAK,WAAW,CAAC,MAAM,IAAI,QAAQ,CAAC;IAClC,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC;IACrC,OAAO,IAAI,IAAI,CAAC;IAChB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CAC1D,CAAC,CAAC;AAEH,kGAAkG;AAClG,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAiD9E"}
|
package/dist/asyncSource.js
CHANGED
|
@@ -1,51 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createSourceStore as n } from "./sourceStore.js";
|
|
3
|
-
//#region src/asyncSource.ts
|
|
4
|
-
function r(r) {
|
|
5
|
-
let i = n(r), a = e();
|
|
6
|
-
return {
|
|
7
|
-
get disposalSignal() {
|
|
8
|
-
return i.disposalSignal;
|
|
9
|
-
},
|
|
10
|
-
dispose() {
|
|
11
|
-
a.dispose(), i.dispose();
|
|
12
|
-
},
|
|
13
|
-
get disposed() {
|
|
14
|
-
return i.disposed;
|
|
15
|
-
},
|
|
16
|
-
async fetch(e) {
|
|
17
|
-
if (i.disposed) return;
|
|
18
|
-
let { query: n, load: r, success: o, pending: s, failure: c } = e, l = a.begin(), u = i.value;
|
|
19
|
-
i.set(s ? s(u) : {
|
|
20
|
-
...u,
|
|
21
|
-
error: null,
|
|
22
|
-
isFetching: !0,
|
|
23
|
-
pendingQuery: n
|
|
24
|
-
});
|
|
25
|
-
let d;
|
|
26
|
-
try {
|
|
27
|
-
d = o(await r(l.signal));
|
|
28
|
-
} catch (e) {
|
|
29
|
-
if (!l.isCurrent() || i.disposed) return;
|
|
30
|
-
let n = t(e);
|
|
31
|
-
throw i.set(c ? c(u, n) : {
|
|
32
|
-
...u,
|
|
33
|
-
error: n,
|
|
34
|
-
isFetching: !1,
|
|
35
|
-
pendingQuery: void 0
|
|
36
|
-
}), n;
|
|
37
|
-
} finally {
|
|
38
|
-
l.finish();
|
|
39
|
-
}
|
|
40
|
-
!l.isCurrent() || i.disposed || i.set(d);
|
|
41
|
-
},
|
|
42
|
-
get snapshot() {
|
|
43
|
-
return i.value;
|
|
44
|
-
},
|
|
45
|
-
subscribe: i.subscribe
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
//#endregion
|
|
49
|
-
export { r as createAsyncSource };
|
|
50
|
-
|
|
1
|
+
import{SourcererDisposedError as e}from"./errors.js";import{createRequestController as t,toError as n}from"./requestController.js";import{createSourceStore as r}from"./sourceStore.js";import{abortError as i}from"@vielzeug/arsenal";var loadWithSignal=(e,t)=>new Promise((n,r)=>{let abort=()=>r(i(t,`The operation was aborted.`));if(t.aborted){abort();return}t.addEventListener(`abort`,abort,{once:!0});let a;try{a=e(t)}catch(e){t.removeEventListener(`abort`,abort),r(e);return}a.then(e=>{t.removeEventListener(`abort`,abort),n(e)},e=>{t.removeEventListener(`abort`,abort),r(e)})});function createAsyncSource(i){let a=r(i),o=t();return{get disposalSignal(){return a.disposalSignal},dispose(){o.dispose(),a.dispose()},get disposed(){return a.disposed},async fetch(t){if(a.disposed)throw new e;let r=o.begin(),i=a.value;a.set(t.pending(i));try{let e=await loadWithSignal(t.load,r.signal);if(!r.isCurrent()||a.disposed)return;let n=t.success(e);t.commit?.(n,e),a.set(n)}catch(e){if(!r.isCurrent()||a.disposed)return;let o=n(e);throw a.set(t.failure(i,o)),o}finally{r.finish()}},get state(){return a.value},subscribe:a.subscribe}}export{createAsyncSource};
|
|
51
2
|
//# sourceMappingURL=asyncSource.js.map
|
package/dist/asyncSource.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asyncSource.js","names":[],"sources":["../src/asyncSource.ts"],"sourcesContent":["import { createRequestController, toError } from './requestController';\nimport { createSourceStore } from './sourceStore';\
|
|
1
|
+
{"version":3,"file":"asyncSource.js","names":[],"sources":["../src/asyncSource.ts"],"sourcesContent":["import { abortError } from '@vielzeug/arsenal';\n\nimport { SourcererDisposedError } from './errors';\nimport { createRequestController, toError } from './requestController';\nimport { createSourceStore } from './sourceStore';\n\nconst loadWithSignal = <T>(load: (signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T> =>\n new Promise((resolve, reject) => {\n const abort = (): void => reject(abortError(signal, 'The operation was aborted.'));\n if (signal.aborted) {\n abort();\n return;\n }\n\n signal.addEventListener('abort', abort, { once: true });\n let result: Promise<T>;\n try {\n result = load(signal);\n } catch (error) {\n signal.removeEventListener('abort', abort);\n reject(error);\n return;\n }\n\n result.then(\n (value) => {\n signal.removeEventListener('abort', abort);\n resolve(value);\n },\n (error: unknown) => {\n signal.removeEventListener('abort', abort);\n reject(error);\n },\n );\n });\n\ntype FetchOptions<TState, TResult> = {\n load(signal: AbortSignal): Promise<TResult>;\n success(result: TResult): TState;\n commit?(state: TState, result: TResult): void;\n pending(previous: TState): TState;\n failure(previous: TState, error: Error): TState;\n};\n\ntype AsyncSource<TState> = Readonly<{\n readonly disposalSignal: AbortSignal;\n dispose(): void;\n readonly disposed: boolean;\n fetch<TResult>(options: FetchOptions<TState, TResult>): Promise<void>;\n readonly state: TState;\n subscribe(listener: (state: TState) => void): () => void;\n}>;\n\n/** Only the current request may commit; superseded work settles without changing source state. */\nexport function createAsyncSource<TState>(initial: TState): AsyncSource<TState> {\n const store = createSourceStore(initial);\n const requests = createRequestController();\n\n return {\n get disposalSignal() {\n return store.disposalSignal;\n },\n\n dispose() {\n requests.dispose();\n store.dispose();\n },\n\n get disposed() {\n return store.disposed;\n },\n\n async fetch(options) {\n if (store.disposed) throw new SourcererDisposedError();\n\n const request = requests.begin();\n const previous = store.value;\n store.set(options.pending(previous));\n\n try {\n const result = await loadWithSignal(options.load, request.signal);\n if (!request.isCurrent() || store.disposed) return;\n\n const state = options.success(result);\n options.commit?.(state, result);\n store.set(state);\n } catch (reason: unknown) {\n if (!request.isCurrent() || store.disposed) return;\n\n const error = toError(reason);\n store.set(options.failure(previous, error));\n throw error;\n } finally {\n request.finish();\n }\n },\n\n get state() {\n return store.value;\n },\n\n subscribe: store.subscribe,\n };\n}\n"],"mappings":"uOAMA,IAAM,gBAAqB,EAA2C,IACpE,IAAI,SAAS,EAAS,IAAW,CAC/B,IAAM,UAAoB,EAAO,EAAW,EAAQ,4BAA4B,CAAC,EACjF,GAAI,EAAO,QAAS,CAClB,MAAM,EACN,MACF,CAEA,EAAO,iBAAiB,QAAS,MAAO,CAAE,KAAM,EAAK,CAAC,EACtD,IAAI,EACJ,GAAI,CACF,EAAS,EAAK,CAAM,CACtB,OAAS,EAAO,CACd,EAAO,oBAAoB,QAAS,KAAK,EACzC,EAAO,CAAK,EACZ,MACF,CAEA,EAAO,KACJ,GAAU,CACT,EAAO,oBAAoB,QAAS,KAAK,EACzC,EAAQ,CAAK,CACf,EACC,GAAmB,CAClB,EAAO,oBAAoB,QAAS,KAAK,EACzC,EAAO,CAAK,CACd,CACF,CACF,CAAC,EAoBH,SAAgB,kBAA0B,EAAsC,CAC9E,IAAM,EAAQ,EAAkB,CAAO,EACjC,EAAW,EAAwB,EAEzC,MAAO,CACL,IAAI,gBAAiB,CACnB,OAAO,EAAM,cACf,EAEA,SAAU,CACR,EAAS,QAAQ,EACjB,EAAM,QAAQ,CAChB,EAEA,IAAI,UAAW,CACb,OAAO,EAAM,QACf,EAEA,MAAM,MAAM,EAAS,CACnB,GAAI,EAAM,SAAU,MAAM,IAAI,EAE9B,IAAM,EAAU,EAAS,MAAM,EACzB,EAAW,EAAM,MACvB,EAAM,IAAI,EAAQ,QAAQ,CAAQ,CAAC,EAEnC,GAAI,CACF,IAAM,EAAS,MAAM,eAAe,EAAQ,KAAM,EAAQ,MAAM,EAChE,GAAI,CAAC,EAAQ,UAAU,GAAK,EAAM,SAAU,OAE5C,IAAM,EAAQ,EAAQ,QAAQ,CAAM,EACpC,EAAQ,SAAS,EAAO,CAAM,EAC9B,EAAM,IAAI,CAAK,CACjB,OAAS,EAAiB,CACxB,GAAI,CAAC,EAAQ,UAAU,GAAK,EAAM,SAAU,OAE5C,IAAM,EAAQ,EAAQ,CAAM,EAE5B,MADA,EAAM,IAAI,EAAQ,QAAQ,EAAU,CAAK,CAAC,EACpC,CACR,QAAU,CACR,EAAQ,OAAO,CACjB,CACF,EAEA,IAAI,OAAQ,CACV,OAAO,EAAM,KACf,EAEA,UAAW,EAAM,SACnB,CACF"}
|
package/dist/cursorSource.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./
|
|
1
|
+
const e=require("./errors.cjs"),t=require("./asyncSource.cjs"),n=require("./pagination.cjs");var createPagination=(e,t)=>({...t?.nextCursor!==void 0&&{nextCursor:t.nextCursor},pageSize:e,...t?.previousCursor!==void 0&&{previousCursor:t.previousCursor},...t?.totalItems!==void 0&&{totalItems:n.totalItems(t.totalItems)}});function createCursorSource(r){if(r.after!==void 0&&r.before!==void 0)throw new e.SourcererConfigurationError(`Cursor source cannot start with both after and before`);let i={...r.after!==void 0&&{after:r.after},...r.before!==void 0&&{before:r.before},pageSize:n.positiveInteger(r.pageSize??20,`pageSize`),params:r.params},a=t.createAsyncSource({error:null,items:[],loading:!1,pagination:createPagination(i.pageSize),params:i.params}),assertLive=()=>{if(a.disposed)throw new e.SourcererDisposedError},fetch=e=>a.fetch({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:createPagination(e.pageSize,t),params:e.params})}),o={get disposalSignal(){return a.disposalSignal},dispose:a.dispose,get disposed(){return a.disposed},async next(){assertLive();let e=a.state.pagination.nextCursor;a.state.loading||e===void 0||(i={after:e,pageSize:i.pageSize,params:i.params},await fetch(i))},async previous(){assertLive();let e=a.state.pagination.previousCursor;a.state.loading||e===void 0||(i={before:e,pageSize:i.pageSize,params:i.params},await fetch(i))},reload(){return fetch(i)},async setPageSize(e){assertLive();let t=n.positiveInteger(e,`pageSize`);if(t===i.pageSize&&i.after===void 0&&i.before===void 0){if(a.state.loading||a.state.pagination.pageSize===t&&Object.is(a.state.params,i.params))return;await fetch(i);return}i={pageSize:t,params:i.params},await fetch(i)},async setParams(e){if(assertLive(),Object.is(e,i.params)){!a.state.loading&&!Object.is(e,a.state.params)&&await fetch(i);return}i={pageSize:i.pageSize,params:e},await fetch(i)},get state(){return a.state},subscribe:a.subscribe,[Symbol.dispose](){o.dispose()}};return o}exports.createCursorSource=createCursorSource;
|
|
2
2
|
//# sourceMappingURL=cursorSource.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cursorSource.cjs","names":[],"sources":["../src/cursorSource.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"cursorSource.cjs","names":[],"sources":["../src/cursorSource.ts"],"sourcesContent":["import { createAsyncSource } from './asyncSource';\nimport { SourcererConfigurationError, SourcererDisposedError } from './errors';\nimport { positiveInteger, totalItems } from './pagination';\nimport type { CursorPagination, CursorResult, CursorSource, CursorSourceConfig, CursorSourceState } from './types';\n\ntype Request<TParams, TCursor> = Readonly<{\n after?: TCursor;\n before?: TCursor;\n pageSize: number;\n params: TParams;\n}>;\n\nconst createPagination = <TCursor>(\n pageSize: number,\n result?: CursorResult<unknown, TCursor>,\n): CursorPagination<TCursor> => ({\n ...(result?.nextCursor !== undefined && { nextCursor: result.nextCursor }),\n pageSize,\n ...(result?.previousCursor !== undefined && { previousCursor: result.previousCursor }),\n ...(result?.totalItems !== undefined && { totalItems: totalItems(result.totalItems) }),\n});\n\n/** Cursor sources retain committed items and cursors while replacement work is pending. */\nexport function createCursorSource<T, TParams = undefined, TCursor = string>(\n config: CursorSourceConfig<T, TParams, TCursor>,\n): CursorSource<T, TParams, TCursor> {\n if (config.after !== undefined && config.before !== undefined) {\n throw new SourcererConfigurationError('Cursor source cannot start with both after and before');\n }\n\n let requested: Request<TParams, TCursor> = {\n ...(config.after !== undefined && { after: config.after }),\n ...(config.before !== undefined && { before: config.before }),\n pageSize: positiveInteger(config.pageSize ?? 20, 'pageSize'),\n params: config.params as TParams,\n };\n const asyncSource = createAsyncSource<CursorSourceState<T, TParams, TCursor>>({\n error: null,\n items: [],\n loading: false,\n pagination: createPagination(requested.pageSize),\n params: requested.params,\n });\n const assertLive = (): void => {\n if (asyncSource.disposed) throw new SourcererDisposedError();\n };\n\n const fetch = (request: Request<TParams, TCursor>): Promise<void> =>\n asyncSource.fetch({\n failure: (previous, error) => ({ ...previous, error, loading: false, pendingParams: undefined }),\n load: (signal) => config.load({ ...request, signal }),\n pending: (previous) => ({\n ...previous,\n error: null,\n loading: true,\n ...(Object.is(request.params, previous.params) ? {} : { pendingParams: request.params }),\n }),\n success: (result) => ({\n error: null,\n items: [...result.items],\n loading: false,\n pagination: createPagination(request.pageSize, result),\n params: request.params,\n }),\n });\n\n const source: CursorSource<T, TParams, TCursor> = {\n get disposalSignal() {\n return asyncSource.disposalSignal;\n },\n\n dispose: asyncSource.dispose,\n\n get disposed() {\n return asyncSource.disposed;\n },\n\n async next() {\n assertLive();\n const cursor = asyncSource.state.pagination.nextCursor;\n if (asyncSource.state.loading || cursor === undefined) return;\n requested = { after: cursor, pageSize: requested.pageSize, params: requested.params };\n await fetch(requested);\n },\n\n async previous() {\n assertLive();\n const cursor = asyncSource.state.pagination.previousCursor;\n if (asyncSource.state.loading || cursor === undefined) return;\n requested = { before: cursor, pageSize: requested.pageSize, params: requested.params };\n await fetch(requested);\n },\n\n reload() {\n return fetch(requested);\n },\n\n async setPageSize(pageSize) {\n assertLive();\n const normalized = positiveInteger(pageSize, 'pageSize');\n if (normalized === requested.pageSize && requested.after === undefined && requested.before === undefined) {\n if (\n asyncSource.state.loading ||\n (asyncSource.state.pagination.pageSize === normalized &&\n Object.is(asyncSource.state.params, requested.params))\n )\n return;\n await fetch(requested);\n return;\n }\n requested = { pageSize: normalized, params: requested.params };\n await fetch(requested);\n },\n\n async setParams(params) {\n assertLive();\n if (Object.is(params, requested.params)) {\n if (!asyncSource.state.loading && !Object.is(params, asyncSource.state.params)) await fetch(requested);\n return;\n }\n requested = { pageSize: requested.pageSize, params };\n await fetch(requested);\n },\n\n get state() {\n return asyncSource.state;\n },\n\n subscribe: asyncSource.subscribe,\n\n [Symbol.dispose]() {\n source.dispose();\n },\n };\n\n return source;\n}\n"],"mappings":"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"}
|
package/dist/cursorSource.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { CursorSource, CursorSourceConfig } from './types';
|
|
2
|
-
/** Cursor sources retain
|
|
3
|
-
export declare function createCursorSource<T, TCursor = string>(config: CursorSourceConfig<T, TCursor>): CursorSource<T, TCursor>;
|
|
2
|
+
/** Cursor sources retain committed items and cursors while replacement work is pending. */
|
|
3
|
+
export declare function createCursorSource<T, TParams = undefined, TCursor = string>(config: CursorSourceConfig<T, TParams, TCursor>): CursorSource<T, TParams, TCursor>;
|
|
4
4
|
//# sourceMappingURL=cursorSource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cursorSource.d.ts","sourceRoot":"","sources":["../src/cursorSource.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cursorSource.d.ts","sourceRoot":"","sources":["../src/cursorSource.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAkC,YAAY,EAAE,kBAAkB,EAAqB,MAAM,SAAS,CAAC;AAmBnH,2FAA2F;AAC3F,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS,EAAE,OAAO,GAAG,MAAM,EACzE,MAAM,EAAE,kBAAkB,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,GAC9C,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CA+GnC"}
|
package/dist/cursorSource.js
CHANGED
|
@@ -1,82 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createAsyncSource as t } from "./asyncSource.js";
|
|
3
|
-
import { SourcererConfigurationError as n } from "./errors.js";
|
|
4
|
-
import { positiveInteger as r, sameQuery as i, totalItems as a } from "./pagination.js";
|
|
5
|
-
//#region src/cursorSource.ts
|
|
6
|
-
var o = (e) => ({
|
|
7
|
-
hasNext: e?.nextCursor !== void 0,
|
|
8
|
-
hasPrevious: e?.previousCursor !== void 0,
|
|
9
|
-
kind: "cursor",
|
|
10
|
-
...e?.nextCursor !== void 0 && { nextCursor: e.nextCursor },
|
|
11
|
-
...e?.previousCursor !== void 0 && { previousCursor: e.previousCursor },
|
|
12
|
-
...e?.total !== void 0 && { total: a(e.total) }
|
|
13
|
-
}), s = (e, t = {}) => {
|
|
14
|
-
if (t.after !== void 0 && t.before !== void 0) throw new n("Cursor query cannot include both after and before");
|
|
15
|
-
let i = t.pageSize !== void 0 || t.search !== void 0, a = i || "before" in t ? void 0 : "after" in t ? t.after : e.after, o = i || "after" in t ? void 0 : "before" in t ? t.before : e.before;
|
|
16
|
-
return {
|
|
17
|
-
...a !== void 0 && { after: a },
|
|
18
|
-
...o !== void 0 && { before: o },
|
|
19
|
-
pageSize: r(t.pageSize ?? e.pageSize, "pageSize"),
|
|
20
|
-
search: t.search ?? e.search
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
function c(n) {
|
|
24
|
-
let r = s({
|
|
25
|
-
pageSize: 20,
|
|
26
|
-
search: ""
|
|
27
|
-
}, n.initialQuery), a = t({
|
|
28
|
-
data: [],
|
|
29
|
-
error: null,
|
|
30
|
-
isFetching: !1,
|
|
31
|
-
pagination: o(),
|
|
32
|
-
query: r
|
|
33
|
-
}), c = (e) => a.fetch({
|
|
34
|
-
load: (t) => n.load({
|
|
35
|
-
query: e,
|
|
36
|
-
signal: t
|
|
37
|
-
}),
|
|
38
|
-
query: e,
|
|
39
|
-
success: (t) => ({
|
|
40
|
-
data: t.data,
|
|
41
|
-
error: null,
|
|
42
|
-
isFetching: !1,
|
|
43
|
-
pagination: o(t),
|
|
44
|
-
query: e
|
|
45
|
-
})
|
|
46
|
-
}), l = () => c(r), u = async (e) => {
|
|
47
|
-
let t = s(a.snapshot.pendingQuery ?? a.snapshot.query, e);
|
|
48
|
-
i(t, r) || (r = t, await c(t));
|
|
49
|
-
}, d = {
|
|
50
|
-
get disposalSignal() {
|
|
51
|
-
return a.disposalSignal;
|
|
52
|
-
},
|
|
53
|
-
dispose: a.dispose,
|
|
54
|
-
get disposed() {
|
|
55
|
-
return a.disposed;
|
|
56
|
-
},
|
|
57
|
-
page: {
|
|
58
|
-
next() {
|
|
59
|
-
let e = a.snapshot.pagination.nextCursor;
|
|
60
|
-
return a.snapshot.isFetching || e === void 0 ? Promise.resolve() : u({ after: e });
|
|
61
|
-
},
|
|
62
|
-
previous() {
|
|
63
|
-
let e = a.snapshot.pagination.previousCursor;
|
|
64
|
-
return a.snapshot.isFetching || e === void 0 ? Promise.resolve() : u({ before: e });
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
reload: l,
|
|
68
|
-
setQuery: u,
|
|
69
|
-
get snapshot() {
|
|
70
|
-
return a.snapshot;
|
|
71
|
-
},
|
|
72
|
-
subscribe: a.subscribe,
|
|
73
|
-
[Symbol.dispose]() {
|
|
74
|
-
d.dispose();
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
return n.autoStart !== !1 && l().catch(() => /* @__PURE__ */ e("Initial load failed. Inspect source.snapshot.error.")), d;
|
|
78
|
-
}
|
|
79
|
-
//#endregion
|
|
80
|
-
export { c as createCursorSource };
|
|
81
|
-
|
|
1
|
+
import{SourcererConfigurationError as e,SourcererDisposedError as t}from"./errors.js";import{createAsyncSource as n}from"./asyncSource.js";import{positiveInteger as r,totalItems as i}from"./pagination.js";var createPagination=(e,t)=>({...t?.nextCursor!==void 0&&{nextCursor:t.nextCursor},pageSize:e,...t?.previousCursor!==void 0&&{previousCursor:t.previousCursor},...t?.totalItems!==void 0&&{totalItems:i(t.totalItems)}});function createCursorSource(i){if(i.after!==void 0&&i.before!==void 0)throw new e(`Cursor source cannot start with both after and before`);let a={...i.after!==void 0&&{after:i.after},...i.before!==void 0&&{before:i.before},pageSize:r(i.pageSize??20,`pageSize`),params:i.params},o=n({error:null,items:[],loading:!1,pagination:createPagination(a.pageSize),params:a.params}),assertLive=()=>{if(o.disposed)throw new t},fetch=e=>o.fetch({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:createPagination(e.pageSize,t),params:e.params})}),s={get disposalSignal(){return o.disposalSignal},dispose:o.dispose,get disposed(){return o.disposed},async next(){assertLive();let e=o.state.pagination.nextCursor;o.state.loading||e===void 0||(a={after:e,pageSize:a.pageSize,params:a.params},await fetch(a))},async previous(){assertLive();let e=o.state.pagination.previousCursor;o.state.loading||e===void 0||(a={before:e,pageSize:a.pageSize,params:a.params},await fetch(a))},reload(){return fetch(a)},async setPageSize(e){assertLive();let t=r(e,`pageSize`);if(t===a.pageSize&&a.after===void 0&&a.before===void 0){if(o.state.loading||o.state.pagination.pageSize===t&&Object.is(o.state.params,a.params))return;await fetch(a);return}a={pageSize:t,params:a.params},await fetch(a)},async setParams(e){if(assertLive(),Object.is(e,a.params)){!o.state.loading&&!Object.is(e,o.state.params)&&await fetch(a);return}a={pageSize:a.pageSize,params:e},await fetch(a)},get state(){return o.state},subscribe:o.subscribe,[Symbol.dispose](){s.dispose()}};return s}export{createCursorSource};
|
|
82
2
|
//# sourceMappingURL=cursorSource.js.map
|
package/dist/cursorSource.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cursorSource.js","names":[],"sources":["../src/cursorSource.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"cursorSource.js","names":[],"sources":["../src/cursorSource.ts"],"sourcesContent":["import { createAsyncSource } from './asyncSource';\nimport { SourcererConfigurationError, SourcererDisposedError } from './errors';\nimport { positiveInteger, totalItems } from './pagination';\nimport type { CursorPagination, CursorResult, CursorSource, CursorSourceConfig, CursorSourceState } from './types';\n\ntype Request<TParams, TCursor> = Readonly<{\n after?: TCursor;\n before?: TCursor;\n pageSize: number;\n params: TParams;\n}>;\n\nconst createPagination = <TCursor>(\n pageSize: number,\n result?: CursorResult<unknown, TCursor>,\n): CursorPagination<TCursor> => ({\n ...(result?.nextCursor !== undefined && { nextCursor: result.nextCursor }),\n pageSize,\n ...(result?.previousCursor !== undefined && { previousCursor: result.previousCursor }),\n ...(result?.totalItems !== undefined && { totalItems: totalItems(result.totalItems) }),\n});\n\n/** Cursor sources retain committed items and cursors while replacement work is pending. */\nexport function createCursorSource<T, TParams = undefined, TCursor = string>(\n config: CursorSourceConfig<T, TParams, TCursor>,\n): CursorSource<T, TParams, TCursor> {\n if (config.after !== undefined && config.before !== undefined) {\n throw new SourcererConfigurationError('Cursor source cannot start with both after and before');\n }\n\n let requested: Request<TParams, TCursor> = {\n ...(config.after !== undefined && { after: config.after }),\n ...(config.before !== undefined && { before: config.before }),\n pageSize: positiveInteger(config.pageSize ?? 20, 'pageSize'),\n params: config.params as TParams,\n };\n const asyncSource = createAsyncSource<CursorSourceState<T, TParams, TCursor>>({\n error: null,\n items: [],\n loading: false,\n pagination: createPagination(requested.pageSize),\n params: requested.params,\n });\n const assertLive = (): void => {\n if (asyncSource.disposed) throw new SourcererDisposedError();\n };\n\n const fetch = (request: Request<TParams, TCursor>): Promise<void> =>\n asyncSource.fetch({\n failure: (previous, error) => ({ ...previous, error, loading: false, pendingParams: undefined }),\n load: (signal) => config.load({ ...request, signal }),\n pending: (previous) => ({\n ...previous,\n error: null,\n loading: true,\n ...(Object.is(request.params, previous.params) ? {} : { pendingParams: request.params }),\n }),\n success: (result) => ({\n error: null,\n items: [...result.items],\n loading: false,\n pagination: createPagination(request.pageSize, result),\n params: request.params,\n }),\n });\n\n const source: CursorSource<T, TParams, TCursor> = {\n get disposalSignal() {\n return asyncSource.disposalSignal;\n },\n\n dispose: asyncSource.dispose,\n\n get disposed() {\n return asyncSource.disposed;\n },\n\n async next() {\n assertLive();\n const cursor = asyncSource.state.pagination.nextCursor;\n if (asyncSource.state.loading || cursor === undefined) return;\n requested = { after: cursor, pageSize: requested.pageSize, params: requested.params };\n await fetch(requested);\n },\n\n async previous() {\n assertLive();\n const cursor = asyncSource.state.pagination.previousCursor;\n if (asyncSource.state.loading || cursor === undefined) return;\n requested = { before: cursor, pageSize: requested.pageSize, params: requested.params };\n await fetch(requested);\n },\n\n reload() {\n return fetch(requested);\n },\n\n async setPageSize(pageSize) {\n assertLive();\n const normalized = positiveInteger(pageSize, 'pageSize');\n if (normalized === requested.pageSize && requested.after === undefined && requested.before === undefined) {\n if (\n asyncSource.state.loading ||\n (asyncSource.state.pagination.pageSize === normalized &&\n Object.is(asyncSource.state.params, requested.params))\n )\n return;\n await fetch(requested);\n return;\n }\n requested = { pageSize: normalized, params: requested.params };\n await fetch(requested);\n },\n\n async setParams(params) {\n assertLive();\n if (Object.is(params, requested.params)) {\n if (!asyncSource.state.loading && !Object.is(params, asyncSource.state.params)) await fetch(requested);\n return;\n }\n requested = { pageSize: requested.pageSize, params };\n await fetch(requested);\n },\n\n get state() {\n return asyncSource.state;\n },\n\n subscribe: asyncSource.subscribe,\n\n [Symbol.dispose]() {\n source.dispose();\n },\n };\n\n return source;\n}\n"],"mappings":"6MAYA,IAAM,kBACJ,EACA,KAC+B,CAC/B,GAAI,GAAQ,aAAe,IAAA,IAAa,CAAE,WAAY,EAAO,UAAW,EACxE,WACA,GAAI,GAAQ,iBAAmB,IAAA,IAAa,CAAE,eAAgB,EAAO,cAAe,EACpF,GAAI,GAAQ,aAAe,IAAA,IAAa,CAAE,WAAY,EAAW,EAAO,UAAU,CAAE,CACtF,GAGA,SAAgB,mBACd,EACmC,CACnC,GAAI,EAAO,QAAU,IAAA,IAAa,EAAO,SAAW,IAAA,GAClD,MAAM,IAAI,EAA4B,uDAAuD,EAG/F,IAAI,EAAuC,CACzC,GAAI,EAAO,QAAU,IAAA,IAAa,CAAE,MAAO,EAAO,KAAM,EACxD,GAAI,EAAO,SAAW,IAAA,IAAa,CAAE,OAAQ,EAAO,MAAO,EAC3D,SAAU,EAAgB,EAAO,UAAY,GAAI,UAAU,EAC3D,OAAQ,EAAO,MACjB,EACM,EAAc,EAA0D,CAC5E,MAAO,KACP,MAAO,CAAC,EACR,QAAS,GACT,WAAY,iBAAiB,EAAU,QAAQ,EAC/C,OAAQ,EAAU,MACpB,CAAC,EACK,eAAyB,CAC7B,GAAI,EAAY,SAAU,MAAM,IAAI,CACtC,EAEM,MAAS,GACb,EAAY,MAAM,CAChB,SAAU,EAAU,KAAW,CAAE,GAAG,EAAU,QAAO,QAAS,GAAO,cAAe,IAAA,EAAU,GAC9F,KAAO,GAAW,EAAO,KAAK,CAAE,GAAG,EAAS,QAAO,CAAC,EACpD,QAAU,IAAc,CACtB,GAAG,EACH,MAAO,KACP,QAAS,GACT,GAAI,OAAO,GAAG,EAAQ,OAAQ,EAAS,MAAM,EAAI,CAAC,EAAI,CAAE,cAAe,EAAQ,MAAO,CACxF,GACA,QAAU,IAAY,CACpB,MAAO,KACP,MAAO,CAAC,GAAG,EAAO,KAAK,EACvB,QAAS,GACT,WAAY,iBAAiB,EAAQ,SAAU,CAAM,EACrD,OAAQ,EAAQ,MAClB,EACF,CAAC,EAEG,EAA4C,CAChD,IAAI,gBAAiB,CACnB,OAAO,EAAY,cACrB,EAEA,QAAS,EAAY,QAErB,IAAI,UAAW,CACb,OAAO,EAAY,QACrB,EAEA,MAAM,MAAO,CACX,WAAW,EACX,IAAM,EAAS,EAAY,MAAM,WAAW,WACxC,EAAY,MAAM,SAAW,IAAW,IAAA,KAC5C,EAAY,CAAE,MAAO,EAAQ,SAAU,EAAU,SAAU,OAAQ,EAAU,MAAO,EACpF,MAAM,MAAM,CAAS,EACvB,EAEA,MAAM,UAAW,CACf,WAAW,EACX,IAAM,EAAS,EAAY,MAAM,WAAW,eACxC,EAAY,MAAM,SAAW,IAAW,IAAA,KAC5C,EAAY,CAAE,OAAQ,EAAQ,SAAU,EAAU,SAAU,OAAQ,EAAU,MAAO,EACrF,MAAM,MAAM,CAAS,EACvB,EAEA,QAAS,CACP,OAAO,MAAM,CAAS,CACxB,EAEA,MAAM,YAAY,EAAU,CAC1B,WAAW,EACX,IAAM,EAAa,EAAgB,EAAU,UAAU,EACvD,GAAI,IAAe,EAAU,UAAY,EAAU,QAAU,IAAA,IAAa,EAAU,SAAW,IAAA,GAAW,CACxG,GACE,EAAY,MAAM,SACjB,EAAY,MAAM,WAAW,WAAa,GACzC,OAAO,GAAG,EAAY,MAAM,OAAQ,EAAU,MAAM,EAEtD,OACF,MAAM,MAAM,CAAS,EACrB,MACF,CACA,EAAY,CAAE,SAAU,EAAY,OAAQ,EAAU,MAAO,EAC7D,MAAM,MAAM,CAAS,CACvB,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,MAAM,CAAS,EACrG,MACF,CACA,EAAY,CAAE,SAAU,EAAU,SAAU,QAAO,EACnD,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/errors.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var SourcererError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},SourcererConfigurationError=class extends SourcererError{},SourcererDisposedError=class extends SourcererError{constructor(e=`Sourcerer source disposed`){super(e)}};exports.SourcererConfigurationError=SourcererConfigurationError,exports.SourcererDisposedError=SourcererDisposedError,exports.SourcererError=SourcererError;
|
|
2
2
|
//# sourceMappingURL=errors.cjs.map
|
package/dist/errors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all sourcerer errors. Use `instanceof SourcererError` to catch any sourcerer-originated error. */\nexport class SourcererError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a source is configured or queried with invalid arguments. */\nexport class SourcererConfigurationError extends SourcererError {}\n"],"mappings":"AACA,IAAa,
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all sourcerer errors. Use `instanceof SourcererError` to catch any sourcerer-originated error. */\nexport class SourcererError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a source is configured or queried with invalid arguments. */\nexport class SourcererConfigurationError extends SourcererError {}\n\nexport class SourcererDisposedError extends SourcererError {\n constructor(message = 'Sourcerer source disposed') {\n super(message);\n }\n}\n"],"mappings":"AACA,IAAa,eAAb,cAAoC,KAAM,CACxC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,4BAAb,cAAiD,cAAe,CAAC,EAEpD,uBAAb,cAA4C,cAAe,CACzD,YAAY,EAAU,4BAA6B,CACjD,MAAM,CAAO,CACf,CACF"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -5,4 +5,7 @@ export declare class SourcererError extends Error {
|
|
|
5
5
|
/** Thrown when a source is configured or queried with invalid arguments. */
|
|
6
6
|
export declare class SourcererConfigurationError extends SourcererError {
|
|
7
7
|
}
|
|
8
|
+
export declare class SourcererDisposedError extends SourcererError {
|
|
9
|
+
constructor(message?: string);
|
|
10
|
+
}
|
|
8
11
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAED,4EAA4E;AAC5E,qBAAa,2BAA4B,SAAQ,cAAc;CAAG"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAED,4EAA4E;AAC5E,qBAAa,2BAA4B,SAAQ,cAAc;CAAG;AAElE,qBAAa,sBAAuB,SAAQ,cAAc;gBAC5C,OAAO,SAA8B;CAGlD"}
|
package/dist/errors.js
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var e = class extends Error {
|
|
3
|
-
constructor(e, t) {
|
|
4
|
-
super(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);
|
|
5
|
-
}
|
|
6
|
-
}, t = class extends e {};
|
|
7
|
-
//#endregion
|
|
8
|
-
export { t as SourcererConfigurationError, e as SourcererError };
|
|
9
|
-
|
|
1
|
+
var SourcererError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},SourcererConfigurationError=class extends SourcererError{},SourcererDisposedError=class extends SourcererError{constructor(e=`Sourcerer source disposed`){super(e)}};export{SourcererConfigurationError,SourcererDisposedError,SourcererError};
|
|
10
2
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all sourcerer errors. Use `instanceof SourcererError` to catch any sourcerer-originated error. */\nexport class SourcererError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a source is configured or queried with invalid arguments. */\nexport class SourcererConfigurationError extends SourcererError {}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all sourcerer errors. Use `instanceof SourcererError` to catch any sourcerer-originated error. */\nexport class SourcererError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a source is configured or queried with invalid arguments. */\nexport class SourcererConfigurationError extends SourcererError {}\n\nexport class SourcererDisposedError extends SourcererError {\n constructor(message = 'Sourcerer source disposed') {\n super(message);\n }\n}\n"],"mappings":"AACA,IAAa,eAAb,cAAoC,KAAM,CACxC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,4BAAb,cAAiD,cAAe,CAAC,EAEpD,uBAAb,cAA4C,cAAe,CACzD,YAAY,EAAU,4BAA6B,CACjD,MAAM,CAAO,CACf,CACF"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./cursorSource.cjs"),n=require("./infiniteSource.cjs"),r=require("./localSource.cjs"),i=require("./pageSource.cjs");exports.SourcererConfigurationError=e.SourcererConfigurationError,exports.SourcererError=e.SourcererError,exports.createCursorSource=t.createCursorSource,exports.createInfiniteSource=n.createInfiniteSource,exports.createLocalSource=r.createLocalSource,exports.createPageSource=i.createPageSource;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./cursorSource.cjs"),n=require("./infiniteSource.cjs"),r=require("./localSource.cjs"),i=require("./pageSource.cjs");exports.SourcererConfigurationError=e.SourcererConfigurationError,exports.SourcererDisposedError=e.SourcererDisposedError,exports.SourcererError=e.SourcererError,exports.createCursorSource=t.createCursorSource,exports.createInfiniteSource=n.createInfiniteSource,exports.createLocalSource=r.createLocalSource,exports.createPageSource=i.createPageSource;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { createCursorSource } from './cursorSource';
|
|
2
|
-
export { SourcererConfigurationError, SourcererError } from './errors';
|
|
2
|
+
export { SourcererConfigurationError, SourcererDisposedError, SourcererError } from './errors';
|
|
3
3
|
export { createInfiniteSource } from './infiniteSource';
|
|
4
4
|
export { createLocalSource } from './localSource';
|
|
5
5
|
export { createPageSource } from './pageSource';
|
|
6
|
-
export type {
|
|
6
|
+
export type { CursorLoadContext, CursorPagination, CursorResult, CursorSource, CursorSourceConfig, CursorSourceState, InfiniteLoadContext, InfinitePagination, InfiniteSource, InfiniteSourceConfig, InfiniteSourceState, LocalSource, LocalSourceConfig, LocalSourceState, PageLoadContext, PagePagination, PageResult, PageSource, PageSourceConfig, PageSourceState, } from './types';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/F,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,eAAe,GAChB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createCursorSource as n } from "./cursorSource.js";
|
|
3
|
-
import { createInfiniteSource as r } from "./infiniteSource.js";
|
|
4
|
-
import { createLocalSource as i } from "./localSource.js";
|
|
5
|
-
import { createPageSource as a } from "./pageSource.js";
|
|
6
|
-
export { e as SourcererConfigurationError, t as SourcererError, n as createCursorSource, r as createInfiniteSource, i as createLocalSource, a as createPageSource };
|
|
1
|
+
import{SourcererConfigurationError as e,SourcererDisposedError as t,SourcererError as n}from"./errors.js";import{createCursorSource as r}from"./cursorSource.js";import{createInfiniteSource as i}from"./infiniteSource.js";import{createLocalSource as a}from"./localSource.js";import{createPageSource as o}from"./pageSource.js";export{e as SourcererConfigurationError,t as SourcererDisposedError,n as SourcererError,r as createCursorSource,i as createInfiniteSource,a as createLocalSource,o as createPageSource};
|
package/dist/infiniteSource.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./
|
|
1
|
+
const e=require("./errors.cjs"),t=require("./asyncSource.cjs"),n=require("./pagination.cjs");var createPagination=(e,t,n)=>({hasMore:e<n,loadedItems:e,pageSize:t,totalItems:n});function createInfiniteSource(r){let i={pageSize:n.positiveInteger(r.pageSize??20,`pageSize`),params:r.params},a=1,o=!1,s=t.createAsyncSource({error:null,items:[],loading:!1,pagination:createPagination(0,i.pageSize,0),params:i.params}),assertLive=()=>{if(s.disposed)throw new e.SourcererDisposedError},fetch=(e,t,c)=>{let l=s.state.items;return s.fetch({commit:()=>{o=!0,a=t+1,i=e},failure:(e,t)=>({...e,error:t,loading:!1,pendingParams:void 0}),load:n=>r.load({page:t,pageSize:e.pageSize,params:e.params,signal:n}),pending:t=>({...t,error:null,loading:!0,...c||Object.is(e.params,t.params)?{}:{pendingParams:e.params}}),success:t=>{let r=c?[...l,...t.items]:[...t.items];return{error:null,items:r,loading:!1,pagination:createPagination(r.length,e.pageSize,n.totalItems(t.totalItems)),params:e.params}}})},reload=()=>fetch(i,1,!1),c={get disposalSignal(){return s.disposalSignal},dispose:s.dispose,get disposed(){return s.disposed},async loadMore(){if(assertLive(),!s.state.loading){if(!o||!Object.is(i.params,s.state.params)){await reload();return}s.state.pagination.hasMore&&await fetch(i,a,!0)}},reload,async setPageSize(e){assertLive();let t=n.positiveInteger(e,`pageSize`);if(t===i.pageSize){if(s.state.loading||s.state.pagination.pageSize===t)return;await reload();return}i={...i,pageSize:t},a=1,await reload()},async setParams(e){if(assertLive(),Object.is(e,i.params)){!s.state.loading&&!Object.is(e,s.state.params)&&await reload();return}i={...i,params:e},a=1,await reload()},get state(){return s.state},subscribe:s.subscribe,[Symbol.dispose](){c.dispose()}};return c}exports.createInfiniteSource=createInfiniteSource;
|
|
2
2
|
//# sourceMappingURL=infiniteSource.cjs.map
|