@igniter-js/caller 0.1.3 → 0.1.5

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/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  All notable changes to this package will be documented in this file.
4
4
 
5
+ ## 0.1.3
6
+
7
+ ### Added
8
+
9
+ - Telemetry integration via `@igniter-js/telemetry` with a dedicated subpath export.
10
+ - Mock store adapter in `@igniter-js/caller/adapters` for testing.
11
+ - Expanded test coverage for core, builders, adapters, and utils.
12
+
13
+ ### Changed
14
+
15
+ - Standardized builders/core structure and public entrypoint pattern.
16
+ - Updated documentation to match the current API and telemetry events.
17
+
5
18
  ## 0.1.1
6
19
 
7
20
  ### New Features
package/README.md CHANGED
@@ -14,7 +14,8 @@ Type-safe HTTP client for Igniter.js apps. Built on top of `fetch`, it gives you
14
14
  - ✅ **Retries** - linear or exponential backoff + status-based retry
15
15
  - ✅ **Caching** - in-memory cache + optional persistent store adapter
16
16
  - ✅ **Schema Validation** - validate request/response using `StandardSchemaV1`
17
- - ✅ **Zod Support** - optional per-request `responseType(zodSchema)` validation
17
+ - ✅ **StandardSchema Support** - Zod or any library that implements `StandardSchemaV1`
18
+ - ✅ **Telemetry-ready** - optional integration with `@igniter-js/telemetry`
18
19
  - ✅ **Global Events** - observe responses for logging/telemetry/cache invalidation
19
20
  - ✅ **Auto query encoding** - body in GET requests converts to query params
20
21
 
@@ -22,19 +23,29 @@ Type-safe HTTP client for Igniter.js apps. Built on top of `fetch`, it gives you
22
23
 
23
24
  ```bash
24
25
  # npm
25
- npm install @igniter-js/caller @igniter-js/core zod
26
+ npm install @igniter-js/caller @igniter-js/common
26
27
 
27
28
  # pnpm
28
- pnpm add @igniter-js/caller @igniter-js/core zod
29
+ pnpm add @igniter-js/caller @igniter-js/common
29
30
 
30
31
  # yarn
31
- yarn add @igniter-js/caller @igniter-js/core zod
32
+ yarn add @igniter-js/caller @igniter-js/common
32
33
 
33
34
  # bun
34
- bun add @igniter-js/caller @igniter-js/core zod
35
+ bun add @igniter-js/caller @igniter-js/common
35
36
  ```
36
37
 
37
- > `@igniter-js/core` and `zod` are peer dependencies.
38
+ Optional dependencies:
39
+
40
+ ```bash
41
+ # Telemetry (optional)
42
+ npm install @igniter-js/telemetry
43
+
44
+ # Schema validation (optional - Zod or any StandardSchemaV1-compatible lib)
45
+ npm install zod
46
+ ```
47
+
48
+ > `@igniter-js/common` is required. `@igniter-js/telemetry` and `zod` are optional peer dependencies.
38
49
 
39
50
  ## Quick Start
40
51
 
@@ -62,6 +73,124 @@ if (result.error) {
62
73
  console.log(result.data)
63
74
  ```
64
75
 
76
+ ## React Client (Provider + Hooks)
77
+
78
+ The React client is exposed via the dedicated subpath export:
79
+
80
+ ```ts
81
+ import { IgniterCallerProvider, useIgniterCaller } from '@igniter-js/caller/client'
82
+ ```
83
+
84
+ This keeps the root entrypoint server-safe and avoids bundling React in non-React environments.
85
+
86
+ ### Basic usage
87
+
88
+ ```tsx
89
+ import { IgniterCallerProvider, useIgniterCaller } from '@igniter-js/caller/client'
90
+
91
+ export function CallerProvider() {
92
+ return (
93
+ <IgniterCallerProvider callers={{ github: githubApi }}>
94
+ <UserProfile />
95
+ </IgniterCallerProvider>
96
+ )
97
+ }
98
+
99
+ export const useCaller = useIgniterCaller<{
100
+ github: typeof githubApi
101
+ }>()
102
+
103
+ function UserProfile() {
104
+ const github = useCaller('github')
105
+ const { data, isLoading, error, refetch, invalidate } = github
106
+ .get('/me')
107
+ .useQuery({
108
+ params: {},
109
+ query: {},
110
+ headers: {},
111
+ cookies: {},
112
+ staleTime: 5000,
113
+ enabled: true,
114
+ })
115
+
116
+ if (isLoading) return <div>Loading...</div>
117
+ if (error) return <div>Error</div>
118
+ return <pre>{JSON.stringify(data, null, 2)}</pre>
119
+ }
120
+ ```
121
+
122
+ ### Global config and invalidation
123
+
124
+ ```tsx
125
+ const github = useCaller('github')
126
+
127
+ // Global defaults
128
+ github.config.set('headers', { Authorization: 'Bearer ...' })
129
+ github.config.set('cookies', { session: '...' })
130
+ github.config.set('query', { locale: 'en' })
131
+
132
+ // Typed invalidation with optional optimistic data
133
+ github.invalidate('/me', { id: 'user_123' })
134
+ ```
135
+
136
+ ### Client safety notes
137
+
138
+ - If your Caller instance uses store adapters or telemetry managers that are server-only,
139
+ do not bundle that instance into browser code. Create a browser-safe instance instead.
140
+ - The React client does not automatically wire store/telemetry to avoid bundler contamination.
141
+
142
+ ## Mocking (IgniterCallerMock)
143
+
144
+ Use `IgniterCallerMock` to create a type-safe mock registry based on your schemas.
145
+
146
+ ```ts
147
+ import { IgniterCaller, IgniterCallerMock } from '@igniter-js/caller'
148
+
149
+ const schemas = {
150
+ '/users/:id': {
151
+ GET: {
152
+ responses: {
153
+ 200: UserSchema,
154
+ },
155
+ },
156
+ },
157
+ }
158
+
159
+ const mock = IgniterCallerMock.create()
160
+ .withSchemas(schemas)
161
+ .mock('/users/:id', {
162
+ GET: {
163
+ response: { id: 'user_1' },
164
+ },
165
+ })
166
+ .build()
167
+
168
+ const api = IgniterCaller.create()
169
+ .withSchemas(schemas)
170
+ .withMock({ enabled: true, mock })
171
+ .build()
172
+ ```
173
+
174
+ Mock handlers receive the full request context:
175
+
176
+ ```ts
177
+ const mock = IgniterCallerMock.create()
178
+ .withSchemas(schemas)
179
+ .mock('/users/:id', {
180
+ GET: (request) => ({
181
+ response: { id: request.params.id },
182
+ status: 200,
183
+ delayMs: 150,
184
+ }),
185
+ })
186
+ .build()
187
+ ```
188
+
189
+ Notes:
190
+
191
+ - If mock is enabled but there is no handler for a request, it falls back to the real request.
192
+ - Mock responses can include `status`, `headers`, and optional `delayMs`.
193
+
65
194
  ## HTTP Methods
66
195
 
67
196
  All HTTP methods accept an optional URL directly:
@@ -230,9 +359,66 @@ const api = IgniterCaller.create()
230
359
  .build()
231
360
  ```
232
361
 
362
+ ## Adapters
363
+
364
+ The package ships a mock store adapter for tests and local development:
365
+
366
+ ```ts
367
+ import { MockCallerStoreAdapter } from '@igniter-js/caller/adapters'
368
+ import { IgniterCaller } from '@igniter-js/caller'
369
+
370
+ const store = MockCallerStoreAdapter.create()
371
+
372
+ const api = IgniterCaller.create()
373
+ .withStore(store)
374
+ .build()
375
+ ```
376
+
233
377
  ## Schema Validation (StandardSchemaV1)
234
378
 
235
379
  If you already use schemas in your Igniter.js app, you can validate requests and responses automatically.
380
+ Schemas must implement `StandardSchemaV1` (Zod is supported, and any compatible library works).
381
+
382
+ ### Preferred: IgniterCallerSchema builder
383
+
384
+ ```ts
385
+ import { IgniterCaller, IgniterCallerSchema } from '@igniter-js/caller'
386
+ import { z } from 'zod'
387
+
388
+ const UserSchema = z.object({ id: z.string(), name: z.string() })
389
+ const ErrorSchema = z.object({ message: z.string() })
390
+
391
+ const callerSchemas = IgniterCallerSchema.create()
392
+ .schema('User', UserSchema)
393
+ .schema('Error', ErrorSchema)
394
+ .path('/users/:id', (path) =>
395
+ path.get({
396
+ responses: {
397
+ 200: path.ref('User').schema,
398
+ 404: path.ref('Error').schema,
399
+ },
400
+ doc: 'Get user by id',
401
+ tags: ['users'],
402
+ operationId: 'users.get',
403
+ }),
404
+ )
405
+ .build()
406
+
407
+ const api = IgniterCaller.create()
408
+ .withBaseUrl('https://api.example.com')
409
+ .withSchemas(callerSchemas, { mode: 'strict' })
410
+ .build()
411
+
412
+ type UserResponse = ReturnType<
413
+ typeof callerSchemas.$Infer.Response<'/users/:id', 'GET', 200>
414
+ >
415
+ ```
416
+
417
+ `callerSchemas.get` exposes runtime helpers (`path`, `endpoint`, `request`, `response`, `schema`) and
418
+ `callerSchemas.$Infer` provides type inference without extra imports. `path.ref()` helpers use Zod
419
+ wrappers; when using a different StandardSchema implementation, use `ref().schema` directly.
420
+
421
+ ### Manual object literal (still supported)
236
422
 
237
423
  ```ts
238
424
  import { IgniterCaller } from '@igniter-js/caller'
@@ -270,10 +456,17 @@ By default this outputs `src/callers/<hostname>/schema.ts` and `index.ts`:
270
456
 
271
457
  ```ts
272
458
  import { facebookCaller } from './src/callers/api.example.com'
459
+ import { facebookCallerSchemas } from './src/callers/api.example.com/schema'
273
460
 
274
461
  const result = await facebookCaller.get('/products').execute()
462
+ type ProductsResponse = ReturnType<
463
+ typeof facebookCallerSchemas.$Infer.Response<'/products', 'GET', 200>
464
+ >
275
465
  ```
276
466
 
467
+ The generated `schema.ts` uses `IgniterCallerSchema` (path-first builder), registers reusable
468
+ schemas, and includes derived type aliases for each endpoint.
469
+
277
470
  ## `responseType()` for Typing and Validation
278
471
 
279
472
  Use `responseType()` to:
@@ -296,12 +489,12 @@ const result = await api.get('/file').responseType<Blob>().execute()
296
489
 
297
490
  ## Global Events
298
491
 
299
- You can observe responses globally using `IgniterCaller.on()`:
492
+ You can observe responses globally using `IgniterCallerManager.on()`:
300
493
 
301
494
  ```ts
302
- import { IgniterCaller } from '@igniter-js/caller'
495
+ import { IgniterCallerManager } from '@igniter-js/caller'
303
496
 
304
- const unsubscribe = IgniterCaller.on(/^\/users/, (result, ctx) => {
497
+ const unsubscribe = IgniterCallerManager.on(/^\/users/, (result, ctx) => {
305
498
  console.log(`[${ctx.method}] ${ctx.url}`, {
306
499
  ok: !result.error,
307
500
  status: result.status,
@@ -312,6 +505,24 @@ const unsubscribe = IgniterCaller.on(/^\/users/, (result, ctx) => {
312
505
  unsubscribe()
313
506
  ```
314
507
 
508
+ ## Observability (Telemetry)
509
+
510
+ ```ts
511
+ import { IgniterTelemetry } from '@igniter-js/telemetry'
512
+ import { IgniterCaller } from '@igniter-js/caller'
513
+ import { IgniterCallerTelemetryEvents } from '@igniter-js/caller/telemetry'
514
+
515
+ const telemetry = IgniterTelemetry.create()
516
+ .withService('my-api')
517
+ .addEvents(IgniterCallerTelemetryEvents)
518
+ .build()
519
+
520
+ const api = IgniterCaller.create()
521
+ .withBaseUrl('https://api.example.com')
522
+ .withTelemetry(telemetry)
523
+ .build()
524
+ ```
525
+
315
526
  ## Error Handling
316
527
 
317
528
  All predictable failures return an `IgniterCallerError` with stable error codes.
@@ -351,6 +562,7 @@ Creates a new caller builder.
351
562
  | `.withResponseInterceptor(fn)` | Adds a response interceptor |
352
563
  | `.withStore(store, options)` | Configures a persistent store |
353
564
  | `.withSchemas(schemas, options)` | Configures schema validation |
565
+ | `.withTelemetry(telemetry)` | Attaches telemetry manager |
354
566
  | `.build()` | Builds the caller instance |
355
567
 
356
568
  ### Request Methods
@@ -385,11 +597,11 @@ Creates a new caller builder.
385
597
 
386
598
  | Method | Description |
387
599
  |--------|-------------|
388
- | `IgniterCaller.on(pattern, callback)` | Registers event listener |
389
- | `IgniterCaller.off(pattern, callback?)` | Removes event listener |
390
- | `IgniterCaller.invalidate(key)` | Invalidates cache entry |
391
- | `IgniterCaller.invalidatePattern(pattern)` | Invalidates cache by pattern |
392
- | `IgniterCaller.batch(requests)` | Executes requests in parallel |
600
+ | `IgniterCallerManager.on(pattern, callback)` | Registers event listener |
601
+ | `IgniterCallerManager.off(pattern, callback?)` | Removes event listener |
602
+ | `IgniterCallerManager.invalidate(key)` | Invalidates cache entry |
603
+ | `IgniterCallerManager.invalidatePattern(pattern)` | Invalidates cache by pattern |
604
+ | `IgniterCallerManager.batch(requests)` | Executes requests in parallel |
393
605
 
394
606
  ## Contributing
395
607
 
@@ -0,0 +1,70 @@
1
+ import { I as IgniterCallerStoreAdapter, a as IgniterCallerStoreOptions } from '../store-D2p2dqGN.mjs';
2
+
3
+ /**
4
+ * @fileoverview In-memory mock store adapter for @igniter-js/caller.
5
+ * @module @igniter-js/caller/adapters/mock
6
+ */
7
+
8
+ /**
9
+ * In-memory mock adapter for request caching in tests.
10
+ */
11
+ declare class MockCallerStoreAdapter implements IgniterCallerStoreAdapter<Map<string, unknown>> {
12
+ /** Creates a new mock adapter instance. */
13
+ static create(): MockCallerStoreAdapter;
14
+ /** Underlying in-memory store. */
15
+ readonly client: Map<string, unknown>;
16
+ /** Tracks all calls for assertions. */
17
+ readonly calls: {
18
+ get: number;
19
+ set: number;
20
+ delete: number;
21
+ has: number;
22
+ };
23
+ /** Captures recent operations. */
24
+ readonly history: {
25
+ get: string[];
26
+ set: Array<{
27
+ key: string;
28
+ value: unknown;
29
+ options?: IgniterCallerStoreOptions;
30
+ }>;
31
+ delete: string[];
32
+ has: string[];
33
+ };
34
+ /**
35
+ * Retrieves a cached value by key.
36
+ *
37
+ * @param key - Cache key (without prefix).
38
+ * @returns Cached value or null.
39
+ */
40
+ get<T = any>(key: string): Promise<T | null>;
41
+ /**
42
+ * Stores a cached value.
43
+ *
44
+ * @param key - Cache key (without prefix).
45
+ * @param value - Value to store.
46
+ * @param options - Cache options (ttl, etc).
47
+ */
48
+ set(key: string, value: any, options?: IgniterCallerStoreOptions): Promise<void>;
49
+ /**
50
+ * Removes a cached value.
51
+ *
52
+ * @param key - Cache key (without prefix).
53
+ */
54
+ delete(key: string): Promise<void>;
55
+ /**
56
+ * Checks if a cached value exists.
57
+ *
58
+ * @param key - Cache key (without prefix).
59
+ * @returns True when the key exists.
60
+ */
61
+ has(key: string): Promise<boolean>;
62
+ /**
63
+ * Clears all tracked state.
64
+ *
65
+ * @returns Nothing.
66
+ */
67
+ clear(): void;
68
+ }
69
+
70
+ export { MockCallerStoreAdapter };
@@ -0,0 +1,70 @@
1
+ import { I as IgniterCallerStoreAdapter, a as IgniterCallerStoreOptions } from '../store-D2p2dqGN.js';
2
+
3
+ /**
4
+ * @fileoverview In-memory mock store adapter for @igniter-js/caller.
5
+ * @module @igniter-js/caller/adapters/mock
6
+ */
7
+
8
+ /**
9
+ * In-memory mock adapter for request caching in tests.
10
+ */
11
+ declare class MockCallerStoreAdapter implements IgniterCallerStoreAdapter<Map<string, unknown>> {
12
+ /** Creates a new mock adapter instance. */
13
+ static create(): MockCallerStoreAdapter;
14
+ /** Underlying in-memory store. */
15
+ readonly client: Map<string, unknown>;
16
+ /** Tracks all calls for assertions. */
17
+ readonly calls: {
18
+ get: number;
19
+ set: number;
20
+ delete: number;
21
+ has: number;
22
+ };
23
+ /** Captures recent operations. */
24
+ readonly history: {
25
+ get: string[];
26
+ set: Array<{
27
+ key: string;
28
+ value: unknown;
29
+ options?: IgniterCallerStoreOptions;
30
+ }>;
31
+ delete: string[];
32
+ has: string[];
33
+ };
34
+ /**
35
+ * Retrieves a cached value by key.
36
+ *
37
+ * @param key - Cache key (without prefix).
38
+ * @returns Cached value or null.
39
+ */
40
+ get<T = any>(key: string): Promise<T | null>;
41
+ /**
42
+ * Stores a cached value.
43
+ *
44
+ * @param key - Cache key (without prefix).
45
+ * @param value - Value to store.
46
+ * @param options - Cache options (ttl, etc).
47
+ */
48
+ set(key: string, value: any, options?: IgniterCallerStoreOptions): Promise<void>;
49
+ /**
50
+ * Removes a cached value.
51
+ *
52
+ * @param key - Cache key (without prefix).
53
+ */
54
+ delete(key: string): Promise<void>;
55
+ /**
56
+ * Checks if a cached value exists.
57
+ *
58
+ * @param key - Cache key (without prefix).
59
+ * @returns True when the key exists.
60
+ */
61
+ has(key: string): Promise<boolean>;
62
+ /**
63
+ * Clears all tracked state.
64
+ *
65
+ * @returns Nothing.
66
+ */
67
+ clear(): void;
68
+ }
69
+
70
+ export { MockCallerStoreAdapter };
@@ -0,0 +1,91 @@
1
+ 'use strict';
2
+
3
+ // src/adapters/mock.adapter.ts
4
+ var MockCallerStoreAdapter = class _MockCallerStoreAdapter {
5
+ constructor() {
6
+ /** Underlying in-memory store. */
7
+ this.client = /* @__PURE__ */ new Map();
8
+ /** Tracks all calls for assertions. */
9
+ this.calls = {
10
+ get: 0,
11
+ set: 0,
12
+ delete: 0,
13
+ has: 0
14
+ };
15
+ /** Captures recent operations. */
16
+ this.history = {
17
+ get: [],
18
+ set: [],
19
+ delete: [],
20
+ has: []
21
+ };
22
+ }
23
+ /** Creates a new mock adapter instance. */
24
+ static create() {
25
+ return new _MockCallerStoreAdapter();
26
+ }
27
+ /**
28
+ * Retrieves a cached value by key.
29
+ *
30
+ * @param key - Cache key (without prefix).
31
+ * @returns Cached value or null.
32
+ */
33
+ async get(key) {
34
+ this.calls.get += 1;
35
+ this.history.get.push(key);
36
+ return this.client.has(key) ? this.client.get(key) : null;
37
+ }
38
+ /**
39
+ * Stores a cached value.
40
+ *
41
+ * @param key - Cache key (without prefix).
42
+ * @param value - Value to store.
43
+ * @param options - Cache options (ttl, etc).
44
+ */
45
+ async set(key, value, options) {
46
+ this.calls.set += 1;
47
+ this.history.set.push({ key, value, options });
48
+ this.client.set(key, value);
49
+ }
50
+ /**
51
+ * Removes a cached value.
52
+ *
53
+ * @param key - Cache key (without prefix).
54
+ */
55
+ async delete(key) {
56
+ this.calls.delete += 1;
57
+ this.history.delete.push(key);
58
+ this.client.delete(key);
59
+ }
60
+ /**
61
+ * Checks if a cached value exists.
62
+ *
63
+ * @param key - Cache key (without prefix).
64
+ * @returns True when the key exists.
65
+ */
66
+ async has(key) {
67
+ this.calls.has += 1;
68
+ this.history.has.push(key);
69
+ return this.client.has(key);
70
+ }
71
+ /**
72
+ * Clears all tracked state.
73
+ *
74
+ * @returns Nothing.
75
+ */
76
+ clear() {
77
+ this.client.clear();
78
+ this.calls.get = 0;
79
+ this.calls.set = 0;
80
+ this.calls.delete = 0;
81
+ this.calls.has = 0;
82
+ this.history.get = [];
83
+ this.history.set = [];
84
+ this.history.delete = [];
85
+ this.history.has = [];
86
+ }
87
+ };
88
+
89
+ exports.MockCallerStoreAdapter = MockCallerStoreAdapter;
90
+ //# sourceMappingURL=index.js.map
91
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/adapters/mock.adapter.ts"],"names":[],"mappings":";;;AAUO,IAAM,sBAAA,GAAN,MAAM,uBAAA,CAEb;AAAA,EAFO,WAAA,GAAA;AASL;AAAA,IAAA,IAAA,CAAS,MAAA,uBAAa,GAAA,EAAqB;AAG3C;AAAA,IAAA,IAAA,CAAS,KAAA,GAAQ;AAAA,MACf,GAAA,EAAK,CAAA;AAAA,MACL,GAAA,EAAK,CAAA;AAAA,MACL,MAAA,EAAQ,CAAA;AAAA,MACR,GAA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AM,IAAI,GAAA,EAA+B;AACvC,IAAA,IAAA,CAAK,MAAM,GAAA,IAAO,CAAA;AAClB,IAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,IAAA,CAAK,GAAG,CAAA;AACzB,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,GAAG,CAAA;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,KAAA,GAAc;AACZ,IAAA,IAAA,CAAK,OAAO,KAAA,EAAM;AAClB,IAAA,IAAA,CAAK,MAAM,GAAA,GAAM,CAAA;AACjB,IAAA,IAAA,CAAK,MAAM,GAAA,GAAM,CAAA;AACjB,IAAA,IAAA,CAAK,MAAM,MAAA,GAAS,CAAA;AACpB,IAAA,IAAA,CAAK,MAAM,GAAA,GAAM,CAAA;AACjB,IAAA,IAAA,CAAK,OAAA,CAAQ,MAAM,EAAC;AACpB,IAAA,IAAA,CAAK,OAAA,CAAQ,MAAM,EAAC;AACpB,IAAA,IAAA,CAAK,OAAA,CAAQ,SAAS,EAAC;AACvB,IAAA,IAAA,CAAK,OAAA,CAAQ,MAAM,EAAC;AAAA,EACtB;AACF","file":"index.js","sourcesContent":["/**\n * @fileoverview In-memory mock store adapter for @igniter-js/caller.\n * @module @igniter-js/caller/adapters/mock\n */\n\nimport type { IgniterCallerStoreAdapter, IgniterCallerStoreOptions } from \"../types/store\";\n\n/**\n * In-memory mock adapter for request caching in tests.\n */\nexport class MockCallerStoreAdapter\n implements IgniterCallerStoreAdapter<Map<string, unknown>>\n{\n /** Creates a new mock adapter instance. */\n static create(): MockCallerStoreAdapter {\n return new MockCallerStoreAdapter();\n }\n\n /** Underlying in-memory store. */\n readonly client = new Map<string, unknown>();\n\n /** Tracks all calls for assertions. */\n readonly calls = {\n get: 0,\n set: 0,\n delete: 0,\n has: 0,\n };\n\n /** Captures recent operations. */\n readonly history = {\n get: [] as string[],\n set: [] as Array<{ key: string; value: unknown; options?: IgniterCallerStoreOptions }>,\n delete: [] as string[],\n has: [] as string[],\n };\n\n /**\n * Retrieves a cached value by key.\n *\n * @param key - Cache key (without prefix).\n * @returns Cached value or null.\n */\n async get<T = any>(key: string): Promise<T | null> {\n this.calls.get += 1;\n this.history.get.push(key);\n return (this.client.has(key) ? (this.client.get(key) as T) : null);\n }\n\n /**\n * Stores a cached value.\n *\n * @param key - Cache key (without prefix).\n * @param value - Value to store.\n * @param options - Cache options (ttl, etc).\n */\n async set(\n key: string,\n value: any,\n options?: IgniterCallerStoreOptions,\n ): Promise<void> {\n this.calls.set += 1;\n this.history.set.push({ key, value, options });\n this.client.set(key, value);\n }\n\n /**\n * Removes a cached value.\n *\n * @param key - Cache key (without prefix).\n */\n async delete(key: string): Promise<void> {\n this.calls.delete += 1;\n this.history.delete.push(key);\n this.client.delete(key);\n }\n\n /**\n * Checks if a cached value exists.\n *\n * @param key - Cache key (without prefix).\n * @returns True when the key exists.\n */\n async has(key: string): Promise<boolean> {\n this.calls.has += 1;\n this.history.has.push(key);\n return this.client.has(key);\n }\n\n /**\n * Clears all tracked state.\n *\n * @returns Nothing.\n */\n clear(): void {\n this.client.clear();\n this.calls.get = 0;\n this.calls.set = 0;\n this.calls.delete = 0;\n this.calls.has = 0;\n this.history.get = [];\n this.history.set = [];\n this.history.delete = [];\n this.history.has = [];\n }\n}\n"]}
@@ -0,0 +1,89 @@
1
+ // src/adapters/mock.adapter.ts
2
+ var MockCallerStoreAdapter = class _MockCallerStoreAdapter {
3
+ constructor() {
4
+ /** Underlying in-memory store. */
5
+ this.client = /* @__PURE__ */ new Map();
6
+ /** Tracks all calls for assertions. */
7
+ this.calls = {
8
+ get: 0,
9
+ set: 0,
10
+ delete: 0,
11
+ has: 0
12
+ };
13
+ /** Captures recent operations. */
14
+ this.history = {
15
+ get: [],
16
+ set: [],
17
+ delete: [],
18
+ has: []
19
+ };
20
+ }
21
+ /** Creates a new mock adapter instance. */
22
+ static create() {
23
+ return new _MockCallerStoreAdapter();
24
+ }
25
+ /**
26
+ * Retrieves a cached value by key.
27
+ *
28
+ * @param key - Cache key (without prefix).
29
+ * @returns Cached value or null.
30
+ */
31
+ async get(key) {
32
+ this.calls.get += 1;
33
+ this.history.get.push(key);
34
+ return this.client.has(key) ? this.client.get(key) : null;
35
+ }
36
+ /**
37
+ * Stores a cached value.
38
+ *
39
+ * @param key - Cache key (without prefix).
40
+ * @param value - Value to store.
41
+ * @param options - Cache options (ttl, etc).
42
+ */
43
+ async set(key, value, options) {
44
+ this.calls.set += 1;
45
+ this.history.set.push({ key, value, options });
46
+ this.client.set(key, value);
47
+ }
48
+ /**
49
+ * Removes a cached value.
50
+ *
51
+ * @param key - Cache key (without prefix).
52
+ */
53
+ async delete(key) {
54
+ this.calls.delete += 1;
55
+ this.history.delete.push(key);
56
+ this.client.delete(key);
57
+ }
58
+ /**
59
+ * Checks if a cached value exists.
60
+ *
61
+ * @param key - Cache key (without prefix).
62
+ * @returns True when the key exists.
63
+ */
64
+ async has(key) {
65
+ this.calls.has += 1;
66
+ this.history.has.push(key);
67
+ return this.client.has(key);
68
+ }
69
+ /**
70
+ * Clears all tracked state.
71
+ *
72
+ * @returns Nothing.
73
+ */
74
+ clear() {
75
+ this.client.clear();
76
+ this.calls.get = 0;
77
+ this.calls.set = 0;
78
+ this.calls.delete = 0;
79
+ this.calls.has = 0;
80
+ this.history.get = [];
81
+ this.history.set = [];
82
+ this.history.delete = [];
83
+ this.history.has = [];
84
+ }
85
+ };
86
+
87
+ export { MockCallerStoreAdapter };
88
+ //# sourceMappingURL=index.mjs.map
89
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/adapters/mock.adapter.ts"],"names":[],"mappings":";AAUO,IAAM,sBAAA,GAAN,MAAM,uBAAA,CAEb;AAAA,EAFO,WAAA,GAAA;AASL;AAAA,IAAA,IAAA,CAAS,MAAA,uBAAa,GAAA,EAAqB;AAG3C;AAAA,IAAA,IAAA,CAAS,KAAA,GAAQ;AAAA,MACf,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AAA,CAAO,OAAO,GAAG,CAAA;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,IAAI,GAAA,EAA+B;AACvC,IAAA,IAAA,CAAK,MAAM,GAAA,IAAO,CAAA;AAClB,IAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,IAAA,CAAK,GAAG,CAAA;AACzB,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,GAAG,CAAA;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,KAAA,GAAc;AACZ,IAAA,IAAA,CAAK,OAAO,KAAA,EAAM;AAClB,IAAA,IAAA,CAAK,MAAM,GAAA,GAAM,CAAA;AACjB,IAAA,IAAA,CAAK,MAAM,GAAA,GAAM,CAAA;AACjB,IAAA,IAAA,CAAK,MAAM,MAAA,GAAS,CAAA;AACpB,IAAA,IAAA,CAAK,MAAM,GAAA,GAAM,CAAA;AACjB,IAAA,IAAA,CAAK,OAAA,CAAQ,MAAM,EAAC;AACpB,IAAA,IAAA,CAAK,OAAA,CAAQ,MAAM,EAAC;AACpB,IAAA,IAAA,CAAK,OAAA,CAAQ,SAAS,EAAC;AACvB,IAAA,IAAA,CAAK,OAAA,CAAQ,MAAM,EAAC;AAAA,EACtB;AACF","file":"index.mjs","sourcesContent":["/**\n * @fileoverview In-memory mock store adapter for @igniter-js/caller.\n * @module @igniter-js/caller/adapters/mock\n */\n\nimport type { IgniterCallerStoreAdapter, IgniterCallerStoreOptions } from \"../types/store\";\n\n/**\n * In-memory mock adapter for request caching in tests.\n */\nexport class MockCallerStoreAdapter\n implements IgniterCallerStoreAdapter<Map<string, unknown>>\n{\n /** Creates a new mock adapter instance. */\n static create(): MockCallerStoreAdapter {\n return new MockCallerStoreAdapter();\n }\n\n /** Underlying in-memory store. */\n readonly client = new Map<string, unknown>();\n\n /** Tracks all calls for assertions. */\n readonly calls = {\n get: 0,\n set: 0,\n delete: 0,\n has: 0,\n };\n\n /** Captures recent operations. */\n readonly history = {\n get: [] as string[],\n set: [] as Array<{ key: string; value: unknown; options?: IgniterCallerStoreOptions }>,\n delete: [] as string[],\n has: [] as string[],\n };\n\n /**\n * Retrieves a cached value by key.\n *\n * @param key - Cache key (without prefix).\n * @returns Cached value or null.\n */\n async get<T = any>(key: string): Promise<T | null> {\n this.calls.get += 1;\n this.history.get.push(key);\n return (this.client.has(key) ? (this.client.get(key) as T) : null);\n }\n\n /**\n * Stores a cached value.\n *\n * @param key - Cache key (without prefix).\n * @param value - Value to store.\n * @param options - Cache options (ttl, etc).\n */\n async set(\n key: string,\n value: any,\n options?: IgniterCallerStoreOptions,\n ): Promise<void> {\n this.calls.set += 1;\n this.history.set.push({ key, value, options });\n this.client.set(key, value);\n }\n\n /**\n * Removes a cached value.\n *\n * @param key - Cache key (without prefix).\n */\n async delete(key: string): Promise<void> {\n this.calls.delete += 1;\n this.history.delete.push(key);\n this.client.delete(key);\n }\n\n /**\n * Checks if a cached value exists.\n *\n * @param key - Cache key (without prefix).\n * @returns True when the key exists.\n */\n async has(key: string): Promise<boolean> {\n this.calls.has += 1;\n this.history.has.push(key);\n return this.client.has(key);\n }\n\n /**\n * Clears all tracked state.\n *\n * @returns Nothing.\n */\n clear(): void {\n this.client.clear();\n this.calls.get = 0;\n this.calls.set = 0;\n this.calls.delete = 0;\n this.calls.has = 0;\n this.history.get = [];\n this.history.set = [];\n this.history.delete = [];\n this.history.has = [];\n }\n}\n"]}