@open-mercato/cache-provider-ignite 0.0.0-stage → 0.11.1-develop.9003.1.ce86c31a07

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 CHANGED
@@ -1,3 +1,261 @@
1
- # Temporary Holding Version
1
+ # @open-mercato/cache-provider-ignite
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Apache Ignite **2.x** cache provider for the Open Mercato cache service. It plugs into the v1 provider
4
+ host (`@open-mercato/cache/provider`) and is selected with `CACHE_PROVIDER=open-mercato/ignite`. The
5
+ existing tenant wrapper, `cache` DI service, tag invalidation, readiness and cache administration paths
6
+ stay unchanged.
7
+
8
+ - Provider id: `open-mercato/ignite` · placement: `shared` with verified TLS
9
+ - Client: [`apache-ignite-client`](https://www.npmjs.com/package/apache-ignite-client) **1.0.0** (Ignite
10
+ Node.js thin client, binary protocol 1.2.0). Verified on Node.js 22+ (qualified on Node 26.12).
11
+ - Server-only ESM package with TypeScript declarations.
12
+ - Apache Ignite **3.x is not supported** (different protocol and client).
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ yarn add @open-mercato/cache-provider-ignite
18
+ ```
19
+
20
+ `@open-mercato/cache` (with the v1 provider host) is a peer dependency.
21
+
22
+ **Also pin the client's transitive dependencies in your app.** `apache-ignite-client` declares `long` and `decimal.js` as `latest`. Add the `overrides` (npm) or `resolutions` (yarn) entries from [Supply-chain notes](#supply-chain-notes) to your app's `package.json`.
23
+
24
+ ## Register the provider
25
+
26
+ Add the registration to the app's `src/providers/cache.ts`, then run `yarn generate`.
27
+
28
+ ```ts
29
+ import { readFileSync } from 'node:fs'
30
+ import type { CacheProviderRegistration } from '@open-mercato/cache/provider'
31
+
32
+ export const cacheProviders: CacheProviderRegistration[] = [
33
+ {
34
+ id: 'open-mercato/ignite',
35
+ load: () => import('@open-mercato/cache-provider-ignite').then((mod) => mod.provider),
36
+ settings: () => ({
37
+ endpoints: (process.env.IGNITE_ENDPOINTS ?? '127.0.0.1:10800').split(','),
38
+ username: process.env.IGNITE_USERNAME,
39
+ password: process.env.IGNITE_PASSWORD,
40
+ tls: process.env.IGNITE_TLS_CA_FILE
41
+ ? { ca: readFileSync(process.env.IGNITE_TLS_CA_FILE, 'utf8') }
42
+ : {},
43
+ }),
44
+ },
45
+ ]
46
+ ```
47
+
48
+ ```bash
49
+ CACHE_PROVIDER=open-mercato/ignite
50
+ CACHE_PROVIDER_NAMESPACE=prod-eu-1 # stable deployment namespace; selects the Ignite cache
51
+ IGNITE_ENDPOINTS=ignite-1:10800,ignite-2:10800
52
+ ```
53
+
54
+ `username` and `password` must be given together. Verified TLS is required by default. To exercise the plaintext test profile, omit `tls` and set `CACHE_PROVIDER_ALLOW_INSECURE_DEVELOPMENT=1` in a development or test process. Plaintext and unverified TLS report `local` placement.
55
+
56
+ ## Settings
57
+
58
+ The schema is strict: unknown keys are rejected, and errors report field paths only, never values.
59
+
60
+ | Setting | Type / default | Meaning |
61
+ |---|---|---|
62
+ | `endpoints` | `string[]` (1–32), required | Thin-client endpoints `host:port` (IPv6 as `[::1]:10800`). The client fails over across them. |
63
+ | `username`, `password` | strings, optional, both or neither | Ignite built-in authentication. |
64
+ | `tls` | object, required by default | TLS supports `ca`, `cert`, `key` (PEM strings; `cert`/`key` together), `servername`, `rejectUnauthorized` (default `true`). Minimum TLS 1.2. |
65
+ | `cacheNamePrefix` | default `om-cache-` | The Ignite cache name is `<prefix><namespace>`, and must match the server template (see below). |
66
+ | `createCache` | default `true` | `getOrCreateCache` for the namespace cache. With `false`, the cache must already exist. |
67
+ | `connectTimeoutMs` | default `5000` (100–120000) | Bound on connect and cache resolution. |
68
+ | `commandTimeoutMs` | default `5000` (50–120000) | Bound on every command and every scan page. On expiry the session is dropped and rebuilt on next use. |
69
+ | `scanPageSize` | default `256` (1–10000) | `ScanQuery` page size for enumeration (`keys`, `stats`, `deleteByTags`, `clear`, `cleanup`). |
70
+ | `scanTimeoutMs` | default `120000` (1000–3600000) | Bound on one whole namespace scan. On expiry the call fails with code `timeout`. |
71
+ | `mutationConcurrency` | default `16` (1–256) | Parallel conditional removals per scanned batch. |
72
+ | `casAttempts` | default `8` (1–64) | Conditional-delete retries per entry before the call fails loudly. |
73
+ | `maxValueBytes` | default `4 MiB` (1 KiB–256 MiB) | Larger records are refused with `IgniteCacheValueTooLargeError` (`code: 'value_too_large'`). The previous copy of the key is deleted first, so a stale value is never served after a failed overwrite. Through the cache service the error arrives as a sanitized `CacheProviderError` (`code: 'unavailable'`) with the original as its non-enumerable `originalError`. |
74
+
75
+ `provider.redact(config)` returns endpoints and tuning values. It replaces the username, password, CA
76
+ and key material with `[redacted]`/`configured`.
77
+
78
+ Failures use the host's sanitized `CacheProviderError`: `unavailable` for transport, authentication,
79
+ TLS or missing-cache failures, and `timeout` for deadlines. Messages never contain credentials.
80
+
81
+ ## Server configuration (required)
82
+
83
+ Ready-to-run Spring XML files ship in `docker/` (also in the npm tarball):
84
+
85
+ - `docker/ignite-config.xml`: in-memory, no authentication, plaintext connector on `10800`.
86
+ - `docker/ignite-secure-config.xml`: native persistence, built-in authentication and a TLS-only
87
+ thin-client connector. The PKCS#12 key store goes at `/opt/om-tls/server.p12`, with its password
88
+ in `OM_IGNITE_KEYSTORE_PASSWORD`.
89
+
90
+ Both configs register the **`om-cache-*` cache template** that every namespace cache matches:
91
+
92
+ - `groupName=om-cache` and `RendezvousAffinityFunction(partitions=64)`. **Required.** With one cache per
93
+ namespace and Ignite's default 1024 partitions per cache, partition metadata exhausted a 128 MiB data
94
+ region after a few dozen caches, and the node halted (`IgniteOutOfMemoryException`, observed during
95
+ qualification). The shared cache group keeps per-cache overhead small.
96
+ - `CreatedExpiryPolicy` bounds the **physical** lifetime of every record (`OM_IGNITE_MAX_TTL_SECONDS`,
97
+ default 86400). The thin client has no per-entry expiry API, so this is the only server-side bound.
98
+ - `ATOMIC`, `PARTITIONED`, `backups=0`, and `eagerTtl=true`.
99
+
100
+ The plain profile uses `RANDOM_2_LRU` page eviction in the default data region (`OM_IGNITE_REGION_MB`,
101
+ default 128). Capacity pressure evicts whole entries, which read as misses, instead of failing writes.
102
+
103
+ ```bash
104
+ docker run -d -p 10800:10800 \
105
+ -e JVM_OPTS="-Xms512m -Xmx512m -XX:MaxMetaspaceSize=256m" \
106
+ -e CONFIG_URI=/opt/om/ignite-config.xml \
107
+ -v "$PWD/node_modules/@open-mercato/cache-provider-ignite/docker:/opt/om:ro" \
108
+ apacheignite/ignite:2.17.0-arm64 # use apacheignite/ignite:2.17.0 on amd64
109
+ ```
110
+
111
+ **Authenticated profile:** Ignite 2.x built-in authentication requires native persistence, so the
112
+ cluster starts `INACTIVE`. Activate it once, then create a dedicated user. The default superuser is
113
+ `ignite`/`ignite`; change its password.
114
+
115
+ ```bash
116
+ ./bin/control.sh --set-state ACTIVE --yes --user ignite --password '<superuser password>' \
117
+ --host 127.0.0.1 --port 10800 \
118
+ --keystore /opt/om-tls/server.p12 --keystore-type PKCS12 --keystore-password '<ks password>' \
119
+ --truststore /tmp/trust.jks --truststore-password '<ts password>'
120
+ # then over SQL (any cache, schema PUBLIC): CREATE USER "om_cache" WITH PASSWORD '<password>'
121
+ ```
122
+
123
+ The persistent profile's data survives restarts until the template TTL or a namespace change.
124
+
125
+ ## How it works
126
+
127
+ - **Namespace fencing:** one Ignite cache per deployment namespace (`om-cache-<namespace>`). The thin
128
+ client has no remote scan filter, so all enumeration is a `ScanQuery` over the namespace's own cache
129
+ only. Foreign caches and other namespaces are never read or mutated. There is no global clear and no
130
+ cache destroy.
131
+ - **Records:** every physical key (the host writes one record containing the value and enumeration metadata per logical
132
+ entry) maps to one string record `{v, n, t, e, c, f, p}`. The fields are the layout version, a random
133
+ nonce, tags, logical `expiresAt`, creation time, payload encoding (text or base64 for compressed
134
+ codec output) and the payload.
135
+ - **Expiry:** logical. An expired record is a miss (it stays readable with `returnExpired`) until
136
+ `cleanup()` reclaims it with a conditional delete. The server template TTL bounds physical lifetime.
137
+ - **Tag invalidation:** a bounded scan of the namespace cache. Each matching record is removed with
138
+ `removeIfEquals(key, exactPriorValue)`. If the record changed in between, it is re-read and removed
139
+ only if it still carries a requested tag (up to `casAttempts`). A concurrently retagged entry
140
+ therefore survives. There is **no separate tag index**: index entries would be evictable and
141
+ expirable independently of the values (page eviction, the template TTL) and could lose membership.
142
+ The scan stays complete by construction.
143
+ - **Corrupt records** are misses, dropped on read and on cleanup.
144
+ - **Transport warnings:** `create` logs one warning when `tls.rejectUnauthorized` is `false` or when a password is configured without `tls` (credentials over plaintext). Both require the explicit development or test opt-in.
145
+ - **Connections:** connect and command deadlines. A deadline, lost connection or missing cache discards
146
+ the session and rebuilds it on next use, so it recovers after a node restart and recreates the
147
+ namespace cache. `healthcheck()` is a single `containsKey` (non-mutating). `close()` is idempotent.
148
+
149
+ ## Supported matrix (qualified profiles only)
150
+
151
+ | Profile | Status | Evidence |
152
+ |---|---|---|
153
+ | Ignite 2.17.0, single node, in-memory, no auth, plaintext thin client | **Development and test opt-in** | Conformance 16/16, engine 9/9, limits 2/2, packed install 4/4 |
154
+ | Ignite 2.17.0, single node, native persistence, built-in authentication, TLS thin-client connector (server cert; no client cert) | **Supported** | Conformance 16/16 + 3 negative cases (19/19) |
155
+
156
+ ### Not verified (not supported until qualified)
157
+
158
+ - Multi-node clusters, `backups > 0`, `REPLICATED` caches, rebalancing and node failover across
159
+ endpoints. Multiple endpoints are accepted, but failover is untested.
160
+ - Mutual TLS (client certificates via `tls.cert`/`tls.key`). The setting is accepted but unexercised.
161
+ - Ignite versions other than 2.17.0, and the amd64 image (`apacheignite/ignite:2.17.0`).
162
+ - `createCache: false` with operator-created caches.
163
+ - Long-running stability and memory behaviour beyond the qualification runs.
164
+
165
+ ## Limitations and operating envelope
166
+
167
+ - **Invalidation cost is O(namespace size):** `deleteByTags`, `clear`, `keys`, `stats` and `cleanup`
168
+ scan every record in the namespace cache and transfer values over the wire. The measurements below
169
+ are in the qualification table. Keep namespaces in the tens of thousands of logical entries, or raise
170
+ `scanTimeoutMs` knowingly.
171
+ - A scan is weakly consistent. Entries written concurrently with an invalidation may be observed either
172
+ before or after it. That is linearizable with the invalidation. Unmodified entries are always seen.
173
+ - Capacity eviction drops whole records. A missing record is a miss.
174
+ An orphaned value record is still removed by tag invalidation and `clear`.
175
+ - Old namespace caches are **not destroyed** when you change `CACHE_PROVIDER_NAMESPACE`. Drop
176
+ `om-cache-<old namespace>` manually after a safe cutover. The template TTL drains its records anyway.
177
+ - Each namespace cache costs partition metadata in the data region. The cache group and 64 partitions
178
+ keep this small, but do not create namespaces dynamically.
179
+ - Under host contention, one run during qualification (a sibling engine container running on the same
180
+ 8 GB Docker VM) showed a 30 s command timeout and a 560 s namespace scan. This was not reproduced on a
181
+ quiet host, and the root cause was not isolated. `scanTimeoutMs` now bounds any single scan.
182
+
183
+ ## Supply-chain notes
184
+
185
+ `apache-ignite-client@1.0.0` is the only published version (released 2018, metadata last modified
186
+ 2022, Apache-2.0, maintained under `apache/ignite` `modules/platforms/nodejs`). It declares its own
187
+ dependencies as **`long: "latest"`** and **`decimal.js: "latest"`**, so every fresh npm install resolves
188
+ whatever those tags point to at install time. At qualification time that was `long@5.3.2` and
189
+ `decimal.js@10.6.0`, and those are locked in this monorepo's `yarn.lock`. A library cannot pin its
190
+ transitive dependencies for consumers. **Pin them in your app** and requalify when you change them:
191
+
192
+ ```jsonc
193
+ // package.json (npm)
194
+ "overrides": { "long": "5.3.2", "decimal.js": "10.6.0" }
195
+ // package.json (yarn)
196
+ "resolutions": { "long": "5.3.2", "decimal.js": "10.6.0" }
197
+ ```
198
+
199
+ The package depends on that client, plus `zod` for the settings schema.
200
+
201
+ The package pins `apache-ignite-client` to exactly `1.0.0` because it relies on a **private field** of that client: `src/connection.ts` reaches `client._socket._socket._socket` to destroy the TCP/TLS socket when a deadline expires, since `disconnect()` alone does not abort a stalled socket. That access is wrapped (optional chaining inside a `try`), so a changed client shape loses only the forced close, not correctness. Re-check that path and requalify (`test:containers`, especially the paused-node tests) before changing the client version.
202
+
203
+ ## Qualification evidence
204
+
205
+ Manual runs on a developer machine, not CI. No CI job runs the container suites yet (see `packages/cache-redis-protocol/README.md` → *Proposed CI job*). Command: `yarn workspace @open-mercato/cache-provider-ignite test:containers` (or `yarn test:cache-providers:containers` from the repo root).
206
+
207
+ Date: 2026-11-24 · Host: macOS arm64, Docker Desktop (8 GB VM) · Node.js 26.12.1 · Testcontainers 12 ·
208
+ images pinned: `apacheignite/ignite:2.17.0-arm64`, reference `redis:7.4-alpine`.
209
+
210
+ | Suite (`src/__tests__/…`) | Image@tag | Topology | Auth / TLS | Result |
211
+ |---|---|---|---|---|
212
+ | `ignite.conformance.container.test.ts`: shared v1 conformance kit incl. independent process + corrupt value | `apacheignite/ignite:2.17.0-arm64` | 1 node, in-memory | none / none | 16/16 pass (repeated 4×) |
213
+ | `ignite.secure.container.test.ts`: same kit + wrong password, untrusted CA, plaintext client | `apacheignite/ignite:2.17.0-arm64` | 1 node, native persistence | built-in auth (SQL-created user) / TLS 1.2+ with throwaway CA | 19/19 pass |
214
+ | `ignite.engine.container.test.ts`: two-process retag race, two-process tag churn, foreign-cache fencing, non-mutating healthcheck, oversize values (previous copy dropped), paused node → command timeout → recovery, paused node → scan budget, restart → reconnect + cache recreated | `apacheignite/ignite:2.17.0-arm64` | 1 node | none / none | 9/9 pass |
215
+ | `ignite.limits.container.test.ts`: 3 s `CreatedExpiryPolicy` template reclaims un-TTL'd entries; 656 × 200 KiB into a 64 MiB region (336 survived) with no write failure | `apacheignite/ignite:2.17.0-arm64` | 1 node, 64 MiB region | none / none | 2/2 pass |
216
+ | `ignite.packed.container.test.ts`: pack and install in a fresh app outside the workspace → registration + `resolveCacheProvider` → workflow on Ignite and consumer type-check | `apacheignite/ignite:2.17.0-arm64` | 1 node | none / none | 4/4 pass |
217
+ | Unit (Docker-free, default `yarn test`): settings schema, redaction, transport warnings, key/record layout, CAS retry semantics on a fake transport, oversize overwrite drops the previous copy | none | none | none | 41/41 pass |
218
+
219
+ Linux AMD64 verification (2026-12-01) used `apacheignite/ignite:2.17.0` and passed all 50 container tests.
220
+
221
+ Original full run (2026-11-24, after the oversize and transport-warning changes): `test:containers` 50/50 in 33.6 s plus unit 41/41. An earlier full sequential run of all seven suites passed 89/89 in 42.8 s. Two earlier full runs that day
222
+ failed: one with 20 failures, one with 2, all connect errors or timeouts. Both ran while another
223
+ engine's container was using about 230% CPU on the same 8 GB Docker VM. Every suite passed when rerun
224
+ on a quieter host. Treat the container suites as sensitive to Docker host contention.
225
+
226
+ Run them:
227
+
228
+ ```bash
229
+ yarn workspace @open-mercato/cache-provider-ignite test # unit, no Docker
230
+ yarn workspace @open-mercato/cache-provider-ignite test:containers # all container suites (sequential)
231
+ yarn workspace @open-mercato/cache-provider-ignite qualify # performance (below)
232
+ ```
233
+
234
+ The packed test installs release-shaped tarballs for Ignite, `@open-mercato/cache`, and the host's default
235
+ provider dependencies. It verifies that the standalone app needs only the selected optional adapter.
236
+
237
+ ### Performance (`scripts/qualify.mjs`)
238
+
239
+ Workload: 2 independent client processes on one tenant, each doing 2000 × (`set` with 2 tags + `get`),
240
+ plus `deleteByTags` of a random tag group every 20 iterations. 500 keys, 50 tag groups, ~280 B values.
241
+ Run on a fresh node with a 256 MiB region. Stock Redis strategy is the reference.
242
+
243
+ | Engine | set p50 / p95 / p99 | get p50 / p95 / p99 | deleteByTags p50 / p95 / p99 | errors |
244
+ |---|---|---|---|---|
245
+ | Ignite 2.17.0 (this provider), worker 0 | 0.72 / 1.21 / 1.80 ms | 0.34 / 0.54 / 0.74 ms | 2.03 / 4.83 / 10.29 ms | 0 |
246
+ | Ignite 2.17.0 (this provider), worker 1 | 0.69 / 1.14 / 1.84 ms | 0.33 / 0.54 / 0.73 ms | 1.89 / 3.88 / 15.72 ms | 0 |
247
+ | Redis 7.4 (stock strategy), worker 0 | 0.42 / 0.83 / 1.68 ms | 0.19 / 0.38 / 0.72 ms | 1.07 / 2.07 / 2.51 ms | 0 |
248
+ | Redis 7.4 (stock strategy), worker 1 | 0.43 / 0.83 / 1.69 ms | 0.19 / 0.37 / 0.76 ms | 1.03 / 1.86 / 2.39 ms | 0 |
249
+
250
+ Scan envelope: the cost of one tag invalidation that matches nothing, which is a full namespace scan.
251
+
252
+ | Logical entries (physical records) | no-match `deleteByTags` p50 / max | invalidate all |
253
+ |---|---|---|
254
+ | 1,000 (2,000) | 9 / 13 ms | 85 ms |
255
+ | 10,000 (20,000) | 88 / 97 ms | 624 ms |
256
+ | 50,000 (100,000) | 400 / 497 ms | 3.5 s |
257
+
258
+ Command counts are derived, not instrumented. `set` = 1 `put` per physical record, and the wrapper
259
+ writes 2 per logical entry. `get`/`has` = 1 `get`. `delete` = 1 `removeKey`. A scan = 1 `query` +
260
+ ⌈records / `scanPageSize`⌉ page fetches. Each removal = 1 `removeIfEquals`, plus 1 `get` per lost CAS
261
+ race.
@@ -0,0 +1,16 @@
1
+ import { type IgniteCacheProviderConfig } from './settings';
2
+ export type IgniteCacheCommands = {
3
+ get(key: string): Promise<unknown>;
4
+ put(key: string, value: string): Promise<void>;
5
+ containsKey(key: string): Promise<boolean>;
6
+ removeKey(key: string): Promise<boolean>;
7
+ removeIfEquals(key: string, value: string): Promise<boolean>;
8
+ };
9
+ export type IgniteConnection = {
10
+ readonly cacheName: string;
11
+ run<T>(operation: string, command: (cache: IgniteCacheCommands) => Promise<T>): Promise<T>;
12
+ scan(pageSize: number, visit: (key: string, raw: unknown) => Promise<void>): Promise<void>;
13
+ close(): Promise<void>;
14
+ isClosed(): boolean;
15
+ };
16
+ export declare function createIgniteConnection(config: IgniteCacheProviderConfig, cacheName: string): IgniteConnection;
@@ -0,0 +1,206 @@
1
+ import IgniteClient from "apache-ignite-client";
2
+ import { CacheProviderError } from "@open-mercato/cache/provider";
3
+ import { IGNITE_PROVIDER_ID } from "./settings.js";
4
+ const STATE_CONNECTED = 1;
5
+ const RESET_ERROR_NAMES = /* @__PURE__ */ new Set(["LostConnectionError", "IllegalStateError"]);
6
+ class DeadlineExceededError extends Error {
7
+ constructor() {
8
+ super("[internal] deadline exceeded");
9
+ this.name = "DeadlineExceededError";
10
+ }
11
+ }
12
+ class ScanBudgetExceededError extends Error {
13
+ constructor() {
14
+ super("[internal] scan budget exceeded");
15
+ this.name = "ScanBudgetExceededError";
16
+ }
17
+ }
18
+ function withDeadline(promise, ms) {
19
+ let timer = null;
20
+ const deadline = new Promise((_, reject) => {
21
+ timer = setTimeout(() => reject(new DeadlineExceededError()), ms);
22
+ });
23
+ return Promise.race([promise, deadline]).finally(() => {
24
+ if (timer) clearTimeout(timer);
25
+ });
26
+ }
27
+ function errorName(error) {
28
+ if (!error || typeof error !== "object") return "";
29
+ const ctor = error.constructor;
30
+ return typeof ctor?.name === "string" ? ctor.name : "";
31
+ }
32
+ function requiresSessionReset(error) {
33
+ if (error instanceof DeadlineExceededError) return true;
34
+ if (RESET_ERROR_NAMES.has(errorName(error))) return true;
35
+ const message = error instanceof Error ? error.message : "";
36
+ return /cache does not exist|cache .* not found|not started|connection/i.test(message);
37
+ }
38
+ function attempt(action) {
39
+ try {
40
+ action();
41
+ } catch {
42
+ return;
43
+ }
44
+ }
45
+ function forceCloseTransport(client) {
46
+ const transport = client._socket?._socket?._socket;
47
+ attempt(() => client.disconnect());
48
+ attempt(() => transport?.destroy?.());
49
+ }
50
+ function buildClientConfiguration(config) {
51
+ const clientConfig = new IgniteClient.IgniteClientConfiguration(...config.endpoints);
52
+ if (config.username !== void 0 && config.password !== void 0) {
53
+ clientConfig.setUserName(config.username).setPassword(config.password);
54
+ }
55
+ if (config.tls) {
56
+ clientConfig.setConnectionOptions(true, {
57
+ minVersion: "TLSv1.2",
58
+ rejectUnauthorized: config.tls.rejectUnauthorized,
59
+ ...config.tls.ca !== void 0 ? { ca: config.tls.ca } : {},
60
+ ...config.tls.cert !== void 0 ? { cert: config.tls.cert } : {},
61
+ ...config.tls.key !== void 0 ? { key: config.tls.key } : {},
62
+ ...config.tls.servername !== void 0 ? { servername: config.tls.servername } : {}
63
+ });
64
+ } else {
65
+ clientConfig.setConnectionOptions(false, { noDelay: true });
66
+ }
67
+ return clientConfig;
68
+ }
69
+ function createIgniteConnection(config, cacheName) {
70
+ let session = null;
71
+ let opening = null;
72
+ let closed = false;
73
+ const stringType = IgniteClient.ObjectType.PRIMITIVE_TYPE.STRING;
74
+ const unavailable = (operation, cause) => new CacheProviderError(
75
+ "unavailable",
76
+ `Cache provider "${IGNITE_PROVIDER_ID}" could not complete ${operation} against Apache Ignite`,
77
+ { providerId: IGNITE_PROVIDER_ID, ...cause !== void 0 ? { cause } : {} }
78
+ );
79
+ const timedOut = (operation, ms) => new CacheProviderError(
80
+ "timeout",
81
+ `Cache provider "${IGNITE_PROVIDER_ID}" ${operation} did not complete within ${ms}ms`,
82
+ { providerId: IGNITE_PROVIDER_ID }
83
+ );
84
+ const discard = (target) => {
85
+ target.alive = false;
86
+ if (session === target) session = null;
87
+ forceCloseTransport(target.client);
88
+ };
89
+ const open = async () => {
90
+ const holder = { session: null };
91
+ const client = new IgniteClient((state) => {
92
+ if (state !== STATE_CONNECTED && holder.session) holder.session.alive = false;
93
+ });
94
+ try {
95
+ await withDeadline(client.connect(buildClientConfiguration(config)), config.connectTimeoutMs);
96
+ const cache = config.createCache ? await withDeadline(client.getOrCreateCache(cacheName), config.connectTimeoutMs) : client.getCache(cacheName);
97
+ if (!config.createCache) {
98
+ const names = await withDeadline(client.cacheNames(), config.connectTimeoutMs);
99
+ if (!names.includes(cacheName)) {
100
+ throw new CacheProviderError(
101
+ "unavailable",
102
+ `Cache provider "${IGNITE_PROVIDER_ID}" requires a pre-created Ignite cache for this namespace (createCache is disabled)`,
103
+ { providerId: IGNITE_PROVIDER_ID }
104
+ );
105
+ }
106
+ }
107
+ cache.setKeyType(stringType).setValueType(stringType);
108
+ const created = { client, cache, alive: true };
109
+ holder.session = created;
110
+ return created;
111
+ } catch (error) {
112
+ forceCloseTransport(client);
113
+ if (error instanceof CacheProviderError) throw error;
114
+ if (error instanceof DeadlineExceededError) throw timedOut("connect", config.connectTimeoutMs);
115
+ throw unavailable("connect", error);
116
+ }
117
+ };
118
+ const acquire = async () => {
119
+ if (closed) throw new CacheProviderError("unavailable", `Cache provider "${IGNITE_PROVIDER_ID}" connection is closed`, { providerId: IGNITE_PROVIDER_ID });
120
+ if (session && session.alive) return session;
121
+ if (session && !session.alive) discard(session);
122
+ if (!opening) {
123
+ opening = open().then(
124
+ (created) => {
125
+ opening = null;
126
+ if (closed) {
127
+ discard(created);
128
+ throw new CacheProviderError("unavailable", `Cache provider "${IGNITE_PROVIDER_ID}" connection is closed`, { providerId: IGNITE_PROVIDER_ID });
129
+ }
130
+ session = created;
131
+ return created;
132
+ },
133
+ (error) => {
134
+ opening = null;
135
+ throw error;
136
+ }
137
+ );
138
+ }
139
+ return opening;
140
+ };
141
+ const failure = (target, operation, error) => {
142
+ if (requiresSessionReset(error)) discard(target);
143
+ if (error instanceof CacheProviderError) return error;
144
+ if (error instanceof DeadlineExceededError) return timedOut(operation, config.commandTimeoutMs);
145
+ return unavailable(operation, error);
146
+ };
147
+ const run = async (operation, command) => {
148
+ const current = await acquire();
149
+ try {
150
+ return await withDeadline(command(current.cache), config.commandTimeoutMs);
151
+ } catch (error) {
152
+ throw failure(current, operation, error);
153
+ }
154
+ };
155
+ const scan = async (pageSize, visit) => {
156
+ const current = await acquire();
157
+ const scanDeadline = Date.now() + config.scanTimeoutMs;
158
+ const pageDeadline = () => {
159
+ const remaining = scanDeadline - Date.now();
160
+ if (remaining <= 0) throw new ScanBudgetExceededError();
161
+ return Math.min(config.commandTimeoutMs, remaining);
162
+ };
163
+ let cursor = null;
164
+ let exhausted = false;
165
+ try {
166
+ cursor = await withDeadline(current.cache.query(new IgniteClient.ScanQuery().setPageSize(pageSize)), pageDeadline());
167
+ let entry = await withDeadline(cursor.getValue(), pageDeadline());
168
+ while (entry) {
169
+ const key = entry.getKey();
170
+ if (typeof key === "string") await visit(key, entry.getValue());
171
+ entry = cursor.hasMore() ? await withDeadline(cursor.getValue(), pageDeadline()) : null;
172
+ }
173
+ exhausted = true;
174
+ } catch (error) {
175
+ if (error instanceof ScanBudgetExceededError) {
176
+ throw new CacheProviderError(
177
+ "timeout",
178
+ `Cache provider "${IGNITE_PROVIDER_ID}" namespace scan did not complete within scanTimeoutMs (${config.scanTimeoutMs}ms)`,
179
+ { providerId: IGNITE_PROVIDER_ID }
180
+ );
181
+ }
182
+ throw failure(current, "scan", error);
183
+ } finally {
184
+ if (cursor && !exhausted && current.alive) {
185
+ await withDeadline(cursor.close(), config.commandTimeoutMs).catch(() => void 0);
186
+ }
187
+ }
188
+ };
189
+ const close = async () => {
190
+ closed = true;
191
+ const pendingOpen = opening;
192
+ if (pendingOpen) await pendingOpen.catch(() => void 0);
193
+ if (session) discard(session);
194
+ };
195
+ return {
196
+ cacheName,
197
+ run,
198
+ scan,
199
+ close,
200
+ isClosed: () => closed
201
+ };
202
+ }
203
+ export {
204
+ createIgniteConnection
205
+ };
206
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/connection.ts"],
4
+ "sourcesContent": ["import IgniteClient from 'apache-ignite-client'\nimport type { Cursor } from 'apache-ignite-client'\nimport { CacheProviderError } from '@open-mercato/cache/provider'\nimport { IGNITE_PROVIDER_ID, type IgniteCacheProviderConfig } from './settings'\n\nexport type IgniteCacheCommands = {\n get(key: string): Promise<unknown>\n put(key: string, value: string): Promise<void>\n containsKey(key: string): Promise<boolean>\n removeKey(key: string): Promise<boolean>\n removeIfEquals(key: string, value: string): Promise<boolean>\n}\n\ntype Session = {\n client: IgniteClient\n cache: ReturnType<IgniteClient['getCache']>\n alive: boolean\n}\n\nexport type IgniteConnection = {\n readonly cacheName: string\n run<T>(operation: string, command: (cache: IgniteCacheCommands) => Promise<T>): Promise<T>\n scan(pageSize: number, visit: (key: string, raw: unknown) => Promise<void>): Promise<void>\n close(): Promise<void>\n isClosed(): boolean\n}\n\nconst STATE_CONNECTED = 1\nconst RESET_ERROR_NAMES = new Set(['LostConnectionError', 'IllegalStateError'])\n\nclass DeadlineExceededError extends Error {\n constructor() {\n super('[internal] deadline exceeded')\n this.name = 'DeadlineExceededError'\n }\n}\n\nclass ScanBudgetExceededError extends Error {\n constructor() {\n super('[internal] scan budget exceeded')\n this.name = 'ScanBudgetExceededError'\n }\n}\n\nfunction withDeadline<T>(promise: Promise<T>, ms: number): Promise<T> {\n let timer: ReturnType<typeof setTimeout> | null = null\n const deadline = new Promise<never>((_, reject) => {\n timer = setTimeout(() => reject(new DeadlineExceededError()), ms)\n })\n return Promise.race([promise, deadline]).finally(() => {\n if (timer) clearTimeout(timer)\n })\n}\n\nfunction errorName(error: unknown): string {\n if (!error || typeof error !== 'object') return ''\n const ctor = (error as { constructor?: { name?: unknown } }).constructor\n return typeof ctor?.name === 'string' ? ctor.name : ''\n}\n\nfunction requiresSessionReset(error: unknown): boolean {\n if (error instanceof DeadlineExceededError) return true\n if (RESET_ERROR_NAMES.has(errorName(error))) return true\n const message = error instanceof Error ? error.message : ''\n return /cache does not exist|cache .* not found|not started|connection/i.test(message)\n}\n\ntype TransportHolder = { _socket?: { _socket?: { _socket?: { destroy?: () => void } | null } | null } | null }\n\nfunction attempt(action: () => void): void {\n try {\n action()\n } catch {\n return\n }\n}\n\nfunction forceCloseTransport(client: IgniteClient): void {\n const transport = (client as unknown as TransportHolder)._socket?._socket?._socket\n attempt(() => client.disconnect())\n attempt(() => transport?.destroy?.())\n}\n\nfunction buildClientConfiguration(config: IgniteCacheProviderConfig) {\n const clientConfig = new IgniteClient.IgniteClientConfiguration(...config.endpoints)\n if (config.username !== undefined && config.password !== undefined) {\n clientConfig.setUserName(config.username).setPassword(config.password)\n }\n if (config.tls) {\n clientConfig.setConnectionOptions(true, {\n minVersion: 'TLSv1.2',\n rejectUnauthorized: config.tls.rejectUnauthorized,\n ...(config.tls.ca !== undefined ? { ca: config.tls.ca } : {}),\n ...(config.tls.cert !== undefined ? { cert: config.tls.cert } : {}),\n ...(config.tls.key !== undefined ? { key: config.tls.key } : {}),\n ...(config.tls.servername !== undefined ? { servername: config.tls.servername } : {}),\n })\n } else {\n clientConfig.setConnectionOptions(false, { noDelay: true })\n }\n return clientConfig\n}\n\nexport function createIgniteConnection(config: IgniteCacheProviderConfig, cacheName: string): IgniteConnection {\n let session: Session | null = null\n let opening: Promise<Session> | null = null\n let closed = false\n const stringType = IgniteClient.ObjectType.PRIMITIVE_TYPE.STRING\n\n const unavailable = (operation: string, cause?: unknown) => new CacheProviderError(\n 'unavailable',\n `Cache provider \"${IGNITE_PROVIDER_ID}\" could not complete ${operation} against Apache Ignite`,\n { providerId: IGNITE_PROVIDER_ID, ...(cause !== undefined ? { cause } : {}) },\n )\n\n const timedOut = (operation: string, ms: number) => new CacheProviderError(\n 'timeout',\n `Cache provider \"${IGNITE_PROVIDER_ID}\" ${operation} did not complete within ${ms}ms`,\n { providerId: IGNITE_PROVIDER_ID },\n )\n\n const discard = (target: Session) => {\n target.alive = false\n if (session === target) session = null\n forceCloseTransport(target.client)\n }\n\n const open = async (): Promise<Session> => {\n const holder: { session: Session | null } = { session: null }\n const client = new IgniteClient((state) => {\n if (state !== STATE_CONNECTED && holder.session) holder.session.alive = false\n })\n try {\n await withDeadline(client.connect(buildClientConfiguration(config)), config.connectTimeoutMs)\n const cache = config.createCache\n ? await withDeadline(client.getOrCreateCache(cacheName), config.connectTimeoutMs)\n : client.getCache(cacheName)\n if (!config.createCache) {\n const names = await withDeadline(client.cacheNames(), config.connectTimeoutMs)\n if (!names.includes(cacheName)) {\n throw new CacheProviderError(\n 'unavailable',\n `Cache provider \"${IGNITE_PROVIDER_ID}\" requires a pre-created Ignite cache for this namespace (createCache is disabled)`,\n { providerId: IGNITE_PROVIDER_ID },\n )\n }\n }\n cache.setKeyType(stringType).setValueType(stringType)\n const created: Session = { client, cache, alive: true }\n holder.session = created\n return created\n } catch (error) {\n forceCloseTransport(client)\n if (error instanceof CacheProviderError) throw error\n if (error instanceof DeadlineExceededError) throw timedOut('connect', config.connectTimeoutMs)\n throw unavailable('connect', error)\n }\n }\n\n const acquire = async (): Promise<Session> => {\n if (closed) throw new CacheProviderError('unavailable', `Cache provider \"${IGNITE_PROVIDER_ID}\" connection is closed`, { providerId: IGNITE_PROVIDER_ID })\n if (session && session.alive) return session\n if (session && !session.alive) discard(session)\n if (!opening) {\n opening = open().then(\n (created) => {\n opening = null\n if (closed) {\n discard(created)\n throw new CacheProviderError('unavailable', `Cache provider \"${IGNITE_PROVIDER_ID}\" connection is closed`, { providerId: IGNITE_PROVIDER_ID })\n }\n session = created\n return created\n },\n (error: unknown) => {\n opening = null\n throw error\n },\n )\n }\n return opening\n }\n\n const failure = (target: Session, operation: string, error: unknown): Error => {\n if (requiresSessionReset(error)) discard(target)\n if (error instanceof CacheProviderError) return error\n if (error instanceof DeadlineExceededError) return timedOut(operation, config.commandTimeoutMs)\n return unavailable(operation, error)\n }\n\n const run = async <T>(operation: string, command: (cache: IgniteCacheCommands) => Promise<T>): Promise<T> => {\n const current = await acquire()\n try {\n return await withDeadline(command(current.cache), config.commandTimeoutMs)\n } catch (error) {\n throw failure(current, operation, error)\n }\n }\n\n const scan = async (pageSize: number, visit: (key: string, raw: unknown) => Promise<void>): Promise<void> => {\n const current = await acquire()\n const scanDeadline = Date.now() + config.scanTimeoutMs\n const pageDeadline = () => {\n const remaining = scanDeadline - Date.now()\n if (remaining <= 0) throw new ScanBudgetExceededError()\n return Math.min(config.commandTimeoutMs, remaining)\n }\n let cursor: Cursor | null = null\n let exhausted = false\n try {\n cursor = await withDeadline(current.cache.query(new IgniteClient.ScanQuery().setPageSize(pageSize)), pageDeadline())\n let entry = await withDeadline(cursor.getValue(), pageDeadline())\n while (entry) {\n const key = entry.getKey()\n if (typeof key === 'string') await visit(key, entry.getValue())\n entry = cursor.hasMore() ? await withDeadline(cursor.getValue(), pageDeadline()) : null\n }\n exhausted = true\n } catch (error) {\n if (error instanceof ScanBudgetExceededError) {\n throw new CacheProviderError(\n 'timeout',\n `Cache provider \"${IGNITE_PROVIDER_ID}\" namespace scan did not complete within scanTimeoutMs (${config.scanTimeoutMs}ms)`,\n { providerId: IGNITE_PROVIDER_ID },\n )\n }\n throw failure(current, 'scan', error)\n } finally {\n if (cursor && !exhausted && current.alive) {\n await withDeadline(cursor.close(), config.commandTimeoutMs).catch(() => undefined)\n }\n }\n }\n\n const close = async (): Promise<void> => {\n closed = true\n const pendingOpen = opening\n if (pendingOpen) await pendingOpen.catch(() => undefined)\n if (session) discard(session)\n }\n\n return {\n cacheName,\n run,\n scan,\n close,\n isClosed: () => closed,\n }\n}\n"],
5
+ "mappings": "AAAA,OAAO,kBAAkB;AAEzB,SAAS,0BAA0B;AACnC,SAAS,0BAA0D;AAwBnE,MAAM,kBAAkB;AACxB,MAAM,oBAAoB,oBAAI,IAAI,CAAC,uBAAuB,mBAAmB,CAAC;AAE9E,MAAM,8BAA8B,MAAM;AAAA,EACxC,cAAc;AACZ,UAAM,8BAA8B;AACpC,SAAK,OAAO;AAAA,EACd;AACF;AAEA,MAAM,gCAAgC,MAAM;AAAA,EAC1C,cAAc;AACZ,UAAM,iCAAiC;AACvC,SAAK,OAAO;AAAA,EACd;AACF;AAEA,SAAS,aAAgB,SAAqB,IAAwB;AACpE,MAAI,QAA8C;AAClD,QAAM,WAAW,IAAI,QAAe,CAAC,GAAG,WAAW;AACjD,YAAQ,WAAW,MAAM,OAAO,IAAI,sBAAsB,CAAC,GAAG,EAAE;AAAA,EAClE,CAAC;AACD,SAAO,QAAQ,KAAK,CAAC,SAAS,QAAQ,CAAC,EAAE,QAAQ,MAAM;AACrD,QAAI,MAAO,cAAa,KAAK;AAAA,EAC/B,CAAC;AACH;AAEA,SAAS,UAAU,OAAwB;AACzC,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAChD,QAAM,OAAQ,MAA+C;AAC7D,SAAO,OAAO,MAAM,SAAS,WAAW,KAAK,OAAO;AACtD;AAEA,SAAS,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AAc;AACpB,QAAI,YAAa,OAAM,YAAY,MAAM,MAAM,MAAS;AACxD,QAAI,QAAS,SAAQ,OAAO;AAAA,EAC9B;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,MAAM;AAAA,EAClB;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,26 @@
1
+ export { IGNITE_PROVIDER_ID, DEFAULT_CACHE_NAME_PREFIX, DEFAULT_CAS_ATTEMPTS, DEFAULT_COMMAND_TIMEOUT_MS, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_MAX_VALUE_BYTES, DEFAULT_MUTATION_CONCURRENCY, DEFAULT_SCAN_PAGE_SIZE, DEFAULT_SCAN_TIMEOUT_MS, igniteCacheProviderSettingsSchema, igniteTransportWarnings, redactIgniteCacheProviderConfig, } from './settings';
2
+ export type { IgniteCacheProviderConfig, IgniteCacheProviderSettingsInput, IgniteTransportWarning } from './settings';
3
+ export { igniteCacheName, RECORD_FORMAT_VERSION } from './layout';
4
+ export { IgniteCacheValueTooLargeError } from './strategy';
5
+ export declare const provider: import("@open-mercato/cache/provider").CacheProviderDefinition<{
6
+ endpoints: string[];
7
+ username?: string | undefined;
8
+ password?: string | undefined;
9
+ tls?: {
10
+ ca?: string | undefined;
11
+ cert?: string | undefined;
12
+ key?: string | undefined;
13
+ servername?: string | undefined;
14
+ rejectUnauthorized: boolean;
15
+ } | undefined;
16
+ cacheNamePrefix: string;
17
+ createCache: boolean;
18
+ connectTimeoutMs: number;
19
+ commandTimeoutMs: number;
20
+ scanPageSize: number;
21
+ scanTimeoutMs: number;
22
+ mutationConcurrency: number;
23
+ casAttempts: number;
24
+ maxValueBytes: number;
25
+ }>;
26
+ export default provider;
package/dist/index.js ADDED
@@ -0,0 +1,72 @@
1
+ import { defineCacheProvider } from "@open-mercato/cache/provider";
2
+ import { createIgniteConnection } from "./connection.js";
3
+ import { igniteCacheName } from "./layout.js";
4
+ import { createIgniteStrategy } from "./strategy.js";
5
+ import {
6
+ IGNITE_PROVIDER_ID,
7
+ hasVerifiedIgniteTransport,
8
+ igniteCacheProviderSettingsSchema,
9
+ igniteTransportWarnings,
10
+ redactIgniteCacheProviderConfig
11
+ } from "./settings.js";
12
+ const TRANSPORT_WARNING_MESSAGES = {
13
+ tls_verification_disabled: "TLS server certificate verification is disabled (tls.rejectUnauthorized: false); the connection is open to interception",
14
+ credentials_over_plaintext: "credentials are sent over a plaintext connection; configure tls"
15
+ };
16
+ import {
17
+ IGNITE_PROVIDER_ID as IGNITE_PROVIDER_ID2,
18
+ DEFAULT_CACHE_NAME_PREFIX,
19
+ DEFAULT_CAS_ATTEMPTS,
20
+ DEFAULT_COMMAND_TIMEOUT_MS,
21
+ DEFAULT_CONNECT_TIMEOUT_MS,
22
+ DEFAULT_MAX_VALUE_BYTES,
23
+ DEFAULT_MUTATION_CONCURRENCY,
24
+ DEFAULT_SCAN_PAGE_SIZE,
25
+ DEFAULT_SCAN_TIMEOUT_MS,
26
+ igniteCacheProviderSettingsSchema as igniteCacheProviderSettingsSchema2,
27
+ igniteTransportWarnings as igniteTransportWarnings2,
28
+ redactIgniteCacheProviderConfig as redactIgniteCacheProviderConfig2
29
+ } from "./settings.js";
30
+ import { igniteCacheName as igniteCacheName2, RECORD_FORMAT_VERSION } from "./layout.js";
31
+ import { IgniteCacheValueTooLargeError } from "./strategy.js";
32
+ const provider = defineCacheProvider({
33
+ id: IGNITE_PROVIDER_ID,
34
+ settings: igniteCacheProviderSettingsSchema,
35
+ capability(config) {
36
+ return { placement: hasVerifiedIgniteTransport(config) ? "shared" : "local" };
37
+ },
38
+ async create(config, context) {
39
+ for (const warning of igniteTransportWarnings(config)) context.logger.warn(TRANSPORT_WARNING_MESSAGES[warning]);
40
+ const connection = createIgniteConnection(config, igniteCacheName(config.cacheNamePrefix, context.namespace));
41
+ const strategy = createIgniteStrategy(config, context, connection);
42
+ try {
43
+ await strategy.healthcheck();
44
+ } catch (error) {
45
+ await connection.close();
46
+ throw error;
47
+ }
48
+ return strategy;
49
+ },
50
+ redact: redactIgniteCacheProviderConfig
51
+ });
52
+ var index_default = provider;
53
+ export {
54
+ DEFAULT_CACHE_NAME_PREFIX,
55
+ DEFAULT_CAS_ATTEMPTS,
56
+ DEFAULT_COMMAND_TIMEOUT_MS,
57
+ DEFAULT_CONNECT_TIMEOUT_MS,
58
+ DEFAULT_MAX_VALUE_BYTES,
59
+ DEFAULT_MUTATION_CONCURRENCY,
60
+ DEFAULT_SCAN_PAGE_SIZE,
61
+ DEFAULT_SCAN_TIMEOUT_MS,
62
+ IGNITE_PROVIDER_ID2 as IGNITE_PROVIDER_ID,
63
+ IgniteCacheValueTooLargeError,
64
+ RECORD_FORMAT_VERSION,
65
+ index_default as default,
66
+ igniteCacheName2 as igniteCacheName,
67
+ igniteCacheProviderSettingsSchema2 as igniteCacheProviderSettingsSchema,
68
+ igniteTransportWarnings2 as igniteTransportWarnings,
69
+ provider,
70
+ redactIgniteCacheProviderConfig2 as redactIgniteCacheProviderConfig
71
+ };
72
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["import { defineCacheProvider } from '@open-mercato/cache/provider'\nimport { createIgniteConnection } from './connection'\nimport { igniteCacheName } from './layout'\nimport { createIgniteStrategy } from './strategy'\nimport {\n IGNITE_PROVIDER_ID,\n hasVerifiedIgniteTransport,\n igniteCacheProviderSettingsSchema,\n igniteTransportWarnings,\n redactIgniteCacheProviderConfig,\n type IgniteCacheProviderConfig,\n} from './settings'\n\nconst TRANSPORT_WARNING_MESSAGES = {\n tls_verification_disabled: 'TLS server certificate verification is disabled (tls.rejectUnauthorized: false); the connection is open to interception',\n credentials_over_plaintext: 'credentials are sent over a plaintext connection; configure tls',\n} as const\n\nexport {\n IGNITE_PROVIDER_ID,\n DEFAULT_CACHE_NAME_PREFIX,\n DEFAULT_CAS_ATTEMPTS,\n DEFAULT_COMMAND_TIMEOUT_MS,\n DEFAULT_CONNECT_TIMEOUT_MS,\n DEFAULT_MAX_VALUE_BYTES,\n DEFAULT_MUTATION_CONCURRENCY,\n DEFAULT_SCAN_PAGE_SIZE,\n DEFAULT_SCAN_TIMEOUT_MS,\n igniteCacheProviderSettingsSchema,\n igniteTransportWarnings,\n redactIgniteCacheProviderConfig,\n} from './settings'\nexport type { IgniteCacheProviderConfig, IgniteCacheProviderSettingsInput, IgniteTransportWarning } from './settings'\nexport { igniteCacheName, RECORD_FORMAT_VERSION } from './layout'\nexport { IgniteCacheValueTooLargeError } from './strategy'\n\nexport const provider = defineCacheProvider<IgniteCacheProviderConfig>({\n id: IGNITE_PROVIDER_ID,\n settings: igniteCacheProviderSettingsSchema,\n capability(config) {\n return { placement: hasVerifiedIgniteTransport(config) ? 'shared' : 'local' }\n },\n async create(config, context) {\n for (const warning of igniteTransportWarnings(config)) context.logger.warn(TRANSPORT_WARNING_MESSAGES[warning])\n const connection = createIgniteConnection(config, igniteCacheName(config.cacheNamePrefix, context.namespace))\n const strategy = createIgniteStrategy(config, context, connection)\n try {\n await strategy.healthcheck!()\n } catch (error) {\n await connection.close()\n throw error\n }\n return strategy\n },\n redact: redactIgniteCacheProviderConfig,\n})\n\nexport default provider\n"],
5
+ "mappings": "AAAA,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AACvC,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,MAAM,6BAA6B;AAAA,EACjC,2BAA2B;AAAA,EAC3B,4BAA4B;AAC9B;AAEA;AAAA,EACE,sBAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,qCAAAC;AAAA,EACA,2BAAAC;AAAA,EACA,mCAAAC;AAAA,OACK;AAEP,SAAS,mBAAAC,kBAAiB,6BAA6B;AACvD,SAAS,qCAAqC;AAEvC,MAAM,WAAW,oBAA+C;AAAA,EACrE,IAAI;AAAA,EACJ,UAAU;AAAA,EACV,WAAW,QAAQ;AACjB,WAAO,EAAE,WAAW,2BAA2B,MAAM,IAAI,WAAW,QAAQ;AAAA,EAC9E;AAAA,EACA,MAAM,OAAO,QAAQ,SAAS;AAC5B,eAAW,WAAW,wBAAwB,MAAM,EAAG,SAAQ,OAAO,KAAK,2BAA2B,OAAO,CAAC;AAC9G,UAAM,aAAa,uBAAuB,QAAQ,gBAAgB,OAAO,iBAAiB,QAAQ,SAAS,CAAC;AAC5G,UAAM,WAAW,qBAAqB,QAAQ,SAAS,UAAU;AACjE,QAAI;AACF,YAAM,SAAS,YAAa;AAAA,IAC9B,SAAS,OAAO;AACd,YAAM,WAAW,MAAM;AACvB,YAAM;AAAA,IACR;AACA,WAAO;AAAA,EACT;AAAA,EACA,QAAQ;AACV,CAAC;AAED,IAAO,gBAAQ;",
6
+ "names": ["IGNITE_PROVIDER_ID", "igniteCacheProviderSettingsSchema", "igniteTransportWarnings", "redactIgniteCacheProviderConfig", "igniteCacheName"]
7
+ }