@tigerdata/mcp-boilerplate 1.5.3 → 1.6.0

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/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { Cache } from './cache.js';
2
1
  export { cliEntrypoint } from './cliEntrypoint.js';
3
2
  export { httpServerFactory } from './httpServer.js';
4
3
  export { log } from './logger.js';
@@ -6,5 +5,6 @@ export type { AdditionalSetupArgs } from './mcpServer.js';
6
5
  export { registerExitHandlers } from './registerExitHandlers.js';
7
6
  export { StatusError } from './StatusError.js';
8
7
  export { stdioServerFactory } from './stdio.js';
8
+ export { ArrayStore, Store } from './store.js';
9
9
  export { addAiResultToSpan, withSpan } from './tracing.js';
10
10
  export type { ApiFactory, InferSchema, McpFeatureFlags, MigrationsConfig, ParsedQs, PromptFactory, ResourceFactory, } from './types.js';
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- export { Cache } from './cache.js';
2
1
  export { cliEntrypoint } from './cliEntrypoint.js';
3
2
  export { httpServerFactory } from './httpServer.js';
4
3
  export { log } from './logger.js';
5
4
  export { registerExitHandlers } from './registerExitHandlers.js';
6
5
  export { StatusError } from './StatusError.js';
7
6
  export { stdioServerFactory } from './stdio.js';
7
+ export { ArrayStore, Store } from './store.js';
8
8
  export { addAiResultToSpan, withSpan } from './tracing.js';
@@ -0,0 +1,22 @@
1
+ interface StoreProps<T> {
2
+ fetch: () => Promise<T>;
3
+ ttl?: number;
4
+ }
5
+ export declare class Store<T> {
6
+ private contents;
7
+ private fetch;
8
+ private ttl?;
9
+ private expirationDateTime?;
10
+ constructor({ fetch, ttl }: StoreProps<T>);
11
+ get(): Promise<T>;
12
+ }
13
+ interface ArrayStoreProps<T> {
14
+ fetch: () => Promise<T[]>;
15
+ ttl?: number;
16
+ }
17
+ export declare class ArrayStore<T> extends Store<T[]> {
18
+ constructor({ fetch, ttl }: ArrayStoreProps<T>);
19
+ find(predicate: (item: T) => boolean): Promise<T | null>;
20
+ filter(predicate: (item: T) => boolean): Promise<T[]>;
21
+ }
22
+ export {};
@@ -1,20 +1,30 @@
1
- export class Cache {
1
+ export class Store {
2
2
  contents = null;
3
3
  fetch;
4
+ ttl;
4
5
  expirationDateTime;
5
6
  constructor({ fetch, ttl }) {
6
7
  this.fetch = fetch;
7
8
  if (ttl) {
9
+ this.ttl = ttl;
8
10
  this.expirationDateTime = Date.now() + ttl;
9
11
  }
10
12
  }
11
13
  async get() {
12
14
  if (this.expirationDateTime && Date.now() > this.expirationDateTime) {
13
15
  this.contents = null;
16
+ if (this.ttl) {
17
+ this.expirationDateTime = Date.now() + this.ttl;
18
+ }
14
19
  }
15
20
  this.contents ??= this.fetch();
16
21
  return this.contents;
17
22
  }
23
+ }
24
+ export class ArrayStore extends Store {
25
+ constructor({ fetch, ttl }) {
26
+ super({ fetch, ttl });
27
+ }
18
28
  async find(predicate) {
19
29
  const items = await this.get();
20
30
  return items.find(predicate) ?? null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tigerdata/mcp-boilerplate",
3
- "version": "1.5.3",
3
+ "version": "1.6.0",
4
4
  "description": "MCP boilerplate code for Node.js",
5
5
  "license": "Apache-2.0",
6
6
  "author": "TigerData",
package/dist/cache.d.ts DELETED
@@ -1,15 +0,0 @@
1
- interface CacheProps<T> {
2
- contents?: T;
3
- fetch: () => Promise<T[]>;
4
- ttl?: number;
5
- }
6
- export declare class Cache<T> {
7
- private contents;
8
- private fetch;
9
- private expirationDateTime?;
10
- constructor({ fetch, ttl }: CacheProps<T>);
11
- get(): Promise<T[]>;
12
- find(predicate: (item: T) => boolean): Promise<T | null>;
13
- filter(predicate: (item: T) => boolean): Promise<T[]>;
14
- }
15
- export {};