@suluk/sdk 0.2.1 → 0.2.2
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/package.json +1 -1
- package/src/generate-stores.ts +13 -1
- package/test/stores.test.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suluk/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Generate a COMPLETE, intuitive TypeScript SDK from a v4 'Suluk' contract — built on ofetch, entity-grouped, fully typed from the schemas, auth wired (bearer/session) via interceptors, and the v4 superpowers (declared cost + access) surfaced as typed metadata. Not a bag of functions: a library a developer downloads and uses straight away. CANDIDATE tooling.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
package/src/generate-stores.ts
CHANGED
|
@@ -204,7 +204,19 @@ export interface CreateStoresOptions {
|
|
|
204
204
|
/** Create the reactive store layer for ${title}, bound to an SDK client. The contract declares the policy; you inject the rendering via \`hooks\`. */
|
|
205
205
|
export function createStores(client: SulukClient, options: CreateStoresOptions = {}) {
|
|
206
206
|
const hooks = options.hooks ?? createHooks<StoreHooks>();
|
|
207
|
-
|
|
207
|
+
// A bounded cache: @nanostores/query's default cache (a plain Map) is never evicted (cacheLifetime only gates a HIT),
|
|
208
|
+
// so a parameterized store driven by free text (a search box) would grow it for the page's lifetime. Cap it — evict
|
|
209
|
+
// the oldest entry past the limit (LRU-ish). The entry shape matches @nanostores/query's so the type stays exact.
|
|
210
|
+
const cache = new Map<string, { data?: unknown; error?: unknown; retryCount?: number; created?: number; expires?: number }>();
|
|
211
|
+
const _set = cache.set.bind(cache);
|
|
212
|
+
cache.set = (k, v) => {
|
|
213
|
+
if (!cache.has(k) && cache.size >= 500) {
|
|
214
|
+
const oldest = cache.keys().next().value;
|
|
215
|
+
if (oldest !== undefined) cache.delete(oldest);
|
|
216
|
+
}
|
|
217
|
+
return _set(k, v);
|
|
218
|
+
};
|
|
219
|
+
const [createFetcherStore, , ctx] = nanoquery({ cache });
|
|
208
220
|
/** last surfaced status per op — so an AUTO re-run of a failing query (retry-backoff / revalidate-on-focus) doesn't
|
|
209
221
|
* re-toast the SAME failure. A query clears its entry on success; user-triggered actions/one-offs pass dedupe=false. */
|
|
210
222
|
const _seen = new Map<string, number | "network">();
|
package/test/stores.test.ts
CHANGED
|
@@ -24,7 +24,8 @@ describe("@suluk/sdk generateStores — a typed Nano Stores reactive layer from
|
|
|
24
24
|
expect(stores).toContain('import { createHooks, type Hookable } from "hookable"');
|
|
25
25
|
expect(stores).toContain('import type { SulukClient } from "./sdk"'); // client TYPE only — self-contained
|
|
26
26
|
expect(stores).toContain("export function createStores(client: SulukClient");
|
|
27
|
-
expect(stores).toContain("const [createFetcherStore, , ctx] = nanoquery()");
|
|
27
|
+
expect(stores).toContain("const [createFetcherStore, , ctx] = nanoquery({ cache })"); // bounded cache (no unbounded growth)
|
|
28
|
+
expect(stores).toContain("if (!cache.has(k) && cache.size >= 500)");
|
|
28
29
|
expect(stores).toContain("Requires: `npm i @nanostores/query nanostores hookable`");
|
|
29
30
|
});
|
|
30
31
|
|