@open-mercato/cache 0.11.1-develop.8593.1.50784dae35 → 0.11.1-develop.8665.1.2455b2503c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/AGENTS.md +27 -21
  3. package/README.md +30 -0
  4. package/dist/codec.js +1 -74
  5. package/dist/codec.js.map +2 -2
  6. package/dist/defaults.js +1 -6
  7. package/dist/defaults.js.map +2 -2
  8. package/dist/errors.js +1 -12
  9. package/dist/errors.js.map +2 -2
  10. package/dist/index.js.map +1 -1
  11. package/dist/patterns.js +1 -35
  12. package/dist/patterns.js.map +2 -2
  13. package/dist/provider.js +440 -0
  14. package/dist/provider.js.map +7 -0
  15. package/dist/redisConnection.js +2 -0
  16. package/dist/redisConnection.js.map +7 -0
  17. package/dist/service.js +320 -80
  18. package/dist/service.js.map +3 -3
  19. package/dist/strategies/jsonfile.js +1 -186
  20. package/dist/strategies/jsonfile.js.map +3 -3
  21. package/dist/strategies/memory.js +1 -196
  22. package/dist/strategies/memory.js.map +3 -3
  23. package/dist/strategies/redis.js +1 -443
  24. package/dist/strategies/redis.js.map +3 -3
  25. package/dist/strategies/sqlite.js +1 -196
  26. package/dist/strategies/sqlite.js.map +3 -3
  27. package/dist/testing/conformance.js +448 -0
  28. package/dist/testing/conformance.js.map +7 -0
  29. package/dist/testing/index.js +12 -0
  30. package/dist/testing/index.js.map +7 -0
  31. package/dist/testing/remote.js +182 -0
  32. package/dist/testing/remote.js.map +7 -0
  33. package/fixtures/build-conformance-host.mjs +58 -0
  34. package/fixtures/cache-provider-fixture/index.d.ts +18 -0
  35. package/fixtures/cache-provider-fixture/index.js +307 -0
  36. package/fixtures/cache-provider-fixture/package.json +25 -0
  37. package/fixtures/conformance-child.mjs +41 -0
  38. package/jest.config.cjs +3 -1
  39. package/package.json +10 -2
  40. package/src/__tests__/cache-di-contract-docs.test.ts +2 -2
  41. package/src/__tests__/conformance.memory-provider.test.ts +77 -0
  42. package/src/__tests__/provider-fixture.packed.test.ts +178 -0
  43. package/src/__tests__/provider.test.ts +469 -0
  44. package/src/__tests__/service.provider.test.ts +513 -0
  45. package/src/__tests__/service.test.ts +94 -3
  46. package/src/codec.ts +1 -94
  47. package/src/defaults.ts +1 -2
  48. package/src/errors.ts +1 -14
  49. package/src/index.ts +4 -0
  50. package/src/patterns.ts +1 -40
  51. package/src/provider.ts +641 -0
  52. package/src/redisConnection.ts +1 -0
  53. package/src/service.ts +396 -89
  54. package/src/strategies/jsonfile.ts +1 -242
  55. package/src/strategies/memory.ts +1 -275
  56. package/src/strategies/redis.ts +1 -615
  57. package/src/strategies/sqlite.ts +1 -292
  58. package/src/testing/conformance.ts +569 -0
  59. package/src/testing/index.ts +11 -0
  60. package/src/testing/remote.ts +240 -0
  61. package/src/types.ts +8 -106
@@ -1,2 +1,2 @@
1
- [build:cache] found 12 entry points
1
+ [build:cache] found 17 entry points
2
2
  [build:cache] built successfully
package/AGENTS.md CHANGED
@@ -14,22 +14,33 @@ The `memory` strategy is per process: a write on one instance never invalidates
14
14
 
15
15
  ## Memory Strategy Bounds
16
16
 
17
- The memory strategy is bounded so a process-shared instance (`OM_BOOTSTRAP_CACHE`, long-lived workers, memory-backed CRUD list cache) cannot grow without limit on user-controllable key cardinality.
17
+ Bounded so a process-shared instance (`OM_BOOTSTRAP_CACHE`, workers, CRUD list cache) cannot grow with user-controlled key cardinality.
18
18
 
19
- - **LRU cap** — at most `maxEntries` entries are retained (default `50000`). Reads refresh recency (Map re-insertion); the least-recently-used entries are evicted on write once the cap is exceeded.
20
- - **`CACHE_MEMORY_MAX_ENTRIES`** — env override for the cap, resolved in the cache service. `.env.example` carries a commented `#CACHE_MEMORY_MAX_ENTRIES=50000`. A non-positive value (or an unparseable one — which is ignored, falling back to the default) disables the cap (**unbounded** — only safe for short-lived per-request instances).
21
- - **Amortized expired-entry sweep** — expired entries are reclaimed by a budgeted sweep that runs every 256 writes (no per-instance timer, so the per-request default stays leak-free). Each pass scans a bounded slice from the LRU head, so it stays `O(budget)` rather than scanning the whole store. Expired entries beyond the budget are still reclaimed on access, by LRU eviction, or via an explicit `cleanup()`.
22
- - **Observability** — `stats()` on a memory-backed service surfaces `evictions`, `sweeps`, and `lastSweepReclaimed` (process-global counters) alongside the tenant-scoped `size`/`expired`, so operators can tell whether the bound is actively protecting the process. Other backends omit these fields.
19
+ - **LRU cap** — `maxEntries` (default `50000`); reads refresh recency, writes evict the LRU entries past the cap. Override with `CACHE_MEMORY_MAX_ENTRIES` (commented in `.env.example`); a non-positive value disables the cap (**unbounded** — per-request instances only); an unparseable one is ignored.
20
+ - **Amortized sweep** — every 256 writes a budgeted `O(budget)` pass from the LRU head reclaims expired entries (no timer); the rest go on access, eviction or `cleanup()`.
21
+ - **Observability** — memory-backed `stats()` adds process-global `evictions`, `sweeps`, `lastSweepReclaimed` next to tenant-scoped `size`/`expired`; other backends omit them.
23
22
 
24
23
  ## Value Compression
25
24
 
26
25
  The redis and sqlite strategies can compress serialized entries (`packages/cache/src/codec.ts`); memory and jsonfile never do.
27
26
 
28
- - **`CACHE_COMPRESSION`** — `off` (default) | `zstd` | `gzip`. zstd runs at level 1, gzip at level 6. A `zstd` setting falls back to `gzip` with one warning on a runtime without zstd (the `node:zlib` zstd API is marked experimental).
29
- - **`CACHE_COMPRESSION_MIN_BYTES`** — entries smaller than this (default `1024`) stay plain JSON; a compressed form is kept only when it is smaller.
30
- - **Reads detect the format by magic bytes**, whatever the current setting, so legacy JSON, zstd and gzip entries coexist and switching the setting never strands an entry. Decompression is capped at 64 MiB; a corrupt frame is dropped as a miss.
31
- - **When to enable:** Redis on another host, or memory-bound Redis — fewer bytes over the network and in memory. Redis on localhost or SQLite saves memory/disk only, at a small read cost.
32
- - **Rollout:** deploy with compression `off`, enable it only once every instance runs a version with the codec, and set it back to `off` before rolling back to an older version (older versions read compressed entries as misses and delete them).
27
+ - **`CACHE_COMPRESSION`** — `off` (default) | `zstd` (level 1; falls back to `gzip` with one warning when the runtime lacks zstd) | `gzip` (level 6).
28
+ - **`CACHE_COMPRESSION_MIN_BYTES`** — smaller entries (default `1024`) stay plain JSON; compressed form kept only when smaller.
29
+ - **Reads detect the format by magic bytes**, so JSON, zstd and gzip entries coexist across setting changes. Decompression capped at 64 MiB; a corrupt frame is a miss.
30
+ - **Enable** for remote or memory-bound Redis; on localhost Redis/SQLite it only saves memory/disk at a small read cost.
31
+ - **Rollout:** enable only once every instance supports the codec; set `off` before rolling back (older versions drop compressed entries as misses).
32
+
33
+ ## Pluggable providers
34
+
35
+ An npm package can replace the stock strategies deployment-wide. Docs: `apps/docs/docs/architecture/cache-providers.mdx`.
36
+
37
+ - **Contract** — server-only `@open-mercato/cache/provider`: `defineCacheProvider` (id `<scope>/<name>`, `safeParse` settings schema, `capability()` → `placement: 'shared' | 'local'`, `create()` → base `CacheStrategy` with required `healthcheck` + `close`), `defineCacheProviderRegistration`, `CacheProviderError` (stable `code`, sanitized message).
38
+ - **Selection** — `src/providers/cache.ts` exports `cacheProviders` (`yarn generate` re-exports it). `CACHE_PROVIDER=<id>` beats `CACHE_STRATEGY`; explicit `strategy` option beats both; `CACHE_PROVIDER_NAMESPACE` required. Unset `CACHE_PROVIDER` ignores registrations (no validation). The selection memo is keyed on (registrations, id, namespace); `setCacheProviderRegistrations` resets it.
39
+ - **Runtime** — every provider operation/close error is rethrown as host-authored `unavailable` (cause non-enumerable); failed init is reused for `CACHE_PROVIDER_RETRY_COOLDOWN_MS` (default 1000); `close()` is terminal (later ops reject `unavailable`, never reconnect). Root `yarn generate` (turbo) passes only `CACHE_*` env — provider settings under other env names must live in `.env`.
40
+ - **MUST NOT fall back to memory** for a provider — rethrow `isCacheProviderError` errors from bootstrap catches. Providers always use the process singleton.
41
+ - Use `describeCacheSelection()`, not `CACHE_STRATEGY`, for readiness, the multi-instance guard and placement warnings.
42
+ - **Provider rules** — keys/tags arrive tenant-scoped; fence by `context.namespace`; `helpers.decode` throws → miss; `deleteByTags`/`cleanup`/`clear` count physical records; apply `context.defaultTtl`.
43
+ - **Verify** with `defineCacheProviderConformance` (`@open-mercato/cache/testing`); reference `fixtures/cache-provider-fixture` + `src/__tests__/provider-fixture.packed.test.ts`.
33
44
 
34
45
  ## Always
35
46
 
@@ -74,9 +85,9 @@ await cache.deleteByTags(['customers']) // Clears all customer-related cache
74
85
 
75
86
  ## Consistency vs commit timing
76
87
 
77
- Cache invalidation and query-index side effects (`emitCrudSideEffects`) MUST fire **after** the originating domain write commits — the same rule that keeps them OUTSIDE the `withAtomicFlush` block (see `packages/core/AGENTS.md` → "Entity Update Safety — `withAtomicFlush`"). Because invalidation runs post-commit and the query-index read-projection tail (search tokens, vectors, fulltext, coverage) converges asynchronously, reads can briefly see a short convergence window after a write.
88
+ Cache invalidation and query-index side effects (`emitCrudSideEffects`) MUST fire **after** the domain write commits, OUTSIDE `withAtomicFlush` (see `packages/core/AGENTS.md`). The read-projection tail (search tokens, vectors, fulltext, coverage) converges asynchronously, so reads may briefly lag a write.
78
89
 
79
- The opt-in env flag `OM_CACHE_SAFETY_ALWAYS_CONSISTENT` (default **OFF**, 100% backward compatible) makes that read-projection tail converge synchronously on write and propagates index-write failures instead of swallowing them — at the cost of added write latency. It does not move query-index side effects into the domain-write transaction. See `.ai/specs/2026-06-05-cache-safety-always-consistent.md`.
90
+ Opt-in `OM_CACHE_SAFETY_ALWAYS_CONSISTENT` (default **OFF**) makes that tail converge synchronously and propagates index-write failures, at added write latency; it does not move side effects into the transaction. See `.ai/specs/2026-06-05-cache-safety-always-consistent.md`.
80
91
 
81
92
  ## Adding Caching to a Module
82
93
 
@@ -88,15 +99,10 @@ The opt-in env flag `OM_CACHE_SAFETY_ALWAYS_CONSISTENT` (default **OFF**, 100% b
88
99
 
89
100
  ## Structure
90
101
 
91
- ```
92
- packages/cache/src/
93
- ├── strategies/ # Redis, SQLite, memory implementations
94
- └── __tests__/
95
- ```
102
+ `src/strategies/` (stock backends), `src/provider.ts` (provider contract), `src/testing/` (conformance kit), `fixtures/` (packed provider fixture).
96
103
 
97
104
  ## When Modifying This Package
98
105
 
99
- - Follow the strategy pattern — add new strategies in `strategies/` with the same interface
100
- - Run `yarn test` in `packages/cache` after changes
101
- - Verify tag invalidation works across all strategies when modifying invalidation logic
102
- - The DI token and method names quoted in this file and in `.ai/review-checklist.md` are pinned to the real sources by `src/__tests__/cache-di-contract-docs.test.ts` (it re-derives the token from `packages/core/src/bootstrap.ts` and the members from `CacheStrategy`). Renaming the token or a method MUST update both docs in the same change.
106
+ - Follow the strategy pattern — new strategies go in `strategies/` with the same interface
107
+ - Run `yarn test` in `packages/cache`; verify tag invalidation across all strategies when touching invalidation
108
+ - `src/__tests__/cache-di-contract-docs.test.ts` pins the DI token and method names quoted here and in `.ai/review-checklist.md`; renaming either MUST update both docs.
package/README.md CHANGED
@@ -137,6 +137,36 @@ The glob-matching happens on logical keys, so you can keep friendly names for tr
137
137
 
138
138
  ---
139
139
 
140
+ ## Pluggable cache providers
141
+
142
+ The built-in strategies ship with this package as independent npm providers for memory, SQLite, Redis and JSON files. Existing `CACHE_STRATEGY` settings and the memory default apply. A deployment can also select an installed npm **cache provider**. The app registers it explicitly in `src/providers/cache.ts`:
143
+
144
+ ```ts
145
+ import { defineCacheProviderRegistration } from '@open-mercato/cache/provider'
146
+
147
+ export const cacheProviders = [
148
+ defineCacheProviderRegistration({
149
+ id: 'acme/example',
150
+ load: () => import('@acme/cache-provider-example').then((module) => module.provider),
151
+ settings: () => ({ endpoints: [process.env.ACME_CACHE_ENDPOINT ?? ''] }),
152
+ }),
153
+ ]
154
+ ```
155
+
156
+ ```bash
157
+ yarn generate
158
+ CACHE_PROVIDER=acme/example
159
+ CACHE_PROVIDER_NAMESPACE=shop-prod
160
+ #CACHE_PROVIDER_CONNECT_TIMEOUT_MS=10000
161
+ ```
162
+
163
+ - `CACHE_PROVIDER` wins over `CACHE_STRATEGY`. An explicit programmatic `strategy` still wins over it. A selected provider never falls back to memory: failures surface as a sanitized `CacheProviderError` with a stable `code`.
164
+ - Provider authors build packages with `defineCacheProvider` from `@open-mercato/cache/provider` and verify them with `defineCacheProviderConformance` from `@open-mercato/cache/testing`. The reference implementation is `fixtures/cache-provider-fixture`.
165
+
166
+ Full operator and author guide: [Pluggable cache providers](https://docs.openmercato.com/architecture/cache-providers).
167
+
168
+ ---
169
+
140
170
  ## Building & publishing
141
171
 
142
172
  This package lives inside the monorepo but publishes independently. The emitted JS and declaration files live in `dist/` (ignored by git).
package/dist/codec.js CHANGED
@@ -1,75 +1,2 @@
1
- import zlib from "node:zlib";
2
- const DEFAULT_COMPRESSION_MIN_BYTES = 1024;
3
- const MAX_DECOMPRESSED_BYTES = 64 * 1024 * 1024;
4
- const ZSTD_LEVEL = 1;
5
- const COMPRESSIONS = ["off", "zstd", "gzip"];
6
- const warnedMessages = /* @__PURE__ */ new Set();
7
- function warnOnce(message) {
8
- if (warnedMessages.has(message)) return;
9
- warnedMessages.add(message);
10
- console.warn(message);
11
- }
12
- function isZstdAvailable() {
13
- return typeof zlib.zstdCompressSync === "function" && typeof zlib.zstdDecompressSync === "function";
14
- }
15
- function parseCacheCompression(raw) {
16
- const value = raw?.trim().toLowerCase();
17
- if (!value) return "off";
18
- if (COMPRESSIONS.includes(value)) return value;
19
- warnOnce(`[cache] Unknown CACHE_COMPRESSION value "${raw}". Compression stays off.`);
20
- return "off";
21
- }
22
- function parseCacheCompressionMinBytes(raw) {
23
- if (!raw) return void 0;
24
- const parsed = Number.parseInt(raw, 10);
25
- return Number.isFinite(parsed) && parsed > 0 ? parsed : void 0;
26
- }
27
- function resolveCacheCodecConfig(options) {
28
- const minBytes = options?.compressionMinBytes && options.compressionMinBytes > 0 ? options.compressionMinBytes : DEFAULT_COMPRESSION_MIN_BYTES;
29
- let compression = options?.compression ?? "off";
30
- if (compression === "zstd" && !isZstdAvailable()) {
31
- warnOnce("[cache] zstd is not available in this Node.js runtime. Falling back to gzip cache compression.");
32
- compression = "gzip";
33
- }
34
- return { compression, minBytes };
35
- }
36
- function compress(input, compression) {
37
- if (compression === "zstd") {
38
- return zlib.zstdCompressSync(input, { params: { [zlib.constants.ZSTD_c_compressionLevel]: ZSTD_LEVEL } });
39
- }
40
- return zlib.gzipSync(input);
41
- }
42
- function encodeCacheText(json, config) {
43
- if (config.compression === "off") return json;
44
- const size = Buffer.byteLength(json);
45
- if (size < config.minBytes || size > MAX_DECOMPRESSED_BYTES) return json;
46
- const compressed = compress(Buffer.from(json, "utf8"), config.compression);
47
- return compressed.length < size ? compressed : json;
48
- }
49
- function isZstdFrame(raw) {
50
- return raw.length >= 4 && raw[0] === 40 && raw[1] === 181 && raw[2] === 47 && raw[3] === 253;
51
- }
52
- function isGzipStream(raw) {
53
- return raw.length >= 2 && raw[0] === 31 && raw[1] === 139;
54
- }
55
- function decodeCacheText(raw) {
56
- if (typeof raw === "string") return raw;
57
- if (isZstdFrame(raw)) {
58
- return zlib.zstdDecompressSync(raw, { maxOutputLength: MAX_DECOMPRESSED_BYTES }).toString("utf8");
59
- }
60
- if (isGzipStream(raw)) {
61
- return zlib.gunzipSync(raw, { maxOutputLength: MAX_DECOMPRESSED_BYTES }).toString("utf8");
62
- }
63
- return raw.toString("utf8");
64
- }
65
- export {
66
- DEFAULT_COMPRESSION_MIN_BYTES,
67
- MAX_DECOMPRESSED_BYTES,
68
- decodeCacheText,
69
- encodeCacheText,
70
- isZstdAvailable,
71
- parseCacheCompression,
72
- parseCacheCompressionMinBytes,
73
- resolveCacheCodecConfig
74
- };
1
+ export * from "@open-mercato/cache-provider-kit/codec";
75
2
  //# sourceMappingURL=codec.js.map
package/dist/codec.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/codec.ts"],
4
- "sourcesContent": ["import zlib from 'node:zlib'\n\nexport type CacheCompression = 'off' | 'zstd' | 'gzip'\n\nexport type CacheCodecConfig = {\n compression: CacheCompression\n minBytes: number\n}\n\nexport type CacheCodecOptions = {\n compression?: CacheCompression\n compressionMinBytes?: number\n}\n\nexport const DEFAULT_COMPRESSION_MIN_BYTES = 1024\n\n/** Upper bound for one decompressed entry; larger JSON is never compressed, so no legitimate entry can hit it. */\nexport const MAX_DECOMPRESSED_BYTES = 64 * 1024 * 1024\n\nconst ZSTD_LEVEL = 1\nconst COMPRESSIONS: CacheCompression[] = ['off', 'zstd', 'gzip']\n\nconst warnedMessages = new Set<string>()\n\nfunction warnOnce(message: string): void {\n if (warnedMessages.has(message)) return\n warnedMessages.add(message)\n console.warn(message)\n}\n\nexport function isZstdAvailable(): boolean {\n return typeof zlib.zstdCompressSync === 'function' && typeof zlib.zstdDecompressSync === 'function'\n}\n\nexport function parseCacheCompression(raw: string | undefined): CacheCompression {\n const value = raw?.trim().toLowerCase()\n if (!value) return 'off'\n if (COMPRESSIONS.includes(value as CacheCompression)) return value as CacheCompression\n warnOnce(`[cache] Unknown CACHE_COMPRESSION value \"${raw}\". Compression stays off.`)\n return 'off'\n}\n\nexport function parseCacheCompressionMinBytes(raw: string | undefined): number | undefined {\n if (!raw) return undefined\n const parsed = Number.parseInt(raw, 10)\n return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined\n}\n\nexport function resolveCacheCodecConfig(options?: CacheCodecOptions): CacheCodecConfig {\n const minBytes = options?.compressionMinBytes && options.compressionMinBytes > 0\n ? options.compressionMinBytes\n : DEFAULT_COMPRESSION_MIN_BYTES\n let compression = options?.compression ?? 'off'\n if (compression === 'zstd' && !isZstdAvailable()) {\n warnOnce('[cache] zstd is not available in this Node.js runtime. Falling back to gzip cache compression.')\n compression = 'gzip'\n }\n return { compression, minBytes }\n}\n\nfunction compress(input: Buffer, compression: Exclude<CacheCompression, 'off'>): Buffer {\n if (compression === 'zstd') {\n return zlib.zstdCompressSync(input, { params: { [zlib.constants.ZSTD_c_compressionLevel]: ZSTD_LEVEL } })\n }\n return zlib.gzipSync(input)\n}\n\nexport function encodeCacheText(json: string, config: CacheCodecConfig): string | Buffer {\n if (config.compression === 'off') return json\n const size = Buffer.byteLength(json)\n if (size < config.minBytes || size > MAX_DECOMPRESSED_BYTES) return json\n const compressed = compress(Buffer.from(json, 'utf8'), config.compression)\n return compressed.length < size ? compressed : json\n}\n\nfunction isZstdFrame(raw: Buffer): boolean {\n return raw.length >= 4 && raw[0] === 0x28 && raw[1] === 0xb5 && raw[2] === 0x2f && raw[3] === 0xfd\n}\n\nfunction isGzipStream(raw: Buffer): boolean {\n return raw.length >= 2 && raw[0] === 0x1f && raw[1] === 0x8b\n}\n\n/** Detects the format from the stored bytes, so entries stay readable whatever CACHE_COMPRESSION is set to now. */\nexport function decodeCacheText(raw: string | Buffer): string {\n if (typeof raw === 'string') return raw\n if (isZstdFrame(raw)) {\n return zlib.zstdDecompressSync(raw, { maxOutputLength: MAX_DECOMPRESSED_BYTES }).toString('utf8')\n }\n if (isGzipStream(raw)) {\n return zlib.gunzipSync(raw, { maxOutputLength: MAX_DECOMPRESSED_BYTES }).toString('utf8')\n }\n return raw.toString('utf8')\n}\n"],
5
- "mappings": "AAAA,OAAO,UAAU;AAcV,MAAM,gCAAgC;AAGtC,MAAM,yBAAyB,KAAK,OAAO;AAElD,MAAM,aAAa;AACnB,MAAM,eAAmC,CAAC,OAAO,QAAQ,MAAM;AAE/D,MAAM,iBAAiB,oBAAI,IAAY;AAEvC,SAAS,SAAS,SAAuB;AACvC,MAAI,eAAe,IAAI,OAAO,EAAG;AACjC,iBAAe,IAAI,OAAO;AAC1B,UAAQ,KAAK,OAAO;AACtB;AAEO,SAAS,kBAA2B;AACzC,SAAO,OAAO,KAAK,qBAAqB,cAAc,OAAO,KAAK,uBAAuB;AAC3F;AAEO,SAAS,sBAAsB,KAA2C;AAC/E,QAAM,QAAQ,KAAK,KAAK,EAAE,YAAY;AACtC,MAAI,CAAC,MAAO,QAAO;AACnB,MAAI,aAAa,SAAS,KAAyB,EAAG,QAAO;AAC7D,WAAS,4CAA4C,GAAG,2BAA2B;AACnF,SAAO;AACT;AAEO,SAAS,8BAA8B,KAA6C;AACzF,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,SAAS,OAAO,SAAS,KAAK,EAAE;AACtC,SAAO,OAAO,SAAS,MAAM,KAAK,SAAS,IAAI,SAAS;AAC1D;AAEO,SAAS,wBAAwB,SAA+C;AACrF,QAAM,WAAW,SAAS,uBAAuB,QAAQ,sBAAsB,IAC3E,QAAQ,sBACR;AACJ,MAAI,cAAc,SAAS,eAAe;AAC1C,MAAI,gBAAgB,UAAU,CAAC,gBAAgB,GAAG;AAChD,aAAS,gGAAgG;AACzG,kBAAc;AAAA,EAChB;AACA,SAAO,EAAE,aAAa,SAAS;AACjC;AAEA,SAAS,SAAS,OAAe,aAAuD;AACtF,MAAI,gBAAgB,QAAQ;AAC1B,WAAO,KAAK,iBAAiB,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,UAAU,uBAAuB,GAAG,WAAW,EAAE,CAAC;AAAA,EAC1G;AACA,SAAO,KAAK,SAAS,KAAK;AAC5B;AAEO,SAAS,gBAAgB,MAAc,QAA2C;AACvF,MAAI,OAAO,gBAAgB,MAAO,QAAO;AACzC,QAAM,OAAO,OAAO,WAAW,IAAI;AACnC,MAAI,OAAO,OAAO,YAAY,OAAO,uBAAwB,QAAO;AACpE,QAAM,aAAa,SAAS,OAAO,KAAK,MAAM,MAAM,GAAG,OAAO,WAAW;AACzE,SAAO,WAAW,SAAS,OAAO,aAAa;AACjD;AAEA,SAAS,YAAY,KAAsB;AACzC,SAAO,IAAI,UAAU,KAAK,IAAI,CAAC,MAAM,MAAQ,IAAI,CAAC,MAAM,OAAQ,IAAI,CAAC,MAAM,MAAQ,IAAI,CAAC,MAAM;AAChG;AAEA,SAAS,aAAa,KAAsB;AAC1C,SAAO,IAAI,UAAU,KAAK,IAAI,CAAC,MAAM,MAAQ,IAAI,CAAC,MAAM;AAC1D;AAGO,SAAS,gBAAgB,KAA8B;AAC5D,MAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,MAAI,YAAY,GAAG,GAAG;AACpB,WAAO,KAAK,mBAAmB,KAAK,EAAE,iBAAiB,uBAAuB,CAAC,EAAE,SAAS,MAAM;AAAA,EAClG;AACA,MAAI,aAAa,GAAG,GAAG;AACrB,WAAO,KAAK,WAAW,KAAK,EAAE,iBAAiB,uBAAuB,CAAC,EAAE,SAAS,MAAM;AAAA,EAC1F;AACA,SAAO,IAAI,SAAS,MAAM;AAC5B;",
4
+ "sourcesContent": ["export * from '@open-mercato/cache-provider-kit/codec'\n"],
5
+ "mappings": "AAAA,cAAc;",
6
6
  "names": []
7
7
  }
package/dist/defaults.js CHANGED
@@ -1,7 +1,2 @@
1
- const DEFAULT_SQLITE_CACHE_PATH = ".mercato/cache/cache.db";
2
- const DEFAULT_JSON_FILE_CACHE_PATH = ".mercato/cache/cache.json";
3
- export {
4
- DEFAULT_JSON_FILE_CACHE_PATH,
5
- DEFAULT_SQLITE_CACHE_PATH
6
- };
1
+ export * from "@open-mercato/cache-provider-kit/defaults";
7
2
  //# sourceMappingURL=defaults.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/defaults.ts"],
4
- "sourcesContent": ["export const DEFAULT_SQLITE_CACHE_PATH = '.mercato/cache/cache.db'\nexport const DEFAULT_JSON_FILE_CACHE_PATH = '.mercato/cache/cache.json'\n"],
5
- "mappings": "AAAO,MAAM,4BAA4B;AAClC,MAAM,+BAA+B;",
4
+ "sourcesContent": ["export * from '@open-mercato/cache-provider-kit/defaults'\n"],
5
+ "mappings": "AAAA,cAAc;",
6
6
  "names": []
7
7
  }
package/dist/errors.js CHANGED
@@ -1,13 +1,2 @@
1
- class CacheDependencyUnavailableError extends Error {
2
- constructor(strategy, dependency, originalError) {
3
- super(`Cache strategy "${strategy}" requires dependency "${dependency}" which is not available`);
4
- this.name = "CacheDependencyUnavailableError";
5
- this.strategy = strategy;
6
- this.dependency = dependency;
7
- this.originalError = originalError;
8
- }
9
- }
10
- export {
11
- CacheDependencyUnavailableError
12
- };
1
+ export * from "@open-mercato/cache-provider-kit/errors";
13
2
  //# sourceMappingURL=errors.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/errors.ts"],
4
- "sourcesContent": ["export class CacheDependencyUnavailableError extends Error {\n public readonly strategy: string\n public readonly dependency: string\n public readonly originalError?: unknown\n\n constructor(strategy: string, dependency: string, originalError?: unknown) {\n super(`Cache strategy \"${strategy}\" requires dependency \"${dependency}\" which is not available`)\n this.name = 'CacheDependencyUnavailableError'\n this.strategy = strategy\n this.dependency = dependency\n this.originalError = originalError\n }\n}\n\n"],
5
- "mappings": "AAAO,MAAM,wCAAwC,MAAM;AAAA,EAKzD,YAAY,UAAkB,YAAoB,eAAyB;AACzE,UAAM,mBAAmB,QAAQ,0BAA0B,UAAU,0BAA0B;AAC/F,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,SAAK,aAAa;AAClB,SAAK,gBAAgB;AAAA,EACvB;AACF;",
4
+ "sourcesContent": ["export * from '@open-mercato/cache-provider-kit/errors'\n"],
5
+ "mappings": "AAAA,cAAc;",
6
6
  "names": []
7
7
  }
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["export * from './types'\nexport * from './service'\nexport * from './defaults'\nexport { createMemoryStrategy } from './strategies/memory'\nexport { createRedisStrategy } from './strategies/redis'\nexport { createSqliteStrategy } from './strategies/sqlite'\nexport { createJsonFileStrategy } from './strategies/jsonfile'\nexport { runWithCacheTenant, getCurrentCacheTenant } from './tenantContext'\n"],
4
+ "sourcesContent": ["export * from './types'\nexport * from './service'\nexport * from './defaults'\nexport { createMemoryStrategy } from './strategies/memory'\nexport { createRedisStrategy } from './strategies/redis'\nexport { createSqliteStrategy } from './strategies/sqlite'\nexport { createJsonFileStrategy } from './strategies/jsonfile'\nexport { runWithCacheTenant, getCurrentCacheTenant } from './tenantContext'\nexport type {\n CacheProviderPlacement,\n ResolvedCacheProvider,\n} from './provider'\n"],
5
5
  "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AACrC,SAAS,8BAA8B;AACvC,SAAS,oBAAoB,6BAA6B;",
6
6
  "names": []
7
7
  }
package/dist/patterns.js CHANGED
@@ -1,36 +1,2 @@
1
- function matchCacheKeyPattern(key, pattern) {
2
- let patternIndex = 0;
3
- let keyIndex = 0;
4
- let starIndex = -1;
5
- let keyRetryIndex = 0;
6
- while (keyIndex < key.length) {
7
- const patternChar = pattern[patternIndex];
8
- const keyChar = key[keyIndex];
9
- if (patternChar === "*") {
10
- starIndex = patternIndex;
11
- keyRetryIndex = keyIndex;
12
- patternIndex += 1;
13
- continue;
14
- }
15
- if (patternChar === "?" || patternChar === keyChar) {
16
- patternIndex += 1;
17
- keyIndex += 1;
18
- continue;
19
- }
20
- if (starIndex !== -1) {
21
- patternIndex = starIndex + 1;
22
- keyRetryIndex += 1;
23
- keyIndex = keyRetryIndex;
24
- continue;
25
- }
26
- return false;
27
- }
28
- while (pattern[patternIndex] === "*") {
29
- patternIndex += 1;
30
- }
31
- return patternIndex === pattern.length;
32
- }
33
- export {
34
- matchCacheKeyPattern
35
- };
1
+ export * from "@open-mercato/cache-provider-kit/patterns";
36
2
  //# sourceMappingURL=patterns.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/patterns.ts"],
4
- "sourcesContent": ["export function matchCacheKeyPattern(key: string, pattern: string): boolean {\n let patternIndex = 0\n let keyIndex = 0\n let starIndex = -1\n let keyRetryIndex = 0\n\n while (keyIndex < key.length) {\n const patternChar = pattern[patternIndex]\n const keyChar = key[keyIndex]\n\n if (patternChar === '*') {\n starIndex = patternIndex\n keyRetryIndex = keyIndex\n patternIndex += 1\n continue\n }\n\n if (patternChar === '?' || patternChar === keyChar) {\n patternIndex += 1\n keyIndex += 1\n continue\n }\n\n if (starIndex !== -1) {\n patternIndex = starIndex + 1\n keyRetryIndex += 1\n keyIndex = keyRetryIndex\n continue\n }\n\n return false\n }\n\n while (pattern[patternIndex] === '*') {\n patternIndex += 1\n }\n\n return patternIndex === pattern.length\n}\n\n"],
5
- "mappings": "AAAO,SAAS,qBAAqB,KAAa,SAA0B;AAC1E,MAAI,eAAe;AACnB,MAAI,WAAW;AACf,MAAI,YAAY;AAChB,MAAI,gBAAgB;AAEpB,SAAO,WAAW,IAAI,QAAQ;AAC5B,UAAM,cAAc,QAAQ,YAAY;AACxC,UAAM,UAAU,IAAI,QAAQ;AAE5B,QAAI,gBAAgB,KAAK;AACvB,kBAAY;AACZ,sBAAgB;AAChB,sBAAgB;AAChB;AAAA,IACF;AAEA,QAAI,gBAAgB,OAAO,gBAAgB,SAAS;AAClD,sBAAgB;AAChB,kBAAY;AACZ;AAAA,IACF;AAEA,QAAI,cAAc,IAAI;AACpB,qBAAe,YAAY;AAC3B,uBAAiB;AACjB,iBAAW;AACX;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO,QAAQ,YAAY,MAAM,KAAK;AACpC,oBAAgB;AAAA,EAClB;AAEA,SAAO,iBAAiB,QAAQ;AAClC;",
4
+ "sourcesContent": ["export * from '@open-mercato/cache-provider-kit/patterns'\n"],
5
+ "mappings": "AAAA,cAAc;",
6
6
  "names": []
7
7
  }