@vielzeug/sourcerer 1.1.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -74
- package/dist/_dev.cjs +1 -1
- package/dist/_dev.cjs.map +1 -1
- package/dist/_dev.js +2 -8
- package/dist/_dev.js.map +1 -1
- package/dist/asyncSource.cjs +1 -1
- package/dist/asyncSource.cjs.map +1 -1
- package/dist/asyncSource.d.ts +14 -58
- package/dist/asyncSource.d.ts.map +1 -1
- package/dist/asyncSource.js +28 -27
- package/dist/asyncSource.js.map +1 -1
- package/dist/cursorSource.cjs +1 -1
- package/dist/cursorSource.cjs.map +1 -1
- package/dist/cursorSource.d.ts +3 -3
- package/dist/cursorSource.d.ts.map +1 -1
- package/dist/cursorSource.js +76 -109
- package/dist/cursorSource.js.map +1 -1
- package/dist/devtools.cjs +1 -1
- package/dist/devtools.cjs.map +1 -1
- package/dist/devtools.d.ts +4 -50
- package/dist/devtools.d.ts.map +1 -1
- package/dist/devtools.js +3 -15
- package/dist/devtools.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -13
- package/dist/infiniteSource.cjs +1 -1
- package/dist/infiniteSource.cjs.map +1 -1
- package/dist/infiniteSource.d.ts +3 -3
- package/dist/infiniteSource.d.ts.map +1 -1
- package/dist/infiniteSource.js +71 -106
- package/dist/infiniteSource.js.map +1 -1
- package/dist/localSource.cjs +1 -1
- package/dist/localSource.cjs.map +1 -1
- package/dist/localSource.d.ts +2 -22
- package/dist/localSource.d.ts.map +1 -1
- package/dist/localSource.js +58 -104
- package/dist/localSource.js.map +1 -1
- package/dist/pageSource.cjs +2 -0
- package/dist/pageSource.cjs.map +1 -0
- package/dist/pageSource.d.ts +4 -0
- package/dist/pageSource.d.ts.map +1 -0
- package/dist/pageSource.js +96 -0
- package/dist/pageSource.js.map +1 -0
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.cjs.map +1 -1
- package/dist/pagination.d.ts +5 -30
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +21 -27
- package/dist/pagination.js.map +1 -1
- package/dist/requestController.cjs +2 -0
- package/dist/requestController.cjs.map +1 -0
- package/dist/requestController.d.ts +13 -0
- package/dist/requestController.d.ts.map +1 -0
- package/dist/requestController.js +29 -0
- package/dist/requestController.js.map +1 -0
- package/dist/sourceStore.cjs +2 -0
- package/dist/sourceStore.cjs.map +1 -0
- package/dist/sourceStore.d.ts +10 -0
- package/dist/sourceStore.d.ts.map +1 -0
- package/dist/sourceStore.js +38 -0
- package/dist/sourceStore.js.map +1 -0
- package/dist/sourcerer.cjs +1 -1
- package/dist/sourcerer.cjs.map +1 -1
- package/dist/sourcerer.iife.js +1 -1
- package/dist/sourcerer.iife.js.map +1 -1
- package/dist/sourcerer.js +1 -1
- package/dist/sourcerer.js.map +1 -1
- package/dist/types.d.ts +128 -355
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -9
- package/dist/_utils.cjs +0 -2
- package/dist/_utils.cjs.map +0 -1
- package/dist/_utils.d.ts +0 -28
- package/dist/_utils.d.ts.map +0 -1
- package/dist/_utils.js +0 -20
- package/dist/_utils.js.map +0 -1
- package/dist/asyncSearch.cjs +0 -2
- package/dist/asyncSearch.cjs.map +0 -1
- package/dist/asyncSearch.d.ts +0 -13
- package/dist/asyncSearch.d.ts.map +0 -1
- package/dist/asyncSearch.js +0 -28
- package/dist/asyncSearch.js.map +0 -1
- package/dist/codecs.cjs +0 -2
- package/dist/codecs.cjs.map +0 -1
- package/dist/codecs.d.ts +0 -30
- package/dist/codecs.d.ts.map +0 -1
- package/dist/codecs.js +0 -38
- package/dist/codecs.js.map +0 -1
- package/dist/core.cjs +0 -2
- package/dist/core.cjs.map +0 -1
- package/dist/core.d.ts +0 -71
- package/dist/core.d.ts.map +0 -1
- package/dist/core.js +0 -59
- package/dist/core.js.map +0 -1
- package/dist/derive.cjs +0 -2
- package/dist/derive.cjs.map +0 -1
- package/dist/derive.d.ts +0 -29
- package/dist/derive.d.ts.map +0 -1
- package/dist/derive.js +0 -38
- package/dist/derive.js.map +0 -1
- package/dist/errors.cjs +0 -2
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.ts +0 -62
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -29
- package/dist/errors.js.map +0 -1
- package/dist/fetchManager.cjs +0 -2
- package/dist/fetchManager.cjs.map +0 -1
- package/dist/fetchManager.d.ts +0 -40
- package/dist/fetchManager.d.ts.map +0 -1
- package/dist/fetchManager.js +0 -41
- package/dist/fetchManager.js.map +0 -1
- package/dist/merge.cjs +0 -2
- package/dist/merge.cjs.map +0 -1
- package/dist/merge.d.ts +0 -35
- package/dist/merge.d.ts.map +0 -1
- package/dist/merge.js +0 -41
- package/dist/merge.js.map +0 -1
- package/dist/prefetch.cjs +0 -2
- package/dist/prefetch.cjs.map +0 -1
- package/dist/prefetch.d.ts +0 -32
- package/dist/prefetch.d.ts.map +0 -1
- package/dist/prefetch.js +0 -38
- package/dist/prefetch.js.map +0 -1
- package/dist/presets.cjs +0 -2
- package/dist/presets.cjs.map +0 -1
- package/dist/presets.d.ts +0 -17
- package/dist/presets.d.ts.map +0 -1
- package/dist/presets.js +0 -43
- package/dist/presets.js.map +0 -1
- package/dist/remoteSource.cjs +0 -2
- package/dist/remoteSource.cjs.map +0 -1
- package/dist/remoteSource.d.ts +0 -4
- package/dist/remoteSource.d.ts.map +0 -1
- package/dist/remoteSource.js +0 -165
- package/dist/remoteSource.js.map +0 -1
- package/dist/state.cjs +0 -2
- package/dist/state.cjs.map +0 -1
- package/dist/state.d.ts +0 -23
- package/dist/state.d.ts.map +0 -1
- package/dist/state.js +0 -14
- package/dist/state.js.map +0 -1
package/dist/_utils.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { hash, retry } from '@vielzeug/arsenal';
|
|
2
|
-
export { retry };
|
|
3
|
-
export declare const defaultKeyOf: typeof hash;
|
|
4
|
-
/** Extracts a user-facing error message from a caught exception. */
|
|
5
|
-
export declare const extractError: (reason: unknown) => string;
|
|
6
|
-
/** Default exponential backoff: 1 s, 2 s, 4 s, … capped at 30 s. Receives a 0-indexed failure count. */
|
|
7
|
-
export declare const defaultRetryDelay: (attempt: number) => number;
|
|
8
|
-
/**
|
|
9
|
-
* Strips control characters (which could otherwise inject terminal escape sequences into
|
|
10
|
-
* `console.warn`/`console.debug` output) and caps length before interpolating caller- or
|
|
11
|
-
* user-controlled text into a dev warning. Same approach as `@vielzeug/forge`'s
|
|
12
|
-
* `sanitizeForLog` — duplicated rather than shared, per this repo's zero-cross-package-utility
|
|
13
|
-
* convention for internal-only helpers.
|
|
14
|
-
*/
|
|
15
|
-
export declare function sanitizeForLog(text: string, maxLength?: number): string;
|
|
16
|
-
/**
|
|
17
|
-
* Coerces a user-supplied `limit`/`page`/target value to a positive integer, warning once per
|
|
18
|
-
* `(apiLabel, fieldName)` call site in dev when the raw input needed clamping (negative, zero,
|
|
19
|
-
* or non-finite) — every source factory previously did `Math.max(1, Math.trunc(value))`
|
|
20
|
-
* silently, so a typo'd or miscalculated config value (e.g. `limit: -1`) produced no signal at
|
|
21
|
-
* all. The once-per-call-site de-dup matters here specifically because `limit`/`page` reach this
|
|
22
|
-
* function via `patch()`, which realistically sits behind live UI (a numeric input, a stepper) —
|
|
23
|
-
* without it, a single persistently-invalid bound value would re-warn on every keystroke.
|
|
24
|
-
* Fractional inputs (e.g. `2.5`) are truncated without a warning — that's a harmless
|
|
25
|
-
* normalization, not a likely mistake.
|
|
26
|
-
*/
|
|
27
|
-
export declare function clampPositiveInt(value: number, apiLabel: string, fieldName: string): number;
|
|
28
|
-
//# sourceMappingURL=_utils.d.ts.map
|
package/dist/_utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_utils.d.ts","sourceRoot":"","sources":["../src/_utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,IAAI,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAIzD,OAAO,EAAE,KAAK,EAAE,CAAC;AAGjB,eAAO,MAAM,YAAY,aAAO,CAAC;AAEjC,oEAAoE;AACpE,eAAO,MAAM,YAAY,GAAI,QAAQ,OAAO,KAAG,MAM9C,CAAC;AAEF,wGAAwG;AACxG,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,KAAG,MAA0B,CAAC;AAE/E;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,SAAM,GAAG,MAAM,CAEpE;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAe3F"}
|
package/dist/_utils.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { devOnly as e, warn as t } from "./_dev.js";
|
|
2
|
-
import { backoff as n, hash as r, retry as i } from "@vielzeug/arsenal";
|
|
3
|
-
//#region src/_utils.ts
|
|
4
|
-
var a = r, o = (e) => e instanceof Error ? e.message : typeof e == "string" && e.length > 0 ? e : "Request failed", s = (e) => n(e);
|
|
5
|
-
function c(e, t = 200) {
|
|
6
|
-
return e.replace(/\p{C}/gu, "?").slice(0, t);
|
|
7
|
-
}
|
|
8
|
-
var l = /* @__PURE__ */ new Set();
|
|
9
|
-
function u(n, r, i) {
|
|
10
|
-
let a = Number.isFinite(n) ? Math.max(1, Math.trunc(n)) : 1;
|
|
11
|
-
if (!Number.isFinite(n) || n < 1) {
|
|
12
|
-
let o = `${r}:${i}`;
|
|
13
|
-
l.has(o) || (l.add(o), e(() => t(`${r}: ${i} ${n} is invalid — clamped to ${a}. Must be a positive integer.`)));
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
}
|
|
17
|
-
//#endregion
|
|
18
|
-
export { u as clampPositiveInt, a as defaultKeyOf, s as defaultRetryDelay, o as extractError, i as retry, c as sanitizeForLog };
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=_utils.js.map
|
package/dist/_utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_utils.js","names":[],"sources":["../src/_utils.ts"],"sourcesContent":["import { backoff, hash, retry } from '@vielzeug/arsenal';\n\nimport { devOnly, warn } from './_dev';\n\nexport { retry };\n\n// Internal stable-key helper — used by source factories, not exposed as public API.\nexport const defaultKeyOf = hash;\n\n/** Extracts a user-facing error message from a caught exception. */\nexport const extractError = (reason: unknown): string => {\n if (reason instanceof Error) return reason.message;\n\n if (typeof reason === 'string' && reason.length > 0) return reason;\n\n return 'Request failed';\n};\n\n/** Default exponential backoff: 1 s, 2 s, 4 s, … capped at 30 s. Receives a 0-indexed failure count. */\nexport const defaultRetryDelay = (attempt: number): number => backoff(attempt);\n\n/**\n * Strips control characters (which could otherwise inject terminal escape sequences into\n * `console.warn`/`console.debug` output) and caps length before interpolating caller- or\n * user-controlled text into a dev warning. Same approach as `@vielzeug/forge`'s\n * `sanitizeForLog` — duplicated rather than shared, per this repo's zero-cross-package-utility\n * convention for internal-only helpers.\n */\nexport function sanitizeForLog(text: string, maxLength = 200): string {\n return text.replace(/\\p{C}/gu, '?').slice(0, maxLength);\n}\n\nconst warnedClamps = new Set<string>();\n\n/**\n * Coerces a user-supplied `limit`/`page`/target value to a positive integer, warning once per\n * `(apiLabel, fieldName)` call site in dev when the raw input needed clamping (negative, zero,\n * or non-finite) — every source factory previously did `Math.max(1, Math.trunc(value))`\n * silently, so a typo'd or miscalculated config value (e.g. `limit: -1`) produced no signal at\n * all. The once-per-call-site de-dup matters here specifically because `limit`/`page` reach this\n * function via `patch()`, which realistically sits behind live UI (a numeric input, a stepper) —\n * without it, a single persistently-invalid bound value would re-warn on every keystroke.\n * Fractional inputs (e.g. `2.5`) are truncated without a warning — that's a harmless\n * normalization, not a likely mistake.\n */\nexport function clampPositiveInt(value: number, apiLabel: string, fieldName: string): number {\n const clamped = Number.isFinite(value) ? Math.max(1, Math.trunc(value)) : 1;\n\n if (!Number.isFinite(value) || value < 1) {\n const key = `${apiLabel}:${fieldName}`;\n\n if (!warnedClamps.has(key)) {\n warnedClamps.add(key);\n devOnly(() =>\n warn(`${apiLabel}: ${fieldName} ${value} is invalid — clamped to ${clamped}. Must be a positive integer.`),\n );\n }\n }\n\n return clamped;\n}\n"],"mappings":";;;AAOA,IAAa,IAAe,GAGf,KAAgB,MACvB,aAAkB,QAAc,EAAO,UAEvC,OAAO,KAAW,YAAY,EAAO,SAAS,IAAU,IAErD,kBAII,KAAqB,MAA4B,EAAQ,CAAO;AAS7E,SAAgB,EAAe,GAAc,IAAY,KAAa;CACpE,OAAO,EAAK,QAAQ,WAAW,GAAG,CAAC,CAAC,MAAM,GAAG,CAAS;AACxD;AAEA,IAAM,oBAAe,IAAI,IAAY;AAarC,SAAgB,EAAiB,GAAe,GAAkB,GAA2B;CAC3F,IAAM,IAAU,OAAO,SAAS,CAAK,IAAI,KAAK,IAAI,GAAG,KAAK,MAAM,CAAK,CAAC,IAAI;CAE1E,IAAI,CAAC,OAAO,SAAS,CAAK,KAAK,IAAQ,GAAG;EACxC,IAAM,IAAM,GAAG,EAAS,GAAG;EAE3B,AAAK,EAAa,IAAI,CAAG,MACvB,EAAa,IAAI,CAAG,GACpB,QACE,EAAK,GAAG,EAAS,IAAI,EAAU,GAAG,EAAM,2BAA2B,EAAQ,8BAA8B,CAC3G;CAEJ;CAEA,OAAO;AACT"}
|
package/dist/asyncSearch.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function e(e,t){let n=null,r=()=>{n&&=(n(),null)};return{cancel(){e.cancelTimer(),r()},dispose(){r()},schedule(i,a){r();let o=new Promise(e=>{n=e});return e.schedule(i,a),t(),o},settleIfIdle(e){e===0&&r()}}}exports.createAsyncSearchCoordinator=e;
|
|
2
|
-
//# sourceMappingURL=asyncSearch.cjs.map
|
package/dist/asyncSearch.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"asyncSearch.cjs","names":[],"sources":["../src/asyncSearch.ts"],"sourcesContent":["import type { SourceCore } from './core';\n\nexport type AsyncSearchCoordinator = Readonly<{\n cancel(): void;\n dispose(): void;\n schedule(run: () => void, delayMs: number): Promise<void>;\n settleIfIdle(pendingCount: number): void;\n}>;\n\n/**\n * Shared debounced-search promise orchestration for async sources.\n * Keeps search() promise lifecycles consistent across remote/cursor/infinite sources.\n */\nexport function createAsyncSearchCoordinator(core: SourceCore, notify: () => void): AsyncSearchCoordinator {\n let pendingResolve: (() => void) | null = null;\n\n const resolvePending = () => {\n if (pendingResolve) {\n pendingResolve();\n pendingResolve = null;\n }\n };\n\n return {\n cancel() {\n core.cancelTimer();\n resolvePending();\n },\n\n dispose() {\n resolvePending();\n },\n\n schedule(run, delayMs) {\n resolvePending();\n\n const promise = new Promise<void>((resolve) => {\n pendingResolve = resolve;\n });\n\n core.schedule(run, delayMs);\n notify();\n\n return promise;\n },\n\n settleIfIdle(pendingCount) {\n if (pendingCount === 0) resolvePending();\n },\n };\n}\n"],"mappings":"AAaA,SAAgB,EAA6B,EAAkB,EAA4C,CACzG,IAAI,EAAsC,KAEpC,MAAuB,CAC3B,AAEE,KADA,EAAe,EACE,KAErB,EAEA,MAAO,CACL,QAAS,CACP,EAAK,YAAY,EACjB,EAAe,CACjB,EAEA,SAAU,CACR,EAAe,CACjB,EAEA,SAAS,EAAK,EAAS,CACrB,EAAe,EAEf,IAAM,EAAU,IAAI,QAAe,GAAY,CAC7C,EAAiB,CACnB,CAAC,EAKD,OAHA,EAAK,SAAS,EAAK,CAAO,EAC1B,EAAO,EAEA,CACT,EAEA,aAAa,EAAc,CACrB,IAAiB,GAAG,EAAe,CACzC,CACF,CACF"}
|
package/dist/asyncSearch.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { SourceCore } from './core';
|
|
2
|
-
export type AsyncSearchCoordinator = Readonly<{
|
|
3
|
-
cancel(): void;
|
|
4
|
-
dispose(): void;
|
|
5
|
-
schedule(run: () => void, delayMs: number): Promise<void>;
|
|
6
|
-
settleIfIdle(pendingCount: number): void;
|
|
7
|
-
}>;
|
|
8
|
-
/**
|
|
9
|
-
* Shared debounced-search promise orchestration for async sources.
|
|
10
|
-
* Keeps search() promise lifecycles consistent across remote/cursor/infinite sources.
|
|
11
|
-
*/
|
|
12
|
-
export declare function createAsyncSearchCoordinator(core: SourceCore, notify: () => void): AsyncSearchCoordinator;
|
|
13
|
-
//# sourceMappingURL=asyncSearch.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"asyncSearch.d.ts","sourceRoot":"","sources":["../src/asyncSearch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC;IAC5C,MAAM,IAAI,IAAI,CAAC;IACf,OAAO,IAAI,IAAI,CAAC;IAChB,QAAQ,CAAC,GAAG,EAAE,MAAM,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1C,CAAC,CAAC;AAEH;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,IAAI,GAAG,sBAAsB,CAqCzG"}
|
package/dist/asyncSearch.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
//#region src/asyncSearch.ts
|
|
2
|
-
function e(e, t) {
|
|
3
|
-
let n = null, r = () => {
|
|
4
|
-
n &&= (n(), null);
|
|
5
|
-
};
|
|
6
|
-
return {
|
|
7
|
-
cancel() {
|
|
8
|
-
e.cancelTimer(), r();
|
|
9
|
-
},
|
|
10
|
-
dispose() {
|
|
11
|
-
r();
|
|
12
|
-
},
|
|
13
|
-
schedule(i, a) {
|
|
14
|
-
r();
|
|
15
|
-
let o = new Promise((e) => {
|
|
16
|
-
n = e;
|
|
17
|
-
});
|
|
18
|
-
return e.schedule(i, a), t(), o;
|
|
19
|
-
},
|
|
20
|
-
settleIfIdle(e) {
|
|
21
|
-
e === 0 && r();
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
export { e as createAsyncSearchCoordinator };
|
|
27
|
-
|
|
28
|
-
//# sourceMappingURL=asyncSearch.js.map
|
package/dist/asyncSearch.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"asyncSearch.js","names":[],"sources":["../src/asyncSearch.ts"],"sourcesContent":["import type { SourceCore } from './core';\n\nexport type AsyncSearchCoordinator = Readonly<{\n cancel(): void;\n dispose(): void;\n schedule(run: () => void, delayMs: number): Promise<void>;\n settleIfIdle(pendingCount: number): void;\n}>;\n\n/**\n * Shared debounced-search promise orchestration for async sources.\n * Keeps search() promise lifecycles consistent across remote/cursor/infinite sources.\n */\nexport function createAsyncSearchCoordinator(core: SourceCore, notify: () => void): AsyncSearchCoordinator {\n let pendingResolve: (() => void) | null = null;\n\n const resolvePending = () => {\n if (pendingResolve) {\n pendingResolve();\n pendingResolve = null;\n }\n };\n\n return {\n cancel() {\n core.cancelTimer();\n resolvePending();\n },\n\n dispose() {\n resolvePending();\n },\n\n schedule(run, delayMs) {\n resolvePending();\n\n const promise = new Promise<void>((resolve) => {\n pendingResolve = resolve;\n });\n\n core.schedule(run, delayMs);\n notify();\n\n return promise;\n },\n\n settleIfIdle(pendingCount) {\n if (pendingCount === 0) resolvePending();\n },\n };\n}\n"],"mappings":";AAaA,SAAgB,EAA6B,GAAkB,GAA4C;CACzG,IAAI,IAAsC,MAEpC,UAAuB;EAC3B,AAEE,OADA,EAAe,GACE;CAErB;CAEA,OAAO;EACL,SAAS;GAEP,AADA,EAAK,YAAY,GACjB,EAAe;EACjB;EAEA,UAAU;GACR,EAAe;EACjB;EAEA,SAAS,GAAK,GAAS;GACrB,EAAe;GAEf,IAAM,IAAU,IAAI,SAAe,MAAY;IAC7C,IAAiB;GACnB,CAAC;GAKD,OAHA,EAAK,SAAS,GAAK,CAAO,GAC1B,EAAO,GAEA;EACT;EAEA,aAAa,GAAc;GACzB,AAAI,MAAiB,KAAG,EAAe;EACzC;CACF;AACF"}
|
package/dist/codecs.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("./_dev.cjs"),t=require("./_utils.cjs"),n=require("./errors.cjs");var r=e=>{let t={...e.search&&{search:e.search},limit:String(e.limit),page:String(e.page)},n=e;return n.filter!==void 0&&(t.filter=JSON.stringify(n.filter)),n.sort!==void 0&&(t.sort=JSON.stringify(n.sort)),t},i=(r,i={})=>{let a=r instanceof URLSearchParams?Object.fromEntries(r.entries()):r,{defaultLimit:o=20,strict:s=!1}=i,c=(n,r,i)=>{if(r===void 0)return i;let a=Array.isArray(r)?r[0]:r,o=Number(a);return Number.isInteger(o)&&o>0?o:(e.devOnly(()=>e.warn(`decodeQuery: ${n} "${t.sanitizeForLog(a,80)}" is not a positive integer — using ${i}.`)),i)},l=(e,r)=>{if(r===void 0)return;let i=Array.isArray(r)?r[0]:r;try{return JSON.parse(i)}catch{if(s)throw new n.SourcererError(`Invalid query param "${e}": ${t.sanitizeForLog(i,80)}`);return}},u=a.limit,d=a.page,f=a.search,p=a.filter,m=a.sort,h=p===void 0?void 0:l(`filter`,p),g=m===void 0?void 0:l(`sort`,m);return{...h!==void 0&&{filter:h},...g!==void 0&&{sort:g},...f!==void 0&&{search:Array.isArray(f)?f[0]:f},limit:c(`limit`,u,o),page:c(`page`,d,1)}};exports.decodeQuery=i,exports.encodeQuery=r;
|
|
2
|
-
//# sourceMappingURL=codecs.cjs.map
|
package/dist/codecs.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codecs.cjs","names":[],"sources":["../src/codecs.ts"],"sourcesContent":["import type { QueryParams, QueryParamsInput, RemoteSourceQuery, SourceQuery } from './types';\n\nimport { devOnly, warn } from './_dev';\nimport { sanitizeForLog } from './_utils';\nimport { SourcererError } from './errors';\n\n/**\n * Serialises a `SourceQuery` or `RemoteSourceQuery` into plain URL-safe string params.\n *\n * ⚠️ `filter` and `sort` are JSON-stringified without a try/catch. A circular object reference\n * throws a native `TypeError` (\"Converting circular structure to JSON\") straight out of this\n * function — ensure filter/sort values are plain serialisable objects, or wrap the call yourself.\n *\n * ⚠️ Round-trip fidelity: `page` and `limit` must be positive integers. `encodeQuery` will\n * serialise any number (including 0), but `decodeQuery` clamps non-positive values to 1/defaultLimit.\n *\n * `encodeQuery` + `decodeQuery` form a round-trip pair: filter/sort values are JSON-stringified\n * on encode and JSON-parsed on decode.\n */\nexport const encodeQuery = <TFilter = unknown, TSort = unknown>(\n query: RemoteSourceQuery<TFilter, TSort> | SourceQuery,\n): QueryParams => {\n const base: QueryParams = {\n ...(query.search && { search: query.search }),\n limit: String(query.limit),\n page: String(query.page),\n };\n\n const rq = query as RemoteSourceQuery<TFilter, TSort>;\n\n if (rq.filter !== undefined) {\n base['filter'] = JSON.stringify(rq.filter);\n }\n\n if (rq.sort !== undefined) {\n base['sort'] = JSON.stringify(rq.sort);\n }\n\n return base;\n};\n\nexport type DecodeQueryOptions = Readonly<{\n defaultLimit?: number;\n strict?: boolean;\n}>;\n\n/**\n * Parses URL query params into a `Partial<RemoteSourceQuery<unknown, unknown>>`.\n * Accepts either a plain `Record<string, string | string[] | undefined>` or a `URLSearchParams` instance.\n *\n * - `filter` and `sort` are JSON-parsed and typed as `unknown` — validate and narrow them\n * with a runtime schema (e.g. Zod) before passing to `source.patch(...)`.\n * - `search` is omitted from the result when the param is absent (rather than defaulting to `''`).\n * - `limit` and `page` are parsed as positive integers; invalid values fall back to defaults.\n */\nexport const decodeQuery = (\n params: QueryParamsInput | URLSearchParams,\n options: DecodeQueryOptions = {},\n): Partial<RemoteSourceQuery<unknown, unknown>> => {\n const raw: QueryParamsInput =\n params instanceof URLSearchParams ? (Object.fromEntries(params.entries()) as QueryParamsInput) : params;\n\n const { defaultLimit = 20, strict = false } = options;\n\n // Deliberately not `_utils.ts::clampPositiveInt` here: that one truncates a fractional\n // config value (2.5 -> 2) as a harmless normalization, and always floors invalid input to 1.\n // A URL param is untrusted network input, not a caller's own config object — \"2.5\" or \"-5\"\n // in a query string is more likely a corrupted/tampered link than a rounding artifact, so\n // this stays strict (reject anything that isn't a clean positive integer) and falls back to\n // the caller's own `defaultLimit`/`1`, not an unconditional floor of 1.\n //\n // @security `str` is the raw, attacker-controllable param value (this function's whole job\n // is parsing untrusted `location.search`/route params) — sanitize before interpolating into\n // the warning to prevent terminal-escape-sequence injection into a developer's console.\n const parsePositiveInt = (fieldName: string, value: string | string[] | undefined, fallback: number): number => {\n if (value === undefined) return fallback;\n\n const str = Array.isArray(value) ? value[0] : value;\n const n = Number(str);\n\n if (Number.isInteger(n) && n > 0) return n;\n\n devOnly(() =>\n warn(`decodeQuery: ${fieldName} \"${sanitizeForLog(str, 80)}\" is not a positive integer — using ${fallback}.`),\n );\n\n return fallback;\n };\n\n // @security Same as `parsePositiveInt` above — `str` is untrusted and may end up in a\n // terminal/log aggregator via this error's `.message`, not just a direct `console.warn`.\n const parseJson = (key: string, value: string | string[] | undefined): unknown => {\n if (value === undefined) return undefined;\n\n const str = Array.isArray(value) ? value[0] : value;\n\n try {\n return JSON.parse(str) as unknown;\n } catch {\n if (strict) throw new SourcererError(`Invalid query param \"${key}\": ${sanitizeForLog(str, 80)}`);\n\n return undefined;\n }\n };\n\n const rawLimit = raw['limit'];\n const rawPage = raw['page'];\n const rawSearch = raw['search'];\n const rawFilter = raw['filter'];\n const rawSort = raw['sort'];\n\n const filter = rawFilter !== undefined ? parseJson('filter', rawFilter) : undefined;\n const sort = rawSort !== undefined ? parseJson('sort', rawSort) : undefined;\n\n const result: Partial<RemoteSourceQuery<unknown, unknown>> = {\n ...(filter !== undefined && { filter }),\n ...(sort !== undefined && { sort }),\n ...(rawSearch !== undefined && { search: Array.isArray(rawSearch) ? rawSearch[0] : rawSearch }),\n limit: parsePositiveInt('limit', rawLimit, defaultLimit),\n page: parsePositiveInt('page', rawPage, 1),\n };\n\n return result;\n};\n"],"mappings":"kFAmBA,IAAa,EACX,GACgB,CAChB,IAAM,EAAoB,CACxB,GAAI,EAAM,QAAU,CAAE,OAAQ,EAAM,MAAO,EAC3C,MAAO,OAAO,EAAM,KAAK,EACzB,KAAM,OAAO,EAAM,IAAI,CACzB,EAEM,EAAK,EAUX,OARI,EAAG,SAAW,IAAA,KAChB,EAAK,OAAY,KAAK,UAAU,EAAG,MAAM,GAGvC,EAAG,OAAS,IAAA,KACd,EAAK,KAAU,KAAK,UAAU,EAAG,IAAI,GAGhC,CACT,EAgBa,GACX,EACA,EAA8B,CAAC,IACkB,CACjD,IAAM,EACJ,aAAkB,gBAAmB,OAAO,YAAY,EAAO,QAAQ,CAAC,EAAyB,EAE7F,CAAE,eAAe,GAAI,SAAS,IAAU,EAYxC,GAAoB,EAAmB,EAAsC,IAA6B,CAC9G,GAAI,IAAU,IAAA,GAAW,OAAO,EAEhC,IAAM,EAAM,MAAM,QAAQ,CAAK,EAAI,EAAM,GAAK,EACxC,EAAI,OAAO,CAAG,EAQpB,OANI,OAAO,UAAU,CAAC,GAAK,EAAI,EAAU,GAEzC,EAAA,YACE,EAAA,KAAK,gBAAgB,EAAU,IAAI,EAAA,eAAe,EAAK,EAAE,EAAE,sCAAsC,EAAS,EAAE,CAC9G,EAEO,EACT,EAIM,GAAa,EAAa,IAAkD,CAChF,GAAI,IAAU,IAAA,GAAW,OAEzB,IAAM,EAAM,MAAM,QAAQ,CAAK,EAAI,EAAM,GAAK,EAE9C,GAAI,CACF,OAAO,KAAK,MAAM,CAAG,CACvB,MAAQ,CACN,GAAI,EAAQ,MAAM,IAAI,EAAA,eAAe,wBAAwB,EAAI,KAAK,EAAA,eAAe,EAAK,EAAE,GAAG,EAE/F,MACF,CACF,EAEM,EAAW,EAAI,MACf,EAAU,EAAI,KACd,EAAY,EAAI,OAChB,EAAY,EAAI,OAChB,EAAU,EAAI,KAEd,EAAS,IAAc,IAAA,GAA6C,IAAA,GAAjC,EAAU,SAAU,CAAS,EAChE,EAAO,IAAY,IAAA,GAAyC,IAAA,GAA7B,EAAU,OAAQ,CAAO,EAU9D,MAAO,CAPL,GAAI,IAAW,IAAA,IAAa,CAAE,QAAO,EACrC,GAAI,IAAS,IAAA,IAAa,CAAE,MAAK,EACjC,GAAI,IAAc,IAAA,IAAa,CAAE,OAAQ,MAAM,QAAQ,CAAS,EAAI,EAAU,GAAK,CAAU,EAC7F,MAAO,EAAiB,QAAS,EAAU,CAAY,EACvD,KAAM,EAAiB,OAAQ,EAAS,CAAC,CAGpC,CACT"}
|
package/dist/codecs.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { QueryParams, QueryParamsInput, RemoteSourceQuery, SourceQuery } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Serialises a `SourceQuery` or `RemoteSourceQuery` into plain URL-safe string params.
|
|
4
|
-
*
|
|
5
|
-
* ⚠️ `filter` and `sort` are JSON-stringified without a try/catch. A circular object reference
|
|
6
|
-
* throws a native `TypeError` ("Converting circular structure to JSON") straight out of this
|
|
7
|
-
* function — ensure filter/sort values are plain serialisable objects, or wrap the call yourself.
|
|
8
|
-
*
|
|
9
|
-
* ⚠️ Round-trip fidelity: `page` and `limit` must be positive integers. `encodeQuery` will
|
|
10
|
-
* serialise any number (including 0), but `decodeQuery` clamps non-positive values to 1/defaultLimit.
|
|
11
|
-
*
|
|
12
|
-
* `encodeQuery` + `decodeQuery` form a round-trip pair: filter/sort values are JSON-stringified
|
|
13
|
-
* on encode and JSON-parsed on decode.
|
|
14
|
-
*/
|
|
15
|
-
export declare const encodeQuery: <TFilter = unknown, TSort = unknown>(query: RemoteSourceQuery<TFilter, TSort> | SourceQuery) => QueryParams;
|
|
16
|
-
export type DecodeQueryOptions = Readonly<{
|
|
17
|
-
defaultLimit?: number;
|
|
18
|
-
strict?: boolean;
|
|
19
|
-
}>;
|
|
20
|
-
/**
|
|
21
|
-
* Parses URL query params into a `Partial<RemoteSourceQuery<unknown, unknown>>`.
|
|
22
|
-
* Accepts either a plain `Record<string, string | string[] | undefined>` or a `URLSearchParams` instance.
|
|
23
|
-
*
|
|
24
|
-
* - `filter` and `sort` are JSON-parsed and typed as `unknown` — validate and narrow them
|
|
25
|
-
* with a runtime schema (e.g. Zod) before passing to `source.patch(...)`.
|
|
26
|
-
* - `search` is omitted from the result when the param is absent (rather than defaulting to `''`).
|
|
27
|
-
* - `limit` and `page` are parsed as positive integers; invalid values fall back to defaults.
|
|
28
|
-
*/
|
|
29
|
-
export declare const decodeQuery: (params: QueryParamsInput | URLSearchParams, options?: DecodeQueryOptions) => Partial<RemoteSourceQuery<unknown, unknown>>;
|
|
30
|
-
//# sourceMappingURL=codecs.d.ts.map
|
package/dist/codecs.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codecs.d.ts","sourceRoot":"","sources":["../src/codecs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAM7F;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO,EAC5D,OAAO,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,WAAW,KACrD,WAkBF,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,gBAAgB,GAAG,eAAe,EAC1C,UAAS,kBAAuB,KAC/B,OAAO,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAiE7C,CAAC"}
|
package/dist/codecs.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { devOnly as e, warn as t } from "./_dev.js";
|
|
2
|
-
import { sanitizeForLog as n } from "./_utils.js";
|
|
3
|
-
import { SourcererError as r } from "./errors.js";
|
|
4
|
-
//#region src/codecs.ts
|
|
5
|
-
var i = (e) => {
|
|
6
|
-
let t = {
|
|
7
|
-
...e.search && { search: e.search },
|
|
8
|
-
limit: String(e.limit),
|
|
9
|
-
page: String(e.page)
|
|
10
|
-
}, n = e;
|
|
11
|
-
return n.filter !== void 0 && (t.filter = JSON.stringify(n.filter)), n.sort !== void 0 && (t.sort = JSON.stringify(n.sort)), t;
|
|
12
|
-
}, a = (i, a = {}) => {
|
|
13
|
-
let o = i instanceof URLSearchParams ? Object.fromEntries(i.entries()) : i, { defaultLimit: s = 20, strict: c = !1 } = a, l = (r, i, a) => {
|
|
14
|
-
if (i === void 0) return a;
|
|
15
|
-
let o = Array.isArray(i) ? i[0] : i, s = Number(o);
|
|
16
|
-
return Number.isInteger(s) && s > 0 ? s : (e(() => t(`decodeQuery: ${r} "${n(o, 80)}" is not a positive integer — using ${a}.`)), a);
|
|
17
|
-
}, u = (e, t) => {
|
|
18
|
-
if (t === void 0) return;
|
|
19
|
-
let i = Array.isArray(t) ? t[0] : t;
|
|
20
|
-
try {
|
|
21
|
-
return JSON.parse(i);
|
|
22
|
-
} catch {
|
|
23
|
-
if (c) throw new r(`Invalid query param "${e}": ${n(i, 80)}`);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
}, d = o.limit, f = o.page, p = o.search, m = o.filter, h = o.sort, g = m === void 0 ? void 0 : u("filter", m), _ = h === void 0 ? void 0 : u("sort", h);
|
|
27
|
-
return {
|
|
28
|
-
...g !== void 0 && { filter: g },
|
|
29
|
-
..._ !== void 0 && { sort: _ },
|
|
30
|
-
...p !== void 0 && { search: Array.isArray(p) ? p[0] : p },
|
|
31
|
-
limit: l("limit", d, s),
|
|
32
|
-
page: l("page", f, 1)
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
//#endregion
|
|
36
|
-
export { a as decodeQuery, i as encodeQuery };
|
|
37
|
-
|
|
38
|
-
//# sourceMappingURL=codecs.js.map
|
package/dist/codecs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codecs.js","names":[],"sources":["../src/codecs.ts"],"sourcesContent":["import type { QueryParams, QueryParamsInput, RemoteSourceQuery, SourceQuery } from './types';\n\nimport { devOnly, warn } from './_dev';\nimport { sanitizeForLog } from './_utils';\nimport { SourcererError } from './errors';\n\n/**\n * Serialises a `SourceQuery` or `RemoteSourceQuery` into plain URL-safe string params.\n *\n * ⚠️ `filter` and `sort` are JSON-stringified without a try/catch. A circular object reference\n * throws a native `TypeError` (\"Converting circular structure to JSON\") straight out of this\n * function — ensure filter/sort values are plain serialisable objects, or wrap the call yourself.\n *\n * ⚠️ Round-trip fidelity: `page` and `limit` must be positive integers. `encodeQuery` will\n * serialise any number (including 0), but `decodeQuery` clamps non-positive values to 1/defaultLimit.\n *\n * `encodeQuery` + `decodeQuery` form a round-trip pair: filter/sort values are JSON-stringified\n * on encode and JSON-parsed on decode.\n */\nexport const encodeQuery = <TFilter = unknown, TSort = unknown>(\n query: RemoteSourceQuery<TFilter, TSort> | SourceQuery,\n): QueryParams => {\n const base: QueryParams = {\n ...(query.search && { search: query.search }),\n limit: String(query.limit),\n page: String(query.page),\n };\n\n const rq = query as RemoteSourceQuery<TFilter, TSort>;\n\n if (rq.filter !== undefined) {\n base['filter'] = JSON.stringify(rq.filter);\n }\n\n if (rq.sort !== undefined) {\n base['sort'] = JSON.stringify(rq.sort);\n }\n\n return base;\n};\n\nexport type DecodeQueryOptions = Readonly<{\n defaultLimit?: number;\n strict?: boolean;\n}>;\n\n/**\n * Parses URL query params into a `Partial<RemoteSourceQuery<unknown, unknown>>`.\n * Accepts either a plain `Record<string, string | string[] | undefined>` or a `URLSearchParams` instance.\n *\n * - `filter` and `sort` are JSON-parsed and typed as `unknown` — validate and narrow them\n * with a runtime schema (e.g. Zod) before passing to `source.patch(...)`.\n * - `search` is omitted from the result when the param is absent (rather than defaulting to `''`).\n * - `limit` and `page` are parsed as positive integers; invalid values fall back to defaults.\n */\nexport const decodeQuery = (\n params: QueryParamsInput | URLSearchParams,\n options: DecodeQueryOptions = {},\n): Partial<RemoteSourceQuery<unknown, unknown>> => {\n const raw: QueryParamsInput =\n params instanceof URLSearchParams ? (Object.fromEntries(params.entries()) as QueryParamsInput) : params;\n\n const { defaultLimit = 20, strict = false } = options;\n\n // Deliberately not `_utils.ts::clampPositiveInt` here: that one truncates a fractional\n // config value (2.5 -> 2) as a harmless normalization, and always floors invalid input to 1.\n // A URL param is untrusted network input, not a caller's own config object — \"2.5\" or \"-5\"\n // in a query string is more likely a corrupted/tampered link than a rounding artifact, so\n // this stays strict (reject anything that isn't a clean positive integer) and falls back to\n // the caller's own `defaultLimit`/`1`, not an unconditional floor of 1.\n //\n // @security `str` is the raw, attacker-controllable param value (this function's whole job\n // is parsing untrusted `location.search`/route params) — sanitize before interpolating into\n // the warning to prevent terminal-escape-sequence injection into a developer's console.\n const parsePositiveInt = (fieldName: string, value: string | string[] | undefined, fallback: number): number => {\n if (value === undefined) return fallback;\n\n const str = Array.isArray(value) ? value[0] : value;\n const n = Number(str);\n\n if (Number.isInteger(n) && n > 0) return n;\n\n devOnly(() =>\n warn(`decodeQuery: ${fieldName} \"${sanitizeForLog(str, 80)}\" is not a positive integer — using ${fallback}.`),\n );\n\n return fallback;\n };\n\n // @security Same as `parsePositiveInt` above — `str` is untrusted and may end up in a\n // terminal/log aggregator via this error's `.message`, not just a direct `console.warn`.\n const parseJson = (key: string, value: string | string[] | undefined): unknown => {\n if (value === undefined) return undefined;\n\n const str = Array.isArray(value) ? value[0] : value;\n\n try {\n return JSON.parse(str) as unknown;\n } catch {\n if (strict) throw new SourcererError(`Invalid query param \"${key}\": ${sanitizeForLog(str, 80)}`);\n\n return undefined;\n }\n };\n\n const rawLimit = raw['limit'];\n const rawPage = raw['page'];\n const rawSearch = raw['search'];\n const rawFilter = raw['filter'];\n const rawSort = raw['sort'];\n\n const filter = rawFilter !== undefined ? parseJson('filter', rawFilter) : undefined;\n const sort = rawSort !== undefined ? parseJson('sort', rawSort) : undefined;\n\n const result: Partial<RemoteSourceQuery<unknown, unknown>> = {\n ...(filter !== undefined && { filter }),\n ...(sort !== undefined && { sort }),\n ...(rawSearch !== undefined && { search: Array.isArray(rawSearch) ? rawSearch[0] : rawSearch }),\n limit: parsePositiveInt('limit', rawLimit, defaultLimit),\n page: parsePositiveInt('page', rawPage, 1),\n };\n\n return result;\n};\n"],"mappings":";;;;AAmBA,IAAa,KACX,MACgB;CAChB,IAAM,IAAoB;EACxB,GAAI,EAAM,UAAU,EAAE,QAAQ,EAAM,OAAO;EAC3C,OAAO,OAAO,EAAM,KAAK;EACzB,MAAM,OAAO,EAAM,IAAI;CACzB,GAEM,IAAK;CAUX,OARI,EAAG,WAAW,KAAA,MAChB,EAAK,SAAY,KAAK,UAAU,EAAG,MAAM,IAGvC,EAAG,SAAS,KAAA,MACd,EAAK,OAAU,KAAK,UAAU,EAAG,IAAI,IAGhC;AACT,GAgBa,KACX,GACA,IAA8B,CAAC,MACkB;CACjD,IAAM,IACJ,aAAkB,kBAAmB,OAAO,YAAY,EAAO,QAAQ,CAAC,IAAyB,GAE7F,EAAE,kBAAe,IAAI,YAAS,OAAU,GAYxC,KAAoB,GAAmB,GAAsC,MAA6B;EAC9G,IAAI,MAAU,KAAA,GAAW,OAAO;EAEhC,IAAM,IAAM,MAAM,QAAQ,CAAK,IAAI,EAAM,KAAK,GACxC,IAAI,OAAO,CAAG;EAQpB,OANI,OAAO,UAAU,CAAC,KAAK,IAAI,IAAU,KAEzC,QACE,EAAK,gBAAgB,EAAU,IAAI,EAAe,GAAK,EAAE,EAAE,sCAAsC,EAAS,EAAE,CAC9G,GAEO;CACT,GAIM,KAAa,GAAa,MAAkD;EAChF,IAAI,MAAU,KAAA,GAAW;EAEzB,IAAM,IAAM,MAAM,QAAQ,CAAK,IAAI,EAAM,KAAK;EAE9C,IAAI;GACF,OAAO,KAAK,MAAM,CAAG;EACvB,QAAQ;GACN,IAAI,GAAQ,MAAM,IAAI,EAAe,wBAAwB,EAAI,KAAK,EAAe,GAAK,EAAE,GAAG;GAE/F;EACF;CACF,GAEM,IAAW,EAAI,OACf,IAAU,EAAI,MACd,IAAY,EAAI,QAChB,IAAY,EAAI,QAChB,IAAU,EAAI,MAEd,IAAS,MAAc,KAAA,IAA6C,KAAA,IAAjC,EAAU,UAAU,CAAS,GAChE,IAAO,MAAY,KAAA,IAAyC,KAAA,IAA7B,EAAU,QAAQ,CAAO;CAU9D,OAAO;EAPL,GAAI,MAAW,KAAA,KAAa,EAAE,UAAO;EACrC,GAAI,MAAS,KAAA,KAAa,EAAE,QAAK;EACjC,GAAI,MAAc,KAAA,KAAa,EAAE,QAAQ,MAAM,QAAQ,CAAS,IAAI,EAAU,KAAK,EAAU;EAC7F,OAAO,EAAiB,SAAS,GAAU,CAAY;EACvD,MAAM,EAAiB,QAAQ,GAAS,CAAC;CAGpC;AACT"}
|
package/dist/core.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("./errors.cjs");function t(t){let n=new Set,r=new Set,i=new AbortController,a,o=!1;return{cancelTimer(){a&&=(clearTimeout(a),void 0)},get disposalSignal(){return i.signal},dispose(){a&&=(clearTimeout(a),void 0);for(let t of r)t.timeoutId!==void 0&&clearTimeout(t.timeoutId),t.reject(new e.SourcererDisposedError);r.clear(),n.clear(),o=!0,i.abort()},flush(e){return a?(clearTimeout(a),a=void 0,e()):Promise.resolve()},get isDisposed(){return o},get isScheduled(){return a!==void 0},notify(e){if(!o){(e??t?.onBeforeNotify)?.();for(let e of n)e();for(let e of r)e.check()}},ready(t,n){return o?Promise.reject(new e.SourcererDisposedError):t()?Promise.resolve():new Promise((i,a)=>{let o={check:()=>{t()&&(o.timeoutId!==void 0&&clearTimeout(o.timeoutId),r.delete(o),i())},reject:a};n!==void 0&&(o.timeoutId=setTimeout(()=>{r.delete(o),a(new e.SourcererTimeoutError(n))},n)),r.add(o)})},schedule(e,t){o||(a&&clearTimeout(a),a=setTimeout(()=>{a=void 0,e()},t))},subscribe(e){return o?()=>{}:(n.add(e),()=>n.delete(e))}}}exports.createSourceCore=t;
|
|
2
|
-
//# sourceMappingURL=core.cjs.map
|
package/dist/core.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs","names":[],"sources":["../src/core.ts"],"sourcesContent":["import { SourcererDisposedError, SourcererTimeoutError } from './errors';\n\n/**\n * Shared source infrastructure: change notification, debounce scheduling, and ready() polling.\n * All source factories compose this core rather than duplicating the same patterns.\n *\n * Change notification is a plain `Set<listener>` — deliberately NOT `@vielzeug/ripple`, despite\n * that being the repo-wide convention for \"reactive\" packages. Tried it; reverted. Two concrete\n * problems, not just aesthetics:\n *\n * 1. `prefetchSource()`/`prefetchSourceAndKeep()` are explicitly documented for SSR, and every\n * source factory routes through this file's `signal`-backed notify. Ripple's own scheduler\n * warns that its module-level flush queue is shared across concurrent requests in Node.js\n * unless the caller opts into `@vielzeug/ripple/ssr`'s per-request isolation — a real,\n * unaddressed risk in exactly the code path meant to run on a server handling concurrent\n * requests.\n * 2. `subscribe()`'s public contract is \"fire on every notify()\", not per-field reactivity —\n * ripple's dependency-tracking machinery (a real subscription object per `watch()` call)\n * buys nothing over a bare `Set.add()` for that contract, since there's exactly one thing\n * ever being watched (an internal version counter, not real data).\n *\n * `current`/`meta` themselves were never ripple signals either way — the public shape has\n * always been plain getters + `subscribe()`, framework-agnostic by design (see `types.ts`'s\n * `ReactiveSource` doc comment). Nothing about restoring a plain `Set` changes that contract.\n *\n * Debounce scheduling and `ready()`'s \"resolve when idle, with a timeout\" polling were never\n * ripple's job either way: ripple is a dependency-tracking signal system (\"notify when a value\n * changes\"), not an async-coordination library (\"wait for a condition, with a timeout, and\n * reject if disposed first\").\n */\nexport type SourceCore = {\n /** Cancels any pending timer without invoking the callback. */\n cancelTimer(): void;\n\n /** `AbortSignal` that is aborted when `dispose()` is called. */\n readonly disposalSignal: AbortSignal;\n\n /**\n * Clears all listeners, cancels any pending timer, and marks the core as disposed.\n * Subsequent method calls on the core become no-ops.\n */\n dispose(): void;\n\n /**\n * If a timer is scheduled, cancels it and immediately invokes `fn`.\n * Returns a resolved Promise when no timer is pending.\n */\n flush(fn: () => Promise<void>): Promise<void>;\n\n /** Whether `dispose()` has been called. All methods become no-ops after disposal. */\n readonly isDisposed: boolean;\n\n /** Whether a debounce timer is currently scheduled (drives `meta.isSearchPending`). */\n readonly isScheduled: boolean;\n\n /**\n * Fire all registered listeners and wake any `ready()` waiters.\n * When provided, `onBefore` runs once before listeners are called — use it to\n * refresh cached meta/current before subscribers observe the new state.\n */\n notify(onBefore?: () => void): void;\n\n /**\n * Returns a Promise that resolves when `isIdle()` returns true.\n * Resolves synchronously if already idle.\n * Rejects with a `TimeoutError` after `timeoutMs` ms if still not idle.\n */\n ready(isIdle: () => boolean, timeoutMs?: number): Promise<void>;\n\n /**\n * Schedules a debounced callback, replacing any pending timer.\n * The callback is invoked after `delayMs` ms of inactivity.\n */\n schedule(fn: () => void, delayMs: number): void;\n\n /** Subscribe to change notifications. Returns an unsubscribe function. */\n subscribe(listener: () => void): () => void;\n};\n\nexport function createSourceCore(opts?: { onBeforeNotify?: () => void }): SourceCore {\n const listeners = new Set<() => void>();\n const readyWaiters = new Set<{\n check: () => void;\n reject: (err: unknown) => void;\n timeoutId?: ReturnType<typeof setTimeout>;\n }>();\n const controller = new AbortController();\n let timer: ReturnType<typeof setTimeout> | undefined;\n let disposed = false;\n\n return {\n cancelTimer() {\n if (timer) {\n clearTimeout(timer);\n timer = undefined;\n }\n },\n\n get disposalSignal() {\n return controller.signal;\n },\n\n dispose() {\n if (timer) {\n clearTimeout(timer);\n timer = undefined;\n }\n\n for (const waiter of readyWaiters) {\n if (waiter.timeoutId !== undefined) clearTimeout(waiter.timeoutId);\n\n waiter.reject(new SourcererDisposedError());\n }\n\n readyWaiters.clear();\n listeners.clear();\n disposed = true;\n controller.abort();\n },\n\n flush(fn) {\n if (!timer) return Promise.resolve();\n\n clearTimeout(timer);\n timer = undefined;\n\n return fn();\n },\n\n get isDisposed() {\n return disposed;\n },\n\n get isScheduled() {\n return timer !== undefined;\n },\n\n notify(onBefore?: () => void) {\n if (disposed) return;\n\n (onBefore ?? opts?.onBeforeNotify)?.();\n\n for (const listener of listeners) {\n listener();\n }\n\n for (const waiter of readyWaiters) {\n waiter.check();\n }\n },\n\n ready(isIdle, timeoutMs) {\n if (disposed) return Promise.reject(new SourcererDisposedError());\n\n if (isIdle()) return Promise.resolve();\n\n return new Promise<void>((resolve, reject) => {\n const waiter: { check: () => void; reject: (err: unknown) => void; timeoutId?: ReturnType<typeof setTimeout> } =\n {\n check: () => {\n if (isIdle()) {\n if (waiter.timeoutId !== undefined) clearTimeout(waiter.timeoutId);\n\n readyWaiters.delete(waiter);\n resolve();\n }\n },\n reject,\n };\n\n if (timeoutMs !== undefined) {\n waiter.timeoutId = setTimeout(() => {\n readyWaiters.delete(waiter);\n reject(new SourcererTimeoutError(timeoutMs));\n }, timeoutMs);\n }\n\n readyWaiters.add(waiter);\n });\n },\n\n schedule(fn, delayMs) {\n if (disposed) return;\n\n if (timer) clearTimeout(timer);\n\n timer = setTimeout(() => {\n timer = undefined;\n fn();\n }, delayMs);\n },\n\n subscribe(listener) {\n if (disposed) return () => {};\n\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n },\n };\n}\n"],"mappings":"gCA+EA,SAAgB,EAAiB,EAAoD,CACnF,IAAM,EAAY,IAAI,IAChB,EAAe,IAAI,IAKnB,EAAa,IAAI,gBACnB,EACA,EAAW,GAEf,MAAO,CACL,aAAc,CACZ,AAEE,KADA,aAAa,CAAK,EACV,IAAA,GAEZ,EAEA,IAAI,gBAAiB,CACnB,OAAO,EAAW,MACpB,EAEA,SAAU,CACR,AAEE,KADA,aAAa,CAAK,EACV,IAAA,IAGV,IAAK,IAAM,KAAU,EACf,EAAO,YAAc,IAAA,IAAW,aAAa,EAAO,SAAS,EAEjE,EAAO,OAAO,IAAI,EAAA,sBAAwB,EAG5C,EAAa,MAAM,EACnB,EAAU,MAAM,EAChB,EAAW,GACX,EAAW,MAAM,CACnB,EAEA,MAAM,EAAI,CAMR,OALK,GAEL,aAAa,CAAK,EAClB,EAAQ,IAAA,GAED,EAAG,GALS,QAAQ,QAAQ,CAMrC,EAEA,IAAI,YAAa,CACf,OAAO,CACT,EAEA,IAAI,aAAc,CAChB,OAAO,IAAU,IAAA,EACnB,EAEA,OAAO,EAAuB,CACxB,MAEJ,EAAC,GAAY,GAAM,eAAA,GAAkB,EAErC,IAAK,IAAM,KAAY,EACrB,EAAS,EAGX,IAAK,IAAM,KAAU,EACnB,EAAO,MAAM,CAPsB,CASvC,EAEA,MAAM,EAAQ,EAAW,CAKvB,OAJI,EAAiB,QAAQ,OAAO,IAAI,EAAA,sBAAwB,EAE5D,EAAO,EAAU,QAAQ,QAAQ,EAE9B,IAAI,SAAe,EAAS,IAAW,CAC5C,IAAM,EACJ,CACE,UAAa,CACP,EAAO,IACL,EAAO,YAAc,IAAA,IAAW,aAAa,EAAO,SAAS,EAEjE,EAAa,OAAO,CAAM,EAC1B,EAAQ,EAEZ,EACA,QACF,EAEE,IAAc,IAAA,KAChB,EAAO,UAAY,eAAiB,CAClC,EAAa,OAAO,CAAM,EAC1B,EAAO,IAAI,EAAA,sBAAsB,CAAS,CAAC,CAC7C,EAAG,CAAS,GAGd,EAAa,IAAI,CAAM,CACzB,CAAC,CACH,EAEA,SAAS,EAAI,EAAS,CAChB,IAEA,GAAO,aAAa,CAAK,EAE7B,EAAQ,eAAiB,CACvB,EAAQ,IAAA,GACR,EAAG,CACL,EAAG,CAAO,EACZ,EAEA,UAAU,EAAU,CAKlB,OAJI,MAAuB,CAAC,GAE5B,EAAU,IAAI,CAAQ,MAET,EAAU,OAAO,CAAQ,EACxC,CACF,CACF"}
|
package/dist/core.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared source infrastructure: change notification, debounce scheduling, and ready() polling.
|
|
3
|
-
* All source factories compose this core rather than duplicating the same patterns.
|
|
4
|
-
*
|
|
5
|
-
* Change notification is a plain `Set<listener>` — deliberately NOT `@vielzeug/ripple`, despite
|
|
6
|
-
* that being the repo-wide convention for "reactive" packages. Tried it; reverted. Two concrete
|
|
7
|
-
* problems, not just aesthetics:
|
|
8
|
-
*
|
|
9
|
-
* 1. `prefetchSource()`/`prefetchSourceAndKeep()` are explicitly documented for SSR, and every
|
|
10
|
-
* source factory routes through this file's `signal`-backed notify. Ripple's own scheduler
|
|
11
|
-
* warns that its module-level flush queue is shared across concurrent requests in Node.js
|
|
12
|
-
* unless the caller opts into `@vielzeug/ripple/ssr`'s per-request isolation — a real,
|
|
13
|
-
* unaddressed risk in exactly the code path meant to run on a server handling concurrent
|
|
14
|
-
* requests.
|
|
15
|
-
* 2. `subscribe()`'s public contract is "fire on every notify()", not per-field reactivity —
|
|
16
|
-
* ripple's dependency-tracking machinery (a real subscription object per `watch()` call)
|
|
17
|
-
* buys nothing over a bare `Set.add()` for that contract, since there's exactly one thing
|
|
18
|
-
* ever being watched (an internal version counter, not real data).
|
|
19
|
-
*
|
|
20
|
-
* `current`/`meta` themselves were never ripple signals either way — the public shape has
|
|
21
|
-
* always been plain getters + `subscribe()`, framework-agnostic by design (see `types.ts`'s
|
|
22
|
-
* `ReactiveSource` doc comment). Nothing about restoring a plain `Set` changes that contract.
|
|
23
|
-
*
|
|
24
|
-
* Debounce scheduling and `ready()`'s "resolve when idle, with a timeout" polling were never
|
|
25
|
-
* ripple's job either way: ripple is a dependency-tracking signal system ("notify when a value
|
|
26
|
-
* changes"), not an async-coordination library ("wait for a condition, with a timeout, and
|
|
27
|
-
* reject if disposed first").
|
|
28
|
-
*/
|
|
29
|
-
export type SourceCore = {
|
|
30
|
-
/** Cancels any pending timer without invoking the callback. */
|
|
31
|
-
cancelTimer(): void;
|
|
32
|
-
/** `AbortSignal` that is aborted when `dispose()` is called. */
|
|
33
|
-
readonly disposalSignal: AbortSignal;
|
|
34
|
-
/**
|
|
35
|
-
* Clears all listeners, cancels any pending timer, and marks the core as disposed.
|
|
36
|
-
* Subsequent method calls on the core become no-ops.
|
|
37
|
-
*/
|
|
38
|
-
dispose(): void;
|
|
39
|
-
/**
|
|
40
|
-
* If a timer is scheduled, cancels it and immediately invokes `fn`.
|
|
41
|
-
* Returns a resolved Promise when no timer is pending.
|
|
42
|
-
*/
|
|
43
|
-
flush(fn: () => Promise<void>): Promise<void>;
|
|
44
|
-
/** Whether `dispose()` has been called. All methods become no-ops after disposal. */
|
|
45
|
-
readonly isDisposed: boolean;
|
|
46
|
-
/** Whether a debounce timer is currently scheduled (drives `meta.isSearchPending`). */
|
|
47
|
-
readonly isScheduled: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Fire all registered listeners and wake any `ready()` waiters.
|
|
50
|
-
* When provided, `onBefore` runs once before listeners are called — use it to
|
|
51
|
-
* refresh cached meta/current before subscribers observe the new state.
|
|
52
|
-
*/
|
|
53
|
-
notify(onBefore?: () => void): void;
|
|
54
|
-
/**
|
|
55
|
-
* Returns a Promise that resolves when `isIdle()` returns true.
|
|
56
|
-
* Resolves synchronously if already idle.
|
|
57
|
-
* Rejects with a `TimeoutError` after `timeoutMs` ms if still not idle.
|
|
58
|
-
*/
|
|
59
|
-
ready(isIdle: () => boolean, timeoutMs?: number): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Schedules a debounced callback, replacing any pending timer.
|
|
62
|
-
* The callback is invoked after `delayMs` ms of inactivity.
|
|
63
|
-
*/
|
|
64
|
-
schedule(fn: () => void, delayMs: number): void;
|
|
65
|
-
/** Subscribe to change notifications. Returns an unsubscribe function. */
|
|
66
|
-
subscribe(listener: () => void): () => void;
|
|
67
|
-
};
|
|
68
|
-
export declare function createSourceCore(opts?: {
|
|
69
|
-
onBeforeNotify?: () => void;
|
|
70
|
-
}): SourceCore;
|
|
71
|
-
//# sourceMappingURL=core.d.ts.map
|
package/dist/core.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,+DAA+D;IAC/D,WAAW,IAAI,IAAI,CAAC;IAEpB,gEAAgE;IAChE,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC;IAErC;;;OAGG;IACH,OAAO,IAAI,IAAI,CAAC;IAEhB;;;OAGG;IACH,KAAK,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9C,qFAAqF;IACrF,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,uFAAuF;IACvF,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAE9B;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAEpC;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhE;;;OAGG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEhD,0EAA0E;IAC1E,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;CAC7C,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE;IAAE,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;CAAE,GAAG,UAAU,CAyHnF"}
|
package/dist/core.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { SourcererDisposedError as e, SourcererTimeoutError as t } from "./errors.js";
|
|
2
|
-
//#region src/core.ts
|
|
3
|
-
function n(n) {
|
|
4
|
-
let r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = new AbortController(), o, s = !1;
|
|
5
|
-
return {
|
|
6
|
-
cancelTimer() {
|
|
7
|
-
o &&= (clearTimeout(o), void 0);
|
|
8
|
-
},
|
|
9
|
-
get disposalSignal() {
|
|
10
|
-
return a.signal;
|
|
11
|
-
},
|
|
12
|
-
dispose() {
|
|
13
|
-
o &&= (clearTimeout(o), void 0);
|
|
14
|
-
for (let t of i) t.timeoutId !== void 0 && clearTimeout(t.timeoutId), t.reject(new e());
|
|
15
|
-
i.clear(), r.clear(), s = !0, a.abort();
|
|
16
|
-
},
|
|
17
|
-
flush(e) {
|
|
18
|
-
return o ? (clearTimeout(o), o = void 0, e()) : Promise.resolve();
|
|
19
|
-
},
|
|
20
|
-
get isDisposed() {
|
|
21
|
-
return s;
|
|
22
|
-
},
|
|
23
|
-
get isScheduled() {
|
|
24
|
-
return o !== void 0;
|
|
25
|
-
},
|
|
26
|
-
notify(e) {
|
|
27
|
-
if (!s) {
|
|
28
|
-
(e ?? n?.onBeforeNotify)?.();
|
|
29
|
-
for (let e of r) e();
|
|
30
|
-
for (let e of i) e.check();
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
ready(n, r) {
|
|
34
|
-
return s ? Promise.reject(new e()) : n() ? Promise.resolve() : new Promise((e, a) => {
|
|
35
|
-
let o = {
|
|
36
|
-
check: () => {
|
|
37
|
-
n() && (o.timeoutId !== void 0 && clearTimeout(o.timeoutId), i.delete(o), e());
|
|
38
|
-
},
|
|
39
|
-
reject: a
|
|
40
|
-
};
|
|
41
|
-
r !== void 0 && (o.timeoutId = setTimeout(() => {
|
|
42
|
-
i.delete(o), a(new t(r));
|
|
43
|
-
}, r)), i.add(o);
|
|
44
|
-
});
|
|
45
|
-
},
|
|
46
|
-
schedule(e, t) {
|
|
47
|
-
s || (o && clearTimeout(o), o = setTimeout(() => {
|
|
48
|
-
o = void 0, e();
|
|
49
|
-
}, t));
|
|
50
|
-
},
|
|
51
|
-
subscribe(e) {
|
|
52
|
-
return s ? () => {} : (r.add(e), () => r.delete(e));
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
//#endregion
|
|
57
|
-
export { n as createSourceCore };
|
|
58
|
-
|
|
59
|
-
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import { SourcererDisposedError, SourcererTimeoutError } from './errors';\n\n/**\n * Shared source infrastructure: change notification, debounce scheduling, and ready() polling.\n * All source factories compose this core rather than duplicating the same patterns.\n *\n * Change notification is a plain `Set<listener>` — deliberately NOT `@vielzeug/ripple`, despite\n * that being the repo-wide convention for \"reactive\" packages. Tried it; reverted. Two concrete\n * problems, not just aesthetics:\n *\n * 1. `prefetchSource()`/`prefetchSourceAndKeep()` are explicitly documented for SSR, and every\n * source factory routes through this file's `signal`-backed notify. Ripple's own scheduler\n * warns that its module-level flush queue is shared across concurrent requests in Node.js\n * unless the caller opts into `@vielzeug/ripple/ssr`'s per-request isolation — a real,\n * unaddressed risk in exactly the code path meant to run on a server handling concurrent\n * requests.\n * 2. `subscribe()`'s public contract is \"fire on every notify()\", not per-field reactivity —\n * ripple's dependency-tracking machinery (a real subscription object per `watch()` call)\n * buys nothing over a bare `Set.add()` for that contract, since there's exactly one thing\n * ever being watched (an internal version counter, not real data).\n *\n * `current`/`meta` themselves were never ripple signals either way — the public shape has\n * always been plain getters + `subscribe()`, framework-agnostic by design (see `types.ts`'s\n * `ReactiveSource` doc comment). Nothing about restoring a plain `Set` changes that contract.\n *\n * Debounce scheduling and `ready()`'s \"resolve when idle, with a timeout\" polling were never\n * ripple's job either way: ripple is a dependency-tracking signal system (\"notify when a value\n * changes\"), not an async-coordination library (\"wait for a condition, with a timeout, and\n * reject if disposed first\").\n */\nexport type SourceCore = {\n /** Cancels any pending timer without invoking the callback. */\n cancelTimer(): void;\n\n /** `AbortSignal` that is aborted when `dispose()` is called. */\n readonly disposalSignal: AbortSignal;\n\n /**\n * Clears all listeners, cancels any pending timer, and marks the core as disposed.\n * Subsequent method calls on the core become no-ops.\n */\n dispose(): void;\n\n /**\n * If a timer is scheduled, cancels it and immediately invokes `fn`.\n * Returns a resolved Promise when no timer is pending.\n */\n flush(fn: () => Promise<void>): Promise<void>;\n\n /** Whether `dispose()` has been called. All methods become no-ops after disposal. */\n readonly isDisposed: boolean;\n\n /** Whether a debounce timer is currently scheduled (drives `meta.isSearchPending`). */\n readonly isScheduled: boolean;\n\n /**\n * Fire all registered listeners and wake any `ready()` waiters.\n * When provided, `onBefore` runs once before listeners are called — use it to\n * refresh cached meta/current before subscribers observe the new state.\n */\n notify(onBefore?: () => void): void;\n\n /**\n * Returns a Promise that resolves when `isIdle()` returns true.\n * Resolves synchronously if already idle.\n * Rejects with a `TimeoutError` after `timeoutMs` ms if still not idle.\n */\n ready(isIdle: () => boolean, timeoutMs?: number): Promise<void>;\n\n /**\n * Schedules a debounced callback, replacing any pending timer.\n * The callback is invoked after `delayMs` ms of inactivity.\n */\n schedule(fn: () => void, delayMs: number): void;\n\n /** Subscribe to change notifications. Returns an unsubscribe function. */\n subscribe(listener: () => void): () => void;\n};\n\nexport function createSourceCore(opts?: { onBeforeNotify?: () => void }): SourceCore {\n const listeners = new Set<() => void>();\n const readyWaiters = new Set<{\n check: () => void;\n reject: (err: unknown) => void;\n timeoutId?: ReturnType<typeof setTimeout>;\n }>();\n const controller = new AbortController();\n let timer: ReturnType<typeof setTimeout> | undefined;\n let disposed = false;\n\n return {\n cancelTimer() {\n if (timer) {\n clearTimeout(timer);\n timer = undefined;\n }\n },\n\n get disposalSignal() {\n return controller.signal;\n },\n\n dispose() {\n if (timer) {\n clearTimeout(timer);\n timer = undefined;\n }\n\n for (const waiter of readyWaiters) {\n if (waiter.timeoutId !== undefined) clearTimeout(waiter.timeoutId);\n\n waiter.reject(new SourcererDisposedError());\n }\n\n readyWaiters.clear();\n listeners.clear();\n disposed = true;\n controller.abort();\n },\n\n flush(fn) {\n if (!timer) return Promise.resolve();\n\n clearTimeout(timer);\n timer = undefined;\n\n return fn();\n },\n\n get isDisposed() {\n return disposed;\n },\n\n get isScheduled() {\n return timer !== undefined;\n },\n\n notify(onBefore?: () => void) {\n if (disposed) return;\n\n (onBefore ?? opts?.onBeforeNotify)?.();\n\n for (const listener of listeners) {\n listener();\n }\n\n for (const waiter of readyWaiters) {\n waiter.check();\n }\n },\n\n ready(isIdle, timeoutMs) {\n if (disposed) return Promise.reject(new SourcererDisposedError());\n\n if (isIdle()) return Promise.resolve();\n\n return new Promise<void>((resolve, reject) => {\n const waiter: { check: () => void; reject: (err: unknown) => void; timeoutId?: ReturnType<typeof setTimeout> } =\n {\n check: () => {\n if (isIdle()) {\n if (waiter.timeoutId !== undefined) clearTimeout(waiter.timeoutId);\n\n readyWaiters.delete(waiter);\n resolve();\n }\n },\n reject,\n };\n\n if (timeoutMs !== undefined) {\n waiter.timeoutId = setTimeout(() => {\n readyWaiters.delete(waiter);\n reject(new SourcererTimeoutError(timeoutMs));\n }, timeoutMs);\n }\n\n readyWaiters.add(waiter);\n });\n },\n\n schedule(fn, delayMs) {\n if (disposed) return;\n\n if (timer) clearTimeout(timer);\n\n timer = setTimeout(() => {\n timer = undefined;\n fn();\n }, delayMs);\n },\n\n subscribe(listener) {\n if (disposed) return () => {};\n\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n },\n };\n}\n"],"mappings":";;AA+EA,SAAgB,EAAiB,GAAoD;CACnF,IAAM,oBAAY,IAAI,IAAgB,GAChC,oBAAe,IAAI,IAItB,GACG,IAAa,IAAI,gBAAgB,GACnC,GACA,IAAW;CAEf,OAAO;EACL,cAAc;GACZ,AAEE,OADA,aAAa,CAAK,GACV,KAAA;EAEZ;EAEA,IAAI,iBAAiB;GACnB,OAAO,EAAW;EACpB;EAEA,UAAU;GACR,AAEE,OADA,aAAa,CAAK,GACV,KAAA;GAGV,KAAK,IAAM,KAAU,GAGnB,AAFI,EAAO,cAAc,KAAA,KAAW,aAAa,EAAO,SAAS,GAEjE,EAAO,OAAO,IAAI,EAAuB,CAAC;GAM5C,AAHA,EAAa,MAAM,GACnB,EAAU,MAAM,GAChB,IAAW,IACX,EAAW,MAAM;EACnB;EAEA,MAAM,GAAI;GAMR,OALK,KAEL,aAAa,CAAK,GAClB,IAAQ,KAAA,GAED,EAAG,KALS,QAAQ,QAAQ;EAMrC;EAEA,IAAI,aAAa;GACf,OAAO;EACT;EAEA,IAAI,cAAc;GAChB,OAAO,MAAU,KAAA;EACnB;EAEA,OAAO,GAAuB;GACxB,QAEJ;KAAC,KAAY,GAAM,eAAA,GAAkB;IAErC,KAAK,IAAM,KAAY,GACrB,EAAS;IAGX,KAAK,IAAM,KAAU,GACnB,EAAO,MAAM;GAPsB;EASvC;EAEA,MAAM,GAAQ,GAAW;GAKvB,OAJI,IAAiB,QAAQ,OAAO,IAAI,EAAuB,CAAC,IAE5D,EAAO,IAAU,QAAQ,QAAQ,IAE9B,IAAI,SAAe,GAAS,MAAW;IAC5C,IAAM,IACJ;KACE,aAAa;MACX,AAAI,EAAO,MACL,EAAO,cAAc,KAAA,KAAW,aAAa,EAAO,SAAS,GAEjE,EAAa,OAAO,CAAM,GAC1B,EAAQ;KAEZ;KACA;IACF;IASF,AAPI,MAAc,KAAA,MAChB,EAAO,YAAY,iBAAiB;KAElC,AADA,EAAa,OAAO,CAAM,GAC1B,EAAO,IAAI,EAAsB,CAAS,CAAC;IAC7C,GAAG,CAAS,IAGd,EAAa,IAAI,CAAM;GACzB,CAAC;EACH;EAEA,SAAS,GAAI,GAAS;GAChB,MAEA,KAAO,aAAa,CAAK,GAE7B,IAAQ,iBAAiB;IAEvB,AADA,IAAQ,KAAA,GACR,EAAG;GACL,GAAG,CAAO;EACZ;EAEA,UAAU,GAAU;GAKlB,OAJI,UAAuB,CAAC,KAE5B,EAAU,IAAI,CAAQ,SAET,EAAU,OAAO,CAAQ;EACxC;CACF;AACF"}
|
package/dist/derive.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("./core.cjs");function t(t,n){let r=e.createSourceCore(),i=[],a=()=>{i=n(t.current)};a();let o=t.subscribe(()=>{a(),r.notify()}),s={get current(){return i},get disposalSignal(){return r.disposalSignal},dispose(){r.isDisposed||(o(),r.dispose())},get disposed(){return r.isDisposed},get meta(){return t.meta},subscribe(e){return r.subscribe(e)},[Symbol.dispose](){s.dispose()}};return t.disposalSignal instanceof AbortSignal&&t.disposalSignal.addEventListener(`abort`,()=>s.dispose(),{once:!0}),s}exports.deriveSource=t;
|
|
2
|
-
//# sourceMappingURL=derive.cjs.map
|
package/dist/derive.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"derive.cjs","names":[],"sources":["../src/derive.ts"],"sourcesContent":["import type { DerivedSource } from './types';\n\nimport { createSourceCore } from './core';\n\n/**\n * Creates a reactive read-only projection derived from a parent source.\n *\n * The derived source mirrors the parent's `meta` and applies `transform` to `current`\n * whenever the parent changes. This is useful for client-side projections (e.g. additional\n * filtering, mapping, or sorting) over a remote source without re-fetching.\n *\n * Call `dispose()` to stop listening to the parent.\n *\n * @example\n * ```ts\n * const source = createRemoteSource<User>({ fetch: fetchUsers, limit: 20 });\n *\n * // Show only active users without re-fetching.\n * const activeUsers = deriveSource(source, (items) => items.filter((u) => u.active));\n *\n * activeUsers.subscribe(() => {\n * console.log(activeUsers.current, activeUsers.meta.totalItems);\n * });\n * ```\n */\nexport function deriveSource<T, U, TMeta>(\n parent: {\n readonly current: readonly T[];\n readonly disposalSignal?: AbortSignal;\n readonly meta: TMeta;\n subscribe(listener: () => void): () => void;\n },\n transform: (items: readonly T[]) => readonly U[],\n): DerivedSource<U, TMeta> {\n const core = createSourceCore();\n let cachedCurrent: readonly U[] = [];\n\n const applyTransform = () => {\n cachedCurrent = transform(parent.current);\n };\n\n applyTransform();\n\n const unsubscribeParent = parent.subscribe(() => {\n applyTransform();\n core.notify();\n });\n\n const source: DerivedSource<U, TMeta> = {\n get current() {\n return cachedCurrent;\n },\n\n get disposalSignal() {\n return core.disposalSignal;\n },\n\n dispose() {\n if (core.isDisposed) return;\n\n unsubscribeParent();\n core.dispose();\n },\n\n get disposed() {\n return core.isDisposed;\n },\n\n get meta() {\n return parent.meta;\n },\n\n subscribe(listener) {\n return core.subscribe(listener);\n },\n\n [Symbol.dispose]() {\n source.dispose();\n },\n };\n\n // Only tracked when the parent actually exposes a disposalSignal — deriveSource() also\n // accepts minimal duck-typed parents (per its parameter type) that may not have one.\n // Routed through the same `dispose()` method above, not `core.dispose()` directly, so there's\n // exactly one cleanup path regardless of what triggered it.\n if (parent.disposalSignal instanceof AbortSignal) {\n parent.disposalSignal.addEventListener('abort', () => source.dispose(), { once: true });\n }\n\n return source;\n}\n"],"mappings":"8BAyBA,SAAgB,EACd,EAMA,EACyB,CACzB,IAAM,EAAO,EAAA,iBAAiB,EAC1B,EAA8B,CAAC,EAE7B,MAAuB,CAC3B,EAAgB,EAAU,EAAO,OAAO,CAC1C,EAEA,EAAe,EAEf,IAAM,EAAoB,EAAO,cAAgB,CAC/C,EAAe,EACf,EAAK,OAAO,CACd,CAAC,EAEK,EAAkC,CACtC,IAAI,SAAU,CACZ,OAAO,CACT,EAEA,IAAI,gBAAiB,CACnB,OAAO,EAAK,cACd,EAEA,SAAU,CACJ,EAAK,aAET,EAAkB,EAClB,EAAK,QAAQ,EACf,EAEA,IAAI,UAAW,CACb,OAAO,EAAK,UACd,EAEA,IAAI,MAAO,CACT,OAAO,EAAO,IAChB,EAEA,UAAU,EAAU,CAClB,OAAO,EAAK,UAAU,CAAQ,CAChC,EAEA,CAAC,OAAO,UAAW,CACjB,EAAO,QAAQ,CACjB,CACF,EAUA,OAJI,EAAO,0BAA0B,aACnC,EAAO,eAAe,iBAAiB,YAAe,EAAO,QAAQ,EAAG,CAAE,KAAM,EAAK,CAAC,EAGjF,CACT"}
|
package/dist/derive.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { DerivedSource } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a reactive read-only projection derived from a parent source.
|
|
4
|
-
*
|
|
5
|
-
* The derived source mirrors the parent's `meta` and applies `transform` to `current`
|
|
6
|
-
* whenever the parent changes. This is useful for client-side projections (e.g. additional
|
|
7
|
-
* filtering, mapping, or sorting) over a remote source without re-fetching.
|
|
8
|
-
*
|
|
9
|
-
* Call `dispose()` to stop listening to the parent.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* const source = createRemoteSource<User>({ fetch: fetchUsers, limit: 20 });
|
|
14
|
-
*
|
|
15
|
-
* // Show only active users without re-fetching.
|
|
16
|
-
* const activeUsers = deriveSource(source, (items) => items.filter((u) => u.active));
|
|
17
|
-
*
|
|
18
|
-
* activeUsers.subscribe(() => {
|
|
19
|
-
* console.log(activeUsers.current, activeUsers.meta.totalItems);
|
|
20
|
-
* });
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export declare function deriveSource<T, U, TMeta>(parent: {
|
|
24
|
-
readonly current: readonly T[];
|
|
25
|
-
readonly disposalSignal?: AbortSignal;
|
|
26
|
-
readonly meta: TMeta;
|
|
27
|
-
subscribe(listener: () => void): () => void;
|
|
28
|
-
}, transform: (items: readonly T[]) => readonly U[]): DerivedSource<U, TMeta>;
|
|
29
|
-
//# sourceMappingURL=derive.d.ts.map
|
package/dist/derive.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"derive.d.ts","sourceRoot":"","sources":["../src/derive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAI7C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EACtC,MAAM,EAAE;IACN,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC;IAC/B,QAAQ,CAAC,cAAc,CAAC,EAAE,WAAW,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;CAC7C,EACD,SAAS,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,KAAK,SAAS,CAAC,EAAE,GAC/C,aAAa,CAAC,CAAC,EAAE,KAAK,CAAC,CAyDzB"}
|
package/dist/derive.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { createSourceCore as e } from "./core.js";
|
|
2
|
-
//#region src/derive.ts
|
|
3
|
-
function t(t, n) {
|
|
4
|
-
let r = e(), i = [], a = () => {
|
|
5
|
-
i = n(t.current);
|
|
6
|
-
};
|
|
7
|
-
a();
|
|
8
|
-
let o = t.subscribe(() => {
|
|
9
|
-
a(), r.notify();
|
|
10
|
-
}), s = {
|
|
11
|
-
get current() {
|
|
12
|
-
return i;
|
|
13
|
-
},
|
|
14
|
-
get disposalSignal() {
|
|
15
|
-
return r.disposalSignal;
|
|
16
|
-
},
|
|
17
|
-
dispose() {
|
|
18
|
-
r.isDisposed || (o(), r.dispose());
|
|
19
|
-
},
|
|
20
|
-
get disposed() {
|
|
21
|
-
return r.isDisposed;
|
|
22
|
-
},
|
|
23
|
-
get meta() {
|
|
24
|
-
return t.meta;
|
|
25
|
-
},
|
|
26
|
-
subscribe(e) {
|
|
27
|
-
return r.subscribe(e);
|
|
28
|
-
},
|
|
29
|
-
[Symbol.dispose]() {
|
|
30
|
-
s.dispose();
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
return t.disposalSignal instanceof AbortSignal && t.disposalSignal.addEventListener("abort", () => s.dispose(), { once: !0 }), s;
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
36
|
-
export { t as deriveSource };
|
|
37
|
-
|
|
38
|
-
//# sourceMappingURL=derive.js.map
|
package/dist/derive.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"derive.js","names":[],"sources":["../src/derive.ts"],"sourcesContent":["import type { DerivedSource } from './types';\n\nimport { createSourceCore } from './core';\n\n/**\n * Creates a reactive read-only projection derived from a parent source.\n *\n * The derived source mirrors the parent's `meta` and applies `transform` to `current`\n * whenever the parent changes. This is useful for client-side projections (e.g. additional\n * filtering, mapping, or sorting) over a remote source without re-fetching.\n *\n * Call `dispose()` to stop listening to the parent.\n *\n * @example\n * ```ts\n * const source = createRemoteSource<User>({ fetch: fetchUsers, limit: 20 });\n *\n * // Show only active users without re-fetching.\n * const activeUsers = deriveSource(source, (items) => items.filter((u) => u.active));\n *\n * activeUsers.subscribe(() => {\n * console.log(activeUsers.current, activeUsers.meta.totalItems);\n * });\n * ```\n */\nexport function deriveSource<T, U, TMeta>(\n parent: {\n readonly current: readonly T[];\n readonly disposalSignal?: AbortSignal;\n readonly meta: TMeta;\n subscribe(listener: () => void): () => void;\n },\n transform: (items: readonly T[]) => readonly U[],\n): DerivedSource<U, TMeta> {\n const core = createSourceCore();\n let cachedCurrent: readonly U[] = [];\n\n const applyTransform = () => {\n cachedCurrent = transform(parent.current);\n };\n\n applyTransform();\n\n const unsubscribeParent = parent.subscribe(() => {\n applyTransform();\n core.notify();\n });\n\n const source: DerivedSource<U, TMeta> = {\n get current() {\n return cachedCurrent;\n },\n\n get disposalSignal() {\n return core.disposalSignal;\n },\n\n dispose() {\n if (core.isDisposed) return;\n\n unsubscribeParent();\n core.dispose();\n },\n\n get disposed() {\n return core.isDisposed;\n },\n\n get meta() {\n return parent.meta;\n },\n\n subscribe(listener) {\n return core.subscribe(listener);\n },\n\n [Symbol.dispose]() {\n source.dispose();\n },\n };\n\n // Only tracked when the parent actually exposes a disposalSignal — deriveSource() also\n // accepts minimal duck-typed parents (per its parameter type) that may not have one.\n // Routed through the same `dispose()` method above, not `core.dispose()` directly, so there's\n // exactly one cleanup path regardless of what triggered it.\n if (parent.disposalSignal instanceof AbortSignal) {\n parent.disposalSignal.addEventListener('abort', () => source.dispose(), { once: true });\n }\n\n return source;\n}\n"],"mappings":";;AAyBA,SAAgB,EACd,GAMA,GACyB;CACzB,IAAM,IAAO,EAAiB,GAC1B,IAA8B,CAAC,GAE7B,UAAuB;EAC3B,IAAgB,EAAU,EAAO,OAAO;CAC1C;CAEA,EAAe;CAEf,IAAM,IAAoB,EAAO,gBAAgB;EAE/C,AADA,EAAe,GACf,EAAK,OAAO;CACd,CAAC,GAEK,IAAkC;EACtC,IAAI,UAAU;GACZ,OAAO;EACT;EAEA,IAAI,iBAAiB;GACnB,OAAO,EAAK;EACd;EAEA,UAAU;GACJ,EAAK,eAET,EAAkB,GAClB,EAAK,QAAQ;EACf;EAEA,IAAI,WAAW;GACb,OAAO,EAAK;EACd;EAEA,IAAI,OAAO;GACT,OAAO,EAAO;EAChB;EAEA,UAAU,GAAU;GAClB,OAAO,EAAK,UAAU,CAAQ;EAChC;EAEA,CAAC,OAAO,WAAW;GACjB,EAAO,QAAQ;EACjB;CACF;CAUA,OAJI,EAAO,0BAA0B,eACnC,EAAO,eAAe,iBAAiB,eAAe,EAAO,QAAQ,GAAG,EAAE,MAAM,GAAK,CAAC,GAGjF;AACT"}
|
package/dist/errors.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var e=class e extends Error{#e;constructor(e,t={}){super(e,t.cause===void 0?void 0:{cause:t.cause}),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype),this.#e=t}get attempt(){return this.#e.attempt??0}get context(){return this.#e.context}static is(t){return t instanceof e}},t=class extends e{timeoutMs;constructor(e){super(`Source.ready() timed out after ${e}ms`),this.timeoutMs=e}},n=class extends e{constructor(){super(`Source disposed while waiting for ready()`)}};exports.SourcererDisposedError=n,exports.SourcererError=e,exports.SourcererTimeoutError=t;
|
|
2
|
-
//# sourceMappingURL=errors.cjs.map
|
package/dist/errors.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","names":["#opts"],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Structured context carried by `SourcererError`.\n * Discriminated on `kind` — narrow with `error.context?.kind` to access typed fields.\n *\n * @example\n * ```ts\n * if (source.meta.error?.context?.kind === 'remote') {\n * console.log('Failed page', source.meta.error.context.page);\n * }\n * ```\n */\nexport type SourcererErrorContext =\n | Readonly<{ kind: 'cursor'; limit: number; search?: string }>\n | Readonly<{ kind: 'infinite'; limit: number; page: number; search?: string }>\n | Readonly<{ kind: 'remote'; limit: number; page: number; search?: string }>;\n\n/**\n * Base class for all sourcerer errors. Catch with `instanceof SourcererError` to handle any\n * sourcerer-originated error regardless of specific subtype.\n *\n * Carries the original cause, structured context, and the attempt number.\n *\n * @example\n * ```ts\n * if (source.meta.error) {\n * console.error(source.meta.error.message, source.meta.error.context);\n * }\n * ```\n */\nexport class SourcererError extends Error {\n readonly #opts: {\n readonly attempt?: number;\n readonly cause?: unknown;\n readonly context?: SourcererErrorContext;\n };\n\n constructor(\n message: string,\n opts: {\n readonly attempt?: number;\n readonly cause?: unknown;\n readonly context?: SourcererErrorContext;\n } = {},\n ) {\n super(message, opts.cause !== undefined ? { cause: opts.cause } : undefined);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n this.#opts = opts;\n }\n\n get attempt(): number {\n return this.#opts.attempt ?? 0;\n }\n\n /** Context bag for the error — safe to log. */\n get context(): SourcererErrorContext | undefined {\n return this.#opts.context;\n }\n\n static is(err: unknown): err is SourcererError {\n return err instanceof SourcererError;\n }\n}\n\n/** Thrown by `ready()` when the source timed out waiting for the first successful fetch. */\nexport class SourcererTimeoutError extends SourcererError {\n /** The configured timeout in milliseconds. */\n readonly timeoutMs: number;\n\n constructor(timeoutMs: number) {\n super(`Source.ready() timed out after ${timeoutMs}ms`);\n this.timeoutMs = timeoutMs;\n }\n}\n\n/** Thrown by `ready()` when the source is disposed while waiting. */\nexport class SourcererDisposedError extends SourcererError {\n constructor() {\n super('Source disposed while waiting for ready()');\n }\n}\n"],"mappings":"AA6BA,IAAa,EAAb,MAAa,UAAuB,KAAM,CACxC,GAMA,YACE,EACA,EAII,CAAC,EACL,CACA,MAAM,EAAS,EAAK,QAAU,IAAA,GAAoC,IAAA,GAAxB,CAAE,MAAO,EAAK,KAAM,CAAa,EAC3E,KAAK,KAAO,IAAI,OAAO,KACvB,OAAO,eAAe,KAAM,IAAI,OAAO,SAAS,EAChD,KAAKA,GAAQ,CACf,CAEA,IAAI,SAAkB,CACpB,OAAO,KAAKA,GAAM,SAAW,CAC/B,CAGA,IAAI,SAA6C,CAC/C,OAAO,KAAKA,GAAM,OACpB,CAEA,OAAO,GAAG,EAAqC,CAC7C,OAAO,aAAe,CACxB,CACF,EAGa,EAAb,cAA2C,CAAe,CAExD,UAEA,YAAY,EAAmB,CAC7B,MAAM,kCAAkC,EAAU,GAAG,EACrD,KAAK,UAAY,CACnB,CACF,EAGa,EAAb,cAA4C,CAAe,CACzD,aAAc,CACZ,MAAM,2CAA2C,CACnD,CACF"}
|
package/dist/errors.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Structured context carried by `SourcererError`.
|
|
3
|
-
* Discriminated on `kind` — narrow with `error.context?.kind` to access typed fields.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* if (source.meta.error?.context?.kind === 'remote') {
|
|
8
|
-
* console.log('Failed page', source.meta.error.context.page);
|
|
9
|
-
* }
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export type SourcererErrorContext = Readonly<{
|
|
13
|
-
kind: 'cursor';
|
|
14
|
-
limit: number;
|
|
15
|
-
search?: string;
|
|
16
|
-
}> | Readonly<{
|
|
17
|
-
kind: 'infinite';
|
|
18
|
-
limit: number;
|
|
19
|
-
page: number;
|
|
20
|
-
search?: string;
|
|
21
|
-
}> | Readonly<{
|
|
22
|
-
kind: 'remote';
|
|
23
|
-
limit: number;
|
|
24
|
-
page: number;
|
|
25
|
-
search?: string;
|
|
26
|
-
}>;
|
|
27
|
-
/**
|
|
28
|
-
* Base class for all sourcerer errors. Catch with `instanceof SourcererError` to handle any
|
|
29
|
-
* sourcerer-originated error regardless of specific subtype.
|
|
30
|
-
*
|
|
31
|
-
* Carries the original cause, structured context, and the attempt number.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* if (source.meta.error) {
|
|
36
|
-
* console.error(source.meta.error.message, source.meta.error.context);
|
|
37
|
-
* }
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export declare class SourcererError extends Error {
|
|
41
|
-
#private;
|
|
42
|
-
constructor(message: string, opts?: {
|
|
43
|
-
readonly attempt?: number;
|
|
44
|
-
readonly cause?: unknown;
|
|
45
|
-
readonly context?: SourcererErrorContext;
|
|
46
|
-
});
|
|
47
|
-
get attempt(): number;
|
|
48
|
-
/** Context bag for the error — safe to log. */
|
|
49
|
-
get context(): SourcererErrorContext | undefined;
|
|
50
|
-
static is(err: unknown): err is SourcererError;
|
|
51
|
-
}
|
|
52
|
-
/** Thrown by `ready()` when the source timed out waiting for the first successful fetch. */
|
|
53
|
-
export declare class SourcererTimeoutError extends SourcererError {
|
|
54
|
-
/** The configured timeout in milliseconds. */
|
|
55
|
-
readonly timeoutMs: number;
|
|
56
|
-
constructor(timeoutMs: number);
|
|
57
|
-
}
|
|
58
|
-
/** Thrown by `ready()` when the source is disposed while waiting. */
|
|
59
|
-
export declare class SourcererDisposedError extends SourcererError {
|
|
60
|
-
constructor();
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,qBAAqB,GAC7B,QAAQ,CAAC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAC5D,QAAQ,CAAC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAC5E,QAAQ,CAAC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE/E;;;;;;;;;;;;GAYG;AACH,qBAAa,cAAe,SAAQ,KAAK;;gBAQrC,OAAO,EAAE,MAAM,EACf,IAAI,GAAE;QACJ,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;QACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;KACrC;IAQR,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,+CAA+C;IAC/C,IAAI,OAAO,IAAI,qBAAqB,GAAG,SAAS,CAE/C;IAED,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc;CAG/C;AAED,4FAA4F;AAC5F,qBAAa,qBAAsB,SAAQ,cAAc;IACvD,8CAA8C;IAC9C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,SAAS,EAAE,MAAM;CAI9B;AAED,qEAAqE;AACrE,qBAAa,sBAAuB,SAAQ,cAAc;;CAIzD"}
|