@juspay/yama 1.0.0 → 1.1.1

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.
@@ -1,14 +1,13 @@
1
- "use strict";
2
1
  /**
3
2
  * Core TypeScript types for Yama
4
3
  * Consolidates all interfaces and types used across the application
5
4
  */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ValidationError = exports.ProviderError = exports.ConfigurationError = exports.GuardianError = void 0;
8
5
  // ============================================================================
9
6
  // Error Types
10
7
  // ============================================================================
11
- class GuardianError extends Error {
8
+ export class GuardianError extends Error {
9
+ code;
10
+ context;
12
11
  constructor(code, message, context) {
13
12
  super(message);
14
13
  this.code = code;
@@ -16,28 +15,24 @@ class GuardianError extends Error {
16
15
  this.name = "GuardianError";
17
16
  }
18
17
  }
19
- exports.GuardianError = GuardianError;
20
- class ConfigurationError extends GuardianError {
18
+ export class ConfigurationError extends GuardianError {
21
19
  constructor(message, context) {
22
20
  super("CONFIGURATION_ERROR", message, context);
23
21
  this.name = "ConfigurationError";
24
22
  }
25
23
  }
26
- exports.ConfigurationError = ConfigurationError;
27
- class ProviderError extends GuardianError {
24
+ export class ProviderError extends GuardianError {
28
25
  constructor(message, context) {
29
26
  super("PROVIDER_ERROR", message, context);
30
27
  this.name = "ProviderError";
31
28
  }
32
29
  }
33
- exports.ProviderError = ProviderError;
34
- class ValidationError extends GuardianError {
30
+ export class ValidationError extends GuardianError {
35
31
  constructor(message, context) {
36
32
  super("VALIDATION_ERROR", message, context);
37
33
  this.name = "ValidationError";
38
34
  }
39
35
  }
40
- exports.ValidationError = ValidationError;
41
36
  // ============================================================================
42
37
  // Export all types - Main file, no re-exports needed
43
38
  // ============================================================================
@@ -2,7 +2,7 @@
2
2
  * Enhanced Cache utility for Yama
3
3
  * Provides intelligent caching for PR data, file contents, and AI responses
4
4
  */
5
- import { Cache as ICache, CacheOptions } from "../types";
5
+ import { Cache as ICache, CacheOptions } from "../types/index.js";
6
6
  export declare class Cache implements ICache {
7
7
  private cache;
8
8
  private statsData;
@@ -1,31 +1,21 @@
1
- "use strict";
2
1
  /**
3
2
  * Enhanced Cache utility for Yama
4
3
  * Provides intelligent caching for PR data, file contents, and AI responses
5
4
  */
6
- var __importDefault = (this && this.__importDefault) || function (mod) {
7
- return (mod && mod.__esModule) ? mod : { "default": mod };
8
- };
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.cache = exports.Cache = void 0;
11
- exports.createCache = createCache;
12
- const node_cache_1 = __importDefault(require("node-cache"));
13
- const Logger_1 = require("./Logger");
14
- class Cache {
5
+ import NodeCache from "node-cache";
6
+ import { logger } from "./Logger.js";
7
+ export class Cache {
8
+ cache;
9
+ statsData = {
10
+ hits: 0,
11
+ misses: 0,
12
+ };
15
13
  constructor(options = {}) {
16
- this.statsData = {
17
- hits: 0,
18
- misses: 0,
19
- };
20
- /**
21
- * Cache with tags for group invalidation
22
- */
23
- this.tags = new Map();
24
14
  const { ttl = 3600, // 1 hour default
25
15
  maxSize = 100, // 100 keys max
26
16
  checkPeriod = 600, // Check every 10 minutes
27
17
  } = options;
28
- this.cache = new node_cache_1.default({
18
+ this.cache = new NodeCache({
29
19
  stdTTL: ttl,
30
20
  maxKeys: maxSize,
31
21
  checkperiod: checkPeriod,
@@ -33,13 +23,13 @@ class Cache {
33
23
  deleteOnExpire: true,
34
24
  });
35
25
  this.cache.on("set", (key, _value) => {
36
- Logger_1.logger.debug(`Cache SET: ${key}`);
26
+ logger.debug(`Cache SET: ${key}`);
37
27
  });
38
28
  this.cache.on("expired", (key, _value) => {
39
- Logger_1.logger.debug(`Cache EXPIRED: ${key}`);
29
+ logger.debug(`Cache EXPIRED: ${key}`);
40
30
  });
41
31
  this.cache.on("del", (key, _value) => {
42
- Logger_1.logger.debug(`Cache DELETE: ${key}`);
32
+ logger.debug(`Cache DELETE: ${key}`);
43
33
  });
44
34
  }
45
35
  /**
@@ -49,12 +39,12 @@ class Cache {
49
39
  const value = this.cache.get(key);
50
40
  if (value !== undefined) {
51
41
  this.statsData.hits++;
52
- Logger_1.logger.debug(`Cache HIT: ${key}`);
42
+ logger.debug(`Cache HIT: ${key}`);
53
43
  return value;
54
44
  }
55
45
  else {
56
46
  this.statsData.misses++;
57
- Logger_1.logger.debug(`Cache MISS: ${key}`);
47
+ logger.debug(`Cache MISS: ${key}`);
58
48
  return undefined;
59
49
  }
60
50
  }
@@ -65,15 +55,15 @@ class Cache {
65
55
  try {
66
56
  const success = this.cache.set(key, value, ttl || 0);
67
57
  if (success) {
68
- Logger_1.logger.debug(`Cache SET successful: ${key}`);
58
+ logger.debug(`Cache SET successful: ${key}`);
69
59
  }
70
60
  else {
71
- Logger_1.logger.warn(`Cache SET failed: ${key}`);
61
+ logger.warn(`Cache SET failed: ${key}`);
72
62
  }
73
63
  return success;
74
64
  }
75
65
  catch (error) {
76
- Logger_1.logger.error(`Cache SET error: ${key}`, error);
66
+ logger.error(`Cache SET error: ${key}`, error);
77
67
  return false;
78
68
  }
79
69
  }
@@ -82,7 +72,7 @@ class Cache {
82
72
  */
83
73
  del(key) {
84
74
  const deleted = this.cache.del(key);
85
- Logger_1.logger.debug(`Cache DELETE: ${key}, deleted: ${deleted}`);
75
+ logger.debug(`Cache DELETE: ${key}, deleted: ${deleted}`);
86
76
  return deleted;
87
77
  }
88
78
  /**
@@ -98,7 +88,7 @@ class Cache {
98
88
  this.cache.flushAll();
99
89
  this.statsData.hits = 0;
100
90
  this.statsData.misses = 0;
101
- Logger_1.logger.debug("Cache cleared");
91
+ logger.debug("Cache cleared");
102
92
  }
103
93
  /**
104
94
  * Get all cache keys
@@ -132,16 +122,20 @@ class Cache {
132
122
  return cached;
133
123
  }
134
124
  try {
135
- Logger_1.logger.debug(`Cache FETCH: ${key}`);
125
+ logger.debug(`Cache FETCH: ${key}`);
136
126
  const value = await fetchFn();
137
127
  this.set(key, value, ttl);
138
128
  return value;
139
129
  }
140
130
  catch (error) {
141
- Logger_1.logger.error(`Cache FETCH error: ${key}`, error);
131
+ logger.error(`Cache FETCH error: ${key}`, error);
142
132
  throw error;
143
133
  }
144
134
  }
135
+ /**
136
+ * Cache with tags for group invalidation
137
+ */
138
+ tags = new Map();
145
139
  setWithTags(key, value, tags, ttl) {
146
140
  const success = this.set(key, value, ttl);
147
141
  if (success) {
@@ -169,21 +163,38 @@ class Cache {
169
163
  });
170
164
  // Clean up tag associations
171
165
  this.tags.delete(tag);
172
- Logger_1.logger.debug(`Invalidated tag "${tag}": ${deleted} keys`);
166
+ logger.debug(`Invalidated tag "${tag}": ${deleted} keys`);
173
167
  return deleted;
174
168
  }
169
+ /**
170
+ * Cache key generators for common patterns
171
+ */
172
+ static keys = {
173
+ prInfo: (workspace, repository, prId) => `pr:${workspace}:${repository}:${prId}`,
174
+ prDiff: (workspace, repository, prId) => `diff:${workspace}:${repository}:${prId}`,
175
+ fileContent: (workspace, repository, filePath, branch) => `file:${workspace}:${repository}:${branch}:${filePath}`,
176
+ directoryContent: (workspace, repository, path, branch) => `dir:${workspace}:${repository}:${branch}:${path}`,
177
+ branchInfo: (workspace, repository, branch) => `branch:${workspace}:${repository}:${branch}`,
178
+ aiResponse: (prompt, provider, model) => {
179
+ // Create a hash of the prompt for consistent keys
180
+ const hash = Buffer.from(prompt).toString("base64").slice(0, 16);
181
+ return `ai:${provider}:${model}:${hash}`;
182
+ },
183
+ projectContext: (workspace, repository, branch) => `context:${workspace}:${repository}:${branch}`,
184
+ reviewResult: (workspace, repository, prId, configHash) => `review:${workspace}:${repository}:${prId}:${configHash}`,
185
+ };
175
186
  /**
176
187
  * Smart cache warming for common patterns
177
188
  */
178
189
  async warmPRCache(workspace, repository, prId) {
179
- Logger_1.logger.debug(`Warming cache for PR ${workspace}/${repository}#${prId}`);
190
+ logger.debug(`Warming cache for PR ${workspace}/${repository}#${prId}`);
180
191
  // Pre-generate cache keys that are likely to be needed
181
192
  const keys = [
182
193
  Cache.keys.prInfo(workspace, repository, prId),
183
194
  Cache.keys.prDiff(workspace, repository, prId),
184
195
  ];
185
196
  // This would be implemented by the calling code to actually fetch the data
186
- Logger_1.logger.debug(`Cache warming prepared for keys: ${keys.join(", ")}`);
197
+ logger.debug(`Cache warming prepared for keys: ${keys.join(", ")}`);
187
198
  }
188
199
  /**
189
200
  * Cleanup expired entries and optimize memory
@@ -198,7 +209,7 @@ class Cache {
198
209
  const afterKeys = this.cache.keys().length;
199
210
  const cleaned = beforeKeys - afterKeys;
200
211
  if (cleaned > 0) {
201
- Logger_1.logger.debug(`Cache cleanup: removed ${cleaned} expired entries`);
212
+ logger.debug(`Cache cleanup: removed ${cleaned} expired entries`);
202
213
  }
203
214
  // Clean up tag associations for deleted keys
204
215
  this.tags.forEach((keys, tag) => {
@@ -228,28 +239,10 @@ class Cache {
228
239
  };
229
240
  }
230
241
  }
231
- exports.Cache = Cache;
232
- /**
233
- * Cache key generators for common patterns
234
- */
235
- Cache.keys = {
236
- prInfo: (workspace, repository, prId) => `pr:${workspace}:${repository}:${prId}`,
237
- prDiff: (workspace, repository, prId) => `diff:${workspace}:${repository}:${prId}`,
238
- fileContent: (workspace, repository, filePath, branch) => `file:${workspace}:${repository}:${branch}:${filePath}`,
239
- directoryContent: (workspace, repository, path, branch) => `dir:${workspace}:${repository}:${branch}:${path}`,
240
- branchInfo: (workspace, repository, branch) => `branch:${workspace}:${repository}:${branch}`,
241
- aiResponse: (prompt, provider, model) => {
242
- // Create a hash of the prompt for consistent keys
243
- const hash = Buffer.from(prompt).toString("base64").slice(0, 16);
244
- return `ai:${provider}:${model}:${hash}`;
245
- },
246
- projectContext: (workspace, repository, branch) => `context:${workspace}:${repository}:${branch}`,
247
- reviewResult: (workspace, repository, prId, configHash) => `review:${workspace}:${repository}:${prId}:${configHash}`,
248
- };
249
242
  // Export singleton instance
250
- exports.cache = new Cache();
243
+ export const cache = new Cache();
251
244
  // Export factory function
252
- function createCache(options) {
245
+ export function createCache(options) {
253
246
  return new Cache(options);
254
247
  }
255
248
  //# sourceMappingURL=Cache.js.map
@@ -2,7 +2,7 @@
2
2
  * Enhanced Configuration Manager for Yama
3
3
  * Handles configuration loading, validation, and merging from multiple sources
4
4
  */
5
- import { GuardianConfig } from "../types";
5
+ import { GuardianConfig } from "../types/index.js";
6
6
  export declare class ConfigManager {
7
7
  private config;
8
8
  private configPaths;