cfw-graphql-bootstrap 1.0.2 → 1.0.3
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 +1 -0
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -330,6 +330,7 @@ interface BaseContext extends JaegerContext, BaseContext$1 {
|
|
|
330
330
|
logger: typeof logger;
|
|
331
331
|
executionCtx: ExecutionContext;
|
|
332
332
|
cache?: KVCache;
|
|
333
|
+
db?: D1Database;
|
|
333
334
|
env: EnvConfig;
|
|
334
335
|
/** @deprecated should not be used directly */
|
|
335
336
|
authorization: string;
|
package/dist/index.js
CHANGED
|
@@ -669,10 +669,13 @@ async function createBaseContext(honoContext) {
|
|
|
669
669
|
"KV cache not found in context - this should not happen if using ServerBuilder"
|
|
670
670
|
);
|
|
671
671
|
}
|
|
672
|
+
const db = rawEnv?.DB;
|
|
672
673
|
return {
|
|
673
674
|
user,
|
|
674
675
|
logger,
|
|
675
676
|
cache,
|
|
677
|
+
db,
|
|
678
|
+
// Raw D1 binding for datasources
|
|
676
679
|
env,
|
|
677
680
|
// Pass validated env config
|
|
678
681
|
executionCtx: honoContext.ctx,
|
|
@@ -1410,8 +1413,7 @@ var PrismaD1Datasource = class extends AbstractDatasource {
|
|
|
1410
1413
|
}
|
|
1411
1414
|
async connect() {
|
|
1412
1415
|
this.logger.info("Connecting Prisma D1 datasource...");
|
|
1413
|
-
|
|
1414
|
-
if (!env?.DB) {
|
|
1416
|
+
if (!this.context.db) {
|
|
1415
1417
|
const error = 'D1 database binding not found. Add to wrangler.toml:\n[[d1_databases]]\nbinding = "DB"\ndatabase_name = "your-database-name"\ndatabase_id = "your-database-id"';
|
|
1416
1418
|
this.logger.error(error);
|
|
1417
1419
|
throw new Error(error);
|
|
@@ -1427,7 +1429,7 @@ var PrismaD1Datasource = class extends AbstractDatasource {
|
|
|
1427
1429
|
this.logger.debug("Creating new PrismaD1 adapter and client...");
|
|
1428
1430
|
const d1Module = await import("@prisma/adapter-d1");
|
|
1429
1431
|
const PrismaD1 = d1Module.PrismaD1 ?? d1Module.default;
|
|
1430
|
-
const adapter = new PrismaD1(
|
|
1432
|
+
const adapter = new PrismaD1(this.context.db);
|
|
1431
1433
|
this._client = this.createClient(adapter);
|
|
1432
1434
|
global.__prismaD1Clients.set(clientKey, this._client);
|
|
1433
1435
|
this.logger.debug(`Cached new Prisma client for ${clientKey}`);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/logger/index.ts","../src/cache/kv-cache.ts","../src/cache/batching-datasource.ts","../src/cache/apollo-cache-adapter.ts","../src/cache/index.ts","../src/context/constants.ts","../src/context/auth.ts","../src/env/config.ts","../src/context/index.ts","../src/utils/builder.util.ts","../src/server/server.builder.ts","../src/datasources/apollo-plugin.datasource.ts","../src/server/hono.configure.ts","../src/middleware/validation.ts","../src/middleware/rate-limit.ts","../src/middleware/tracing.ts","../src/middleware/health.ts","../src/utils/graphql.util.ts","../src/utils/tracing.util.ts","../src/logger/apollo.logger.ts","../src/server/plugin.configure.ts","../src/server/index.ts","../src/utils/error.util.ts","../src/utils/schema.util.ts","../src/datasources/base.datasource.ts","../src/datasources/rest.datasource.ts","../src/datasources/prisma.datasource.ts"],"sourcesContent":["import pino from 'pino/browser';\n\n// Configuration for Cloudflare Workers environment\nconst isDev = process.env.NODE_ENV !== 'production';\nconst logLevel = process.env.LOG_LEVEL || (isDev ? 'debug' : 'info');\n\n// Custom serializers for Cloudflare Workers\nconst serializers = {\n err: (err: any) => {\n if (!err) return err;\n return {\n type: err.constructor?.name || err.name,\n message: err.message,\n stack: err.stack,\n code: err.code,\n statusCode: err.statusCode,\n };\n },\n req: (req: Request) => {\n if (!req) return req;\n return {\n method: req.method,\n url: req.url,\n headers: Object.fromEntries(req.headers.entries()),\n };\n },\n res: (res: Response) => {\n if (!res) return res;\n return {\n statusCode: res.status,\n headers: Object.fromEntries(res.headers.entries()),\n };\n },\n};\n\n// Create pino logger optimized for Cloudflare Workers\nexport const logger = pino({\n browser: {\n asObject: true,\n write: {\n info: (o: any) => {\n // In production, send to external logging service\n if (!isDev && globalThis.logshipper) {\n globalThis.logshipper.log(o);\n }\n console.log(JSON.stringify(o));\n },\n error: (o: any) => {\n if (!isDev && globalThis.logshipper) {\n globalThis.logshipper.log(o);\n }\n console.error(JSON.stringify(o));\n },\n debug: (o: any) => {\n if (isDev) {\n console.debug(JSON.stringify(o));\n }\n },\n warn: (o: any) => {\n if (!isDev && globalThis.logshipper) {\n globalThis.logshipper.log(o);\n }\n console.warn(JSON.stringify(o));\n },\n fatal: (o: any) => {\n if (!isDev && globalThis.logshipper) {\n globalThis.logshipper.log(o);\n }\n console.error(JSON.stringify(o));\n },\n trace: (o: any) => {\n if (isDev) {\n console.trace(JSON.stringify(o));\n }\n },\n },\n },\n level: logLevel,\n base: {\n env: process.env.NODE_ENV,\n service: 'graphql-subgraph',\n runtime: 'cloudflare-workers',\n },\n serializers,\n timestamp: () => `,\"timestamp\":\"${new Date().toISOString()}\"`,\n formatters: {\n level: (label: string) => {\n return {level: label.toUpperCase()};\n },\n log: (object: any) => {\n // Add request context if available\n if (globalThis.requestContext) {\n object.traceId = globalThis.requestContext.traceId;\n object.spanId = globalThis.requestContext.spanId;\n object.userId = globalThis.requestContext.userId;\n }\n return object;\n },\n },\n});\n\n// Helper for creating child loggers with context\nexport function createLogger(context: Record<string, any>) {\n return logger.child(context);\n}\n\n// Export pino types for TypeScript\nexport type Logger = typeof logger;\n\n// Declare global types for Cloudflare Workers\ndeclare global {\n var logshipper: {\n log: (data: any) => void;\n };\n var requestContext: {\n traceId?: string;\n spanId?: string;\n userId?: string;\n };\n}\n","/**\n * KV Cache implementation for Cloudflare Workers\n * Provides caching capabilities for GraphQL resolvers using Cloudflare KV\n */\n\nexport interface CacheOptions {\n ttl?: number; // Time to live in seconds\n namespace?: string; // Cache namespace prefix\n cacheKey?: string; // Custom cache key\n}\n\nexport class KVCache {\n private defaultTTL: number = 300; // 5 minutes default\n private defaultNamespace: string = 'cache';\n\n constructor(\n private kv: KVNamespace,\n defaultNamespace?: string\n ) {\n if (defaultNamespace) {\n this.defaultNamespace = defaultNamespace;\n }\n }\n\n /**\n * Get a value from cache\n */\n async get<T = any>(key: string): Promise<T | null> {\n try {\n const value = await this.kv.get(key);\n if (!value) return null;\n\n // Try to parse JSON, fallback to raw value\n try {\n return JSON.parse(value);\n } catch {\n return value as T;\n }\n } catch (error) {\n console.error(`Cache get error for key ${key}:`, error);\n return null;\n }\n }\n\n /**\n * Set a value in cache with metadata\n */\n async set(\n key: string,\n value: any,\n options: CacheOptions = {}\n ): Promise<void> {\n try {\n const serialized =\n typeof value === 'string' ? value : JSON.stringify(value);\n\n const ttl = options.ttl || this.defaultTTL;\n const kvOptions: KVNamespacePutOptions = {\n expirationTtl: ttl,\n metadata: {\n createdAt: new Date().toISOString(),\n ttl: ttl,\n namespace: options.namespace || this.defaultNamespace,\n },\n };\n\n await this.kv.put(key, serialized, kvOptions);\n } catch (error) {\n console.error(`Cache set error for key ${key}:`, error);\n }\n }\n\n /**\n * Delete a value from cache\n */\n async delete(key: string): Promise<void> {\n try {\n await this.kv.delete(key);\n } catch (error) {\n console.error(`Cache delete error for key ${key}:`, error);\n }\n }\n\n /**\n * Check if a key exists in cache\n */\n async has(key: string): Promise<boolean> {\n try {\n const value = await this.kv.get(key);\n return value !== null;\n } catch (error) {\n console.error(`Cache has error for key ${key}:`, error);\n return false;\n }\n }\n\n /**\n * Clear multiple keys matching a prefix\n */\n async clearPrefix(prefix: string): Promise<number> {\n try {\n const list = await this.kv.list({prefix});\n const promises = list.keys.map((key) => this.kv.delete(key.name));\n await Promise.all(promises);\n return list.keys.length;\n } catch (error) {\n console.error(`Cache clear prefix error for ${prefix}:`, error);\n return 0;\n }\n }\n\n /**\n * Invalidate cache by pattern\n */\n async invalidate(pattern: string): Promise<number> {\n return this.clearPrefix(pattern);\n }\n\n /**\n * Clear all cache in a namespace\n */\n async clearNamespace(namespace?: string): Promise<number> {\n const prefix = namespace ? `${namespace}:` : `${this.defaultNamespace}:`;\n return this.invalidate(prefix);\n }\n\n /**\n * Get or set a value with a factory function\n * Useful for cache-aside pattern\n */\n async getOrSet<T>(\n key: string,\n factory: () => Promise<T>,\n options: CacheOptions = {}\n ): Promise<T> {\n // Try to get from cache first\n const cached = await this.get<T>(key);\n if (cached !== null) {\n return cached;\n }\n\n // Fetch fresh value\n const fresh = await factory();\n\n // Cache the fresh value (non-blocking)\n this.set(key, fresh, options).catch((error) => {\n console.error(`Background cache write error for ${key}:`, error);\n });\n\n return fresh;\n }\n\n /**\n * Memoize function with automatic key generation\n */\n async memoize<T>(\n cacheKey: string,\n params: any,\n fetchFn: () => Promise<T>,\n options: CacheOptions = {}\n ): Promise<T> {\n const namespace = options.namespace || this.defaultNamespace;\n const key = this.generateKey(`${namespace}:${cacheKey}`, params);\n\n try {\n // Try to get from cache\n const cached = await this.get<T>(key);\n if (cached !== null) {\n return cached;\n }\n } catch (error) {\n console.warn(`Cache read error for ${key}:`, error);\n }\n\n // Cache miss - fetch data\n const data = await fetchFn();\n\n // Store in cache (non-blocking)\n this.set(key, data, options).catch((error) => {\n console.warn(`Cache write error for ${key}:`, error);\n });\n\n return data;\n }\n\n /**\n * Generate cache key with namespace and params\n */\n private generateKey(namespace: string, params: any): string {\n const sortedParams = Object.keys(params)\n .sort()\n .reduce((obj: any, key) => {\n if (params[key] !== undefined && params[key] !== null) {\n obj[key] = params[key];\n }\n return obj;\n }, {});\n\n const paramString = JSON.stringify(sortedParams);\n const hash = this.simpleHash(paramString);\n return `${namespace}:${hash}`;\n }\n\n /**\n * Simple hash function for generating cache keys\n */\n private simpleHash(str: string): string {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n const char = str.charCodeAt(i);\n hash = (hash << 5) - hash + char;\n hash = hash & hash; // Convert to 32bit integer\n }\n return Math.abs(hash).toString(36);\n }\n}\n\n/**\n * Create a cache key from multiple parts\n */\nexport function createCacheKey(\n ...parts: (string | number | undefined)[]\n): string {\n return parts\n .filter((part) => part !== undefined)\n .map((part) => String(part))\n .join(':');\n}\n\n/**\n * Cache key patterns for different data types\n */\nexport const CacheKeys = {\n user: (id: string) => createCacheKey('user', id),\n query: (name: string, variables?: string) =>\n createCacheKey('query', name, variables),\n list: (type: string, page?: number) => createCacheKey('list', type, page),\n permission: (userId: string, resource: string) =>\n createCacheKey('perm', userId, resource),\n} as const;\n","import DataLoader, {type BatchLoadFn, type Options} from 'dataloader';\nimport type {BaseContext} from '@/context';\nimport {KVCache} from './kv-cache';\n\n/**\n * Ensures that output items has the same order as input keys (dataloader requirement).\n * Returns error objects for non-existent ids.\n *\n * @param keys list of input keys\n * @param items list of output items\n * @param primaryKey name of the key-holding property\n */\nexport function ensureBatchOrder<\n K extends string | number,\n T extends Record<string, any>,\n>(keys: readonly K[], items: T[], primaryKey = 'id'): Array<T | Error> {\n const itemsMap = new Map<K, T>();\n\n // Build a map for O(1) lookups\n for (const item of items) {\n const key = item[primaryKey] as K;\n if (key !== undefined) {\n itemsMap.set(key, item);\n }\n }\n\n // Return items in the same order as keys\n return keys.map(\n (key) =>\n itemsMap.get(key) || new Error(`Missing value for ${primaryKey} ${key}`)\n );\n}\n\n/**\n * Ensures that output items has the same order as input keys (dataloader requirement).\n * Returns null for non-existent ids.\n *\n * @param keys list of input keys\n * @param items list of output items\n * @param primaryKey name of the key-holding property\n */\nexport function ensureBatchOrderNullable<\n K extends string | number,\n T extends Record<string, any>,\n>(keys: readonly K[], items: T[], primaryKey = 'id'): Array<T | null> {\n const itemsMap = new Map<K, T>();\n\n // Build a map for O(1) lookups\n for (const item of items) {\n const key = item[primaryKey] as K;\n if (key !== undefined) {\n itemsMap.set(key, item);\n }\n }\n\n // Return items in the same order as keys, with nulls for missing\n return keys.map((key) => itemsMap.get(key) || null);\n}\n\n/**\n * Base class for batching data sources with caching support.\n * Uses DataLoader for request batching and deduplication.\n *\n * @typeParam TContext - Apollo context type\n * @typeParam K - Primary key type\n * @typeParam V - Output item type\n * @typeParam CK - Cache key type (same as K by default)\n *\n * @example\n * ```typescript\n * export class UserBatchingDataSource extends BatchingDataSource<BaseContext, string, User> {\n * constructor() {\n * super(async (ids: readonly string[]) => {\n * const users = await fetchUsersFromDB(ids);\n * return ensureBatchOrder(ids, users);\n * });\n * }\n * }\n * ```\n */\nexport class BatchingDataSource<TContext extends BaseContext, K, V, CK = K> {\n protected context!: TContext;\n protected loader: DataLoader<K, V, CK>;\n protected cache?: KVCache;\n\n /**\n * Creates a new batching data source\n *\n * @param resolveBatch - Batch resolving function\n * @param options - DataLoader options\n * @param cacheNamespace - Optional namespace for KV caching\n */\n constructor(\n resolveBatch: BatchLoadFn<K, V>,\n options: Options<K, V, CK> = {},\n protected cacheNamespace?: string\n ) {\n // Bind context to the batch function\n const boundResolveBatch: BatchLoadFn<K, V> = async (keys) => {\n // If we have cache, try to load from cache first\n if (this.cache && this.cacheNamespace) {\n const results: Array<V | undefined> = [];\n const uncachedKeys: K[] = [];\n const uncachedIndexes: number[] = [];\n\n // Check cache for each key\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const cacheKey = `${this.cacheNamespace}:${String(key)}`;\n const cached = await this.cache.get<V>(cacheKey);\n\n if (cached !== null) {\n results[i] = cached;\n } else {\n uncachedKeys.push(key);\n uncachedIndexes.push(i);\n }\n }\n\n // If all items were cached, return them\n if (uncachedKeys.length === 0) {\n return results as V[];\n }\n\n // Fetch uncached items\n const freshItems = await resolveBatch.call(this, uncachedKeys);\n\n // Merge fresh items back and cache them\n for (let i = 0; i < uncachedIndexes.length; i++) {\n const index = uncachedIndexes[i];\n const item = freshItems[i] as V;\n const key = uncachedKeys[i];\n\n results[index] = item;\n\n // Cache the fresh item (non-blocking)\n if (!(item instanceof Error) && item !== null && item !== undefined) {\n const cacheKey = `${this.cacheNamespace}:${String(key)}`;\n this.cache.set(cacheKey, item, {ttl: 300}).catch((err) => {\n console.warn(`Failed to cache item ${cacheKey}:`, err);\n });\n }\n }\n\n return results as V[];\n }\n\n // No cache, just resolve normally\n return resolveBatch.call(this, keys);\n };\n\n this.loader = new DataLoader(boundResolveBatch, {\n ...options,\n // Default to caching within the request\n cache: options.cache !== false,\n });\n }\n\n /**\n * Initialize with Apollo context\n */\n initialize(config: {contextValue: TContext}) {\n this.context = config.contextValue;\n this.cache = config.contextValue.cache;\n }\n\n /**\n * Load a single item by key\n */\n async load(id: K): Promise<V> {\n return this.loader.load(id);\n }\n\n /**\n * Load multiple items by keys\n */\n async loadMany(ids: readonly K[]): Promise<Array<V | Error>> {\n return this.loader.loadMany(ids);\n }\n\n /**\n * Clear a single item from the DataLoader cache\n */\n clear(id: K): this {\n this.loader.clear(id);\n return this;\n }\n\n /**\n * Clear all items from the DataLoader cache\n */\n clearAll(): this {\n this.loader.clearAll();\n return this;\n }\n\n /**\n * Prime the cache with a specific value\n */\n prime(key: K, value: V): this {\n this.loader.prime(key, value);\n return this;\n }\n}\n\n/**\n * Factory function for creating batching data sources\n *\n * @example\n * ```typescript\n * const userDataSource = createBatchingDataSource<BaseContext, string, User>(\n * async (ids) => {\n * const users = await fetchUsersFromDB(ids);\n * return ensureBatchOrder(ids, users);\n * },\n * { cache: true },\n * 'users'\n * );\n * ```\n */\nexport function createBatchingDataSource<\n TContext extends BaseContext,\n K,\n V,\n CK = K,\n>(\n resolveBatch: BatchLoadFn<K, V>,\n options?: Options<K, V, CK>,\n cacheNamespace?: string\n): BatchingDataSource<TContext, K, V, CK> {\n return new BatchingDataSource(resolveBatch, options, cacheNamespace);\n}\n","/**\n * Apollo KeyValueCache adapter for Cloudflare KV\n *\n * Implements the Apollo Server KeyValueCache interface to work with\n * Cloudflare Workers KV storage.\n */\n\nimport type {\n KeyValueCache,\n KeyValueCacheSetOptions,\n} from '@apollo/utils.keyvaluecache';\nimport {KVCache} from './kv-cache';\n\n/**\n * Adapter that makes our KVCache compatible with Apollo's KeyValueCache interface\n *\n * Apollo Server uses this for:\n * - Response caching\n * - APQ (Automatic Persisted Queries)\n * - DataSource caching\n *\n * @example\n * ```typescript\n * const apolloCache = new ApolloKVAdapter(new KVCache(env.KV));\n *\n * const server = new ApolloServer({\n * cache: apolloCache,\n * // ... other options\n * });\n * ```\n */\nexport class ApolloKVAdapter implements KeyValueCache<string> {\n constructor(private kvCache: KVCache) {}\n\n /**\n * Get a value from cache\n * Apollo expects undefined for cache misses\n */\n async get(key: string): Promise<string | undefined> {\n const value = await this.kvCache.get<string>(key);\n // Apollo expects undefined, not null for cache misses\n return value === null ? undefined : value;\n }\n\n /**\n * Set a value in cache with TTL support\n * Apollo passes TTL in seconds via options\n */\n async set(\n key: string,\n value: string,\n options?: KeyValueCacheSetOptions\n ): Promise<void> {\n await this.kvCache.set(key, value, {\n ttl: options?.ttl, // Apollo's TTL is already in seconds\n });\n }\n\n /**\n * Delete a value from cache\n * Apollo expects boolean or void return\n */\n async delete(key: string): Promise<boolean | void> {\n await this.kvCache.delete(key);\n return true;\n }\n}\n\n/**\n * Factory function to create an Apollo-compatible cache from KV namespace\n *\n * @param kv - Cloudflare KV namespace binding\n * @returns Apollo-compatible KeyValueCache\n */\nexport function createApolloCache(kv: KVNamespace): KeyValueCache<string> {\n return new ApolloKVAdapter(new KVCache(kv));\n}\n\n/**\n * In-memory LRU cache for development/testing\n * Falls back to simple Map-based implementation\n */\nexport class InMemoryCache implements KeyValueCache<string> {\n private cache = new Map<string, {value: string; expires?: number}>();\n\n async get(key: string): Promise<string | undefined> {\n const item = this.cache.get(key);\n if (!item) return undefined;\n\n // Check expiration\n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return undefined;\n }\n\n return item.value;\n }\n\n async set(\n key: string,\n value: string,\n options?: KeyValueCacheSetOptions\n ): Promise<void> {\n const expires = options?.ttl\n ? Date.now() + options.ttl * 1000 // Convert seconds to milliseconds\n : undefined;\n\n this.cache.set(key, {value, expires});\n }\n\n async delete(key: string): Promise<boolean> {\n return this.cache.delete(key);\n }\n\n /**\n * Clear all cache entries\n */\n clear(): void {\n this.cache.clear();\n }\n}\n","/**\n * Cache module for GraphQL resolvers\n * Provides caching interface for Cloudflare Workers KV\n */\n\nimport {KVCache, createCacheKey, CacheKeys} from './kv-cache';\nimport type {CacheOptions} from './kv-cache';\nimport {\n BatchingDataSource,\n createBatchingDataSource,\n ensureBatchOrder,\n ensureBatchOrderNullable,\n} from './batching-datasource';\nimport {\n ApolloKVAdapter,\n createApolloCache,\n InMemoryCache,\n} from './apollo-cache-adapter';\n\nexport {KVCache, createCacheKey, CacheKeys};\nexport type {CacheOptions};\nexport {\n BatchingDataSource,\n createBatchingDataSource,\n ensureBatchOrder,\n ensureBatchOrderNullable,\n};\nexport {ApolloKVAdapter, createApolloCache, InMemoryCache};\n\n/**\n * Cache factory - creates KV cache if available\n */\nexport function createCache(env: Env): KVCache | null {\n // Check for KV namespace (Cloudflare Workers KV)\n if (env.KV) {\n return new KVCache(env.KV);\n }\n\n // No cache available\n return null;\n}\n\n/**\n * Decorator for caching resolver results\n */\nexport function cached(\n options: CacheOptions & {keyGenerator?: (...args: any[]) => string} = {}\n) {\n return function (\n target: any,\n propertyKey: string,\n descriptor: PropertyDescriptor\n ) {\n const originalMethod = descriptor.value;\n\n descriptor.value = async function (...args: any[]) {\n const context = args[2]; // GraphQL context is third argument\n const cache = context?.cache;\n\n if (!cache) {\n // No cache available, run original method\n return originalMethod.apply(this, args);\n }\n\n // Generate cache key\n const key = options.keyGenerator\n ? options.keyGenerator(...args)\n : createCacheKey(propertyKey, JSON.stringify(args[1])); // Use field name and arguments\n\n // Try cache-aside pattern\n return cache.getOrSet(\n key,\n () => originalMethod.apply(this, args),\n options\n );\n };\n\n return descriptor;\n };\n}\n\n/**\n * GraphQL DataLoader integration for batching and caching\n */\nexport class CachedDataLoader<K, V> {\n private loader: any; // DataLoader instance\n private cache: KVCache;\n\n constructor(\n batchFn: (keys: K[]) => Promise<V[]>,\n cache: KVCache,\n private options: CacheOptions = {}\n ) {\n this.cache = cache;\n\n // Initialize DataLoader with cache\n // Note: DataLoader is not included by default, install if needed\n // this.loader = new DataLoader(batchFn, { cache: this.createCacheMap() });\n }\n\n async load(key: K): Promise<V> {\n const cacheKey = createCacheKey('loader', String(key));\n\n return this.cache.getOrSet(\n cacheKey,\n async () => {\n // Fallback to batch function for single key\n // In production, use actual DataLoader\n return this.loader ? this.loader.load(key) : null;\n },\n this.options\n );\n }\n\n async loadMany(keys: K[]): Promise<V[]> {\n return Promise.all(keys.map((key) => this.load(key)));\n }\n\n async clear(key: K): Promise<void> {\n const cacheKey = createCacheKey('loader', String(key));\n await this.cache.delete(cacheKey);\n }\n\n async clearAll(): Promise<void> {\n await this.cache.clearPrefix('loader:');\n }\n}\n","export const Headers = {\n GATEWAY_USER: 'x-gateway-user',\n GATEWAY_USER_SIGNATURE: 'x-gateway-user-signature',\n AUTH: 'authorization',\n CLIENT_ID: 'x-client-id',\n} as const;\n","import type {ContextUser} from './types';\n\n/**\n * Verifies and parses user context from gateway headers\n * For Cloudflare Workers deployment, we use HMAC signature verification\n * to ensure the user data hasn't been tampered with\n */\nexport async function verifyAndParseUser(\n encodedUser: string | null,\n signature: string | null,\n secret: string\n): Promise<ContextUser | undefined> {\n if (!encodedUser || !signature) {\n return undefined;\n }\n\n try {\n // Verify HMAC signature\n const encoder = new TextEncoder();\n const key = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n {name: 'HMAC', hash: 'SHA-256'},\n false,\n ['verify']\n );\n\n const signatureBuffer = hexToBuffer(signature);\n const dataBuffer = encoder.encode(encodedUser);\n\n const isValid = await crypto.subtle.verify(\n 'HMAC',\n key,\n signatureBuffer,\n dataBuffer\n );\n\n if (!isValid) {\n console.error('Invalid user signature');\n return undefined;\n }\n\n // Parse the verified user data\n const user = JSON.parse(atob(encodedUser));\n return user;\n } catch (error) {\n console.error('Error verifying user:', error);\n return undefined;\n }\n}\n\nfunction hexToBuffer(hex: string): ArrayBuffer {\n const bytes = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);\n }\n // Return the ArrayBuffer directly, not SharedArrayBuffer\n return bytes.buffer as ArrayBuffer;\n}\n","/**\n * Environment configuration type\n */\nexport interface EnvConfig {\n // Core\n NODE_ENV: 'development' | 'test' | 'production';\n PORT: number;\n\n // Security\n GATEWAY_SECRET?: string;\n ALLOWED_ORIGINS: string[];\n\n // Logging\n LOG_LEVEL: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';\n\n // Rate limiting\n RATE_LIMIT_WINDOW_MS: number;\n RATE_LIMIT_MAX: number;\n\n // Monitoring\n ENABLE_METRICS: boolean;\n ENABLE_TRACING: boolean;\n\n // GraphQL\n MAX_QUERY_DEPTH: number;\n MAX_QUERY_COMPLEXITY: number;\n INTROSPECTION_ENABLED: boolean;\n\n // External services (optional)\n LOG_SERVICE_URL?: string;\n LOG_SERVICE_TOKEN?: string;\n}\n\n/**\n * Lightweight environment parser inspired by @ltv/env\n */\nclass EnvParser {\n constructor(private env: Record<string, any>) {}\n\n string(key: string): string | undefined;\n string(key: string, defaultValue: string): string;\n string(key: string, defaultValue?: string): string | undefined {\n const value = this.env[key];\n return value !== undefined && value !== '' ? String(value) : defaultValue;\n }\n\n int(key: string): number | undefined;\n int(key: string, defaultValue: number): number;\n int(key: string, defaultValue?: number): number | undefined {\n const value = this.env[key];\n if (value === undefined || value === '') return defaultValue;\n const parsed = parseInt(String(value), 10);\n return isNaN(parsed) ? defaultValue : parsed;\n }\n\n bool(key: string): boolean | undefined;\n bool(key: string, defaultValue: boolean): boolean;\n bool(key: string, defaultValue?: boolean): boolean | undefined {\n const value = this.env[key];\n if (value === undefined || value === '') return defaultValue;\n const str = String(value).toLowerCase();\n return str === 'true' || str === '1';\n }\n\n array(key: string): string[] | undefined;\n array(key: string, defaultValue: string[]): string[];\n array(key: string, defaultValue?: string[]): string[] | undefined {\n const value = this.env[key];\n if (value === undefined || value === '') return defaultValue;\n if (Array.isArray(value)) return value;\n return String(value)\n .split(',')\n .map((s) => s.trim())\n .filter(Boolean);\n }\n\n enum<T extends string>(key: string, validValues: T[]): T | undefined;\n enum<T extends string>(key: string, validValues: T[], defaultValue: T): T;\n enum<T extends string>(\n key: string,\n validValues: T[],\n defaultValue?: T\n ): T | undefined {\n const value = this.string(key);\n if (value && validValues.includes(value as T)) {\n return value as T;\n }\n return defaultValue;\n }\n}\n\n/**\n * Environment loader for Cloudflare Workers\n */\nexport class EnvironmentLoader {\n private config: EnvConfig | null = null;\n\n /**\n * Load environment from Cloudflare Workers env object\n */\n load(env: Record<string, any>): EnvConfig {\n const parser = new EnvParser(env);\n\n this.config = {\n NODE_ENV: parser.enum(\n 'NODE_ENV',\n ['development', 'test', 'production'],\n 'production'\n ),\n PORT: parser.int('PORT', 3344),\n GATEWAY_SECRET: parser.string('GATEWAY_SECRET'),\n ALLOWED_ORIGINS: parser.array('ALLOWED_ORIGINS', [\n 'http://localhost:3000',\n ]),\n LOG_LEVEL: parser.enum(\n 'LOG_LEVEL',\n ['trace', 'debug', 'info', 'warn', 'error', 'fatal'],\n 'info'\n ),\n RATE_LIMIT_WINDOW_MS: parser.int('RATE_LIMIT_WINDOW_MS', 60000),\n RATE_LIMIT_MAX: parser.int('RATE_LIMIT_MAX', 100),\n ENABLE_METRICS: parser.bool('ENABLE_METRICS', true),\n ENABLE_TRACING: parser.bool('ENABLE_TRACING', true),\n MAX_QUERY_DEPTH: parser.int('MAX_QUERY_DEPTH', 10),\n MAX_QUERY_COMPLEXITY: parser.int('MAX_QUERY_COMPLEXITY', 1000),\n INTROSPECTION_ENABLED: parser.bool('INTROSPECTION_ENABLED', false),\n LOG_SERVICE_URL: parser.string('LOG_SERVICE_URL'),\n LOG_SERVICE_TOKEN: parser.string('LOG_SERVICE_TOKEN'),\n };\n\n return this.config;\n }\n\n /**\n * Get current configuration\n */\n getConfig(): EnvConfig {\n if (!this.config) {\n throw new Error('Environment not loaded. Call load() first.');\n }\n return this.config;\n }\n\n /**\n * Helper getters for common checks\n */\n get isDev(): boolean {\n return this.config?.NODE_ENV === 'development';\n }\n\n get isTest(): boolean {\n return this.config?.NODE_ENV === 'test';\n }\n\n get isProd(): boolean {\n return this.config?.NODE_ENV === 'production';\n }\n}\n\n// Singleton instance\nexport const envLoader = new EnvironmentLoader();\n","import type {BaseContext as ApolloBaseContext} from '@apollo/server';\nimport type {ExecutionContext} from '@cloudflare/workers-types';\nimport type {CloudflareContextFunctionArgument} from '@as-integrations/cloudflare-workers';\nimport {logger} from '../logger';\nimport {Headers} from './constants';\nimport {verifyAndParseUser} from './auth';\nimport type {ContextUser} from './types';\nimport {createCache} from '@/cache';\nimport type {KVCache} from '@/cache';\nimport {envLoader, type EnvConfig} from '@/env';\n\nexport type {ContextUser} from './types';\n\n// TODO: Replace with actual jaeger types when available\nexport interface JaegerContext {\n rootSpan?: {\n getBaggageItem: (key: string) => string | undefined;\n };\n}\n\nexport interface BaseContext extends JaegerContext, ApolloBaseContext {\n user?: ContextUser;\n logger: typeof logger;\n executionCtx: ExecutionContext;\n cache?: KVCache; // KV cache for resolvers\n env: EnvConfig; // Validated environment configuration\n\n /** @deprecated should not be used directly */\n authorization: string;\n clientId: string;\n}\n\nexport type ContextExtendFunction<T extends BaseContext> = (\n ctx: BaseContext,\n honoContext: CloudflareContextFunctionArgument<unknown>\n) => T | Promise<T>;\n\nasync function createBaseContext(\n honoContext: CloudflareContextFunctionArgument<any>\n): Promise<BaseContext> {\n const request = honoContext.request;\n const rawEnv = honoContext.env;\n\n // Load and validate environment configuration\n const env = envLoader.load(rawEnv);\n\n // Parse user from gateway headers with signature verification\n let user: ContextUser | undefined;\n\n // Check if this is a subgraph request from gateway\n const encodedUser = request.headers.get(Headers.GATEWAY_USER);\n if (encodedUser) {\n // In production, verify signature. In dev, allow without signature\n if (env.GATEWAY_SECRET) {\n const signature = request.headers.get(Headers.GATEWAY_USER_SIGNATURE);\n user = await verifyAndParseUser(\n encodedUser,\n signature,\n env.GATEWAY_SECRET\n );\n } else if (env.NODE_ENV !== 'production') {\n // Development mode: parse without verification\n try {\n user = JSON.parse(atob(encodedUser));\n } catch (e) {\n console.error('Failed to parse user in dev mode:', e);\n }\n }\n }\n\n // Create cache instance - KV is now required\n // Pass raw env for KV bindings, not the parsed config\n const cache = createCache(rawEnv) as KVCache | undefined;\n if (!cache) {\n // This should not happen as ServerBuilder validates KV exists\n logger.warn(\n 'KV cache not found in context - this should not happen if using ServerBuilder'\n );\n }\n\n return {\n user,\n logger,\n cache,\n env, // Pass validated env config\n executionCtx: honoContext.ctx,\n authorization: request.headers.get(Headers.AUTH) || '',\n clientId: request.headers.get(Headers.CLIENT_ID) || '',\n };\n}\n\nexport function createContextFunction<T extends BaseContext>(\n extendContext?: ContextExtendFunction<T>\n) {\n if (!extendContext) {\n return (honoContext: CloudflareContextFunctionArgument<unknown>) =>\n createBaseContext(honoContext);\n }\n\n return async (honoContext: CloudflareContextFunctionArgument<unknown>) => {\n const baseContext = await createBaseContext(honoContext);\n return extendContext(baseContext, honoContext);\n };\n}\n","export function assertDefined<T>(t: T | undefined, msg: string): t is T {\n if (t === undefined) {\n throw new Error('Assertion failed when configuring server: ' + msg);\n }\n return true;\n}\n","import {createApolloCache} from '@/cache';\nimport {\n createContextFunction,\n type BaseContext,\n type ContextExtendFunction,\n} from '@/context';\nimport {assertDefined} from '@/utils/builder.util';\nimport type {ApolloServerOptions, ApolloServerPlugin} from '@apollo/server';\nimport {ApolloServer} from '@apollo/server';\nimport {startServerAndCreateCloudflareWorkersHandler} from '@as-integrations/cloudflare-workers';\nimport type {GraphQLSchema} from 'graphql';\nimport type {Hono} from 'hono';\nimport {ApolloDataSources} from '../datasources/apollo-plugin.datasource';\nimport {configureHono} from './hono.configure';\nimport {configurePlugins} from './plugin.configure';\n\nexport type Runner = {\n fetch: typeof Hono.prototype.fetch;\n port?: number;\n};\n\nimport type {KVCache} from '@/cache';\n\nexport type ServerConfig<TDatasource, TContext extends BaseContext> = {\n path?: string;\n apollo: Partial<ApolloServerOptions<BaseContext>>;\n datasources: (cache: KVCache, context: TContext) => TDatasource;\n extendContext?: ContextExtendFunction<TContext>;\n};\n\nexport class ServerBuilder<TDatasource, TContext extends BaseContext> {\n readonly app: Hono<{\n Variables: {\n env: any;\n };\n }>;\n\n readonly schema: GraphQLSchema;\n readonly plugins: ApolloServerPlugin<BaseContext>[] = [];\n\n constructor(readonly config: ServerConfig<TDatasource, TContext>) {\n this.assert();\n\n // TODO: Configure metrics\n this.app = configureHono(this);\n this.schema = this.config.apollo.schema as GraphQLSchema;\n }\n\n configure(): Runner {\n const honoApp = this.app;\n configurePlugins(this);\n\n // Build plugins array with datasources\n const plugins: ApolloServerPlugin<TContext>[] = [...this.plugins];\n\n // Add datasources plugin (now required)\n plugins.push(\n ApolloDataSources({\n datasources: this.config.datasources as any,\n }) as any\n );\n\n // We need to create the Apollo server for each request to pass the correct cache\n const createHandler = (env: any) => {\n // Validate KV binding exists\n if (!env?.KV) {\n throw new Error(\n 'Missing required KV namespace binding. ' +\n 'Please add KV namespace binding in your wrangler.toml:\\n' +\n '[[kv_namespaces]]\\n' +\n 'binding = \"KV\"\\n' +\n 'id = \"your-kv-namespace-id\"'\n );\n }\n\n // Create Apollo cache from KV\n const apolloCache = createApolloCache(env.KV);\n\n // Create Apollo server with cache\n // We need to ensure we don't include gateway if schema is provided\n const {gateway, ...apolloConfigWithoutGateway} = this.config.apollo || {};\n\n const server = new ApolloServer<TContext>({\n ...apolloConfigWithoutGateway, // User config without gateway\n schema: this.schema, // Our schema\n plugins, // Our plugins\n cache: apolloCache, // Apollo cache for APQ and response caching (override any user cache)\n } as ApolloServerOptions<TContext>);\n\n return startServerAndCreateCloudflareWorkersHandler<any, any>(server, {\n context: async (c) =>\n createContextFunction(this.config.extendContext)(c),\n });\n };\n\n // Cache handlers per environment (for efficiency)\n const handlerCache = new WeakMap();\n\n const getOrCreateHandler = (env: any) => {\n if (!handlerCache.has(env)) {\n handlerCache.set(env, createHandler(env));\n }\n return handlerCache.get(env);\n };\n\n honoApp.all(this.config.path ?? '/', async (c) => {\n // Get or create handler for this environment\n const cfHandler = getOrCreateHandler(c.env);\n\n // In local development, executionCtx doesn't exist\n // In Cloudflare Workers, it's provided\n let executionCtx;\n try {\n executionCtx = c.executionCtx;\n } catch (e) {\n // Create a mock executionCtx for local development\n executionCtx = {\n waitUntil: (promise: Promise<any>) => promise,\n passThroughOnException: () => {},\n };\n }\n return cfHandler(c.req.raw, c.env, executionCtx);\n });\n\n return {\n async fetch(request, env, ctx) {\n return honoApp.fetch(request, env, ctx);\n },\n };\n }\n\n assert() {\n assertDefined(\n this.config.apollo.schema,\n 'Apollo server config must have a schema'\n );\n }\n}\n","import type {ApolloServerPlugin} from '@apollo/server';\nimport type {BaseContext} from '../context';\nimport type {ServerConfig} from '../server/server.builder';\nimport type {KVCache} from '../cache';\n\ntype DataSources = Record<string, any>;\ntype DataSourcesFn = <TContext extends BaseContext = BaseContext>(\n cache: KVCache,\n contextValue: TContext\n) => DataSources;\n\nexport type ComputedContext<\n TDatasource,\n TContext extends BaseContext,\n> = TContext & {\n datasources: ReturnType<\n NonNullable<ServerConfig<TDatasource, TContext>['datasources']>\n >;\n};\n\nexport const ApolloDataSources = <\n TDatasource,\n TContext extends BaseContext,\n>(options: {\n datasources: DataSourcesFn;\n}): ApolloServerPlugin<ComputedContext<TDatasource, TContext>> => ({\n requestDidStart: async (requestContext) => {\n // Get KVCache from context instead of Apollo's cache\n const kvCache = requestContext.contextValue.cache;\n if (!kvCache) {\n throw new Error(\n 'KVCache not found in context. This should not happen if using ServerBuilder.'\n );\n }\n\n const dataSources = options.datasources(\n kvCache,\n requestContext.contextValue\n );\n\n // Auto-connect datasources that have connect method\n const connectPromises = Object.values(dataSources).map(\n async (dataSource) => {\n if (dataSource && typeof dataSource.connect === 'function') {\n await dataSource.connect();\n }\n }\n );\n\n await Promise.all(connectPromises);\n\n requestContext.contextValue.datasources =\n dataSources as unknown as TDatasource;\n },\n});\n","import {BaseContext} from '@/context';\nimport {Hono} from 'hono';\nimport {cors} from 'hono/cors';\nimport {compress} from 'hono/compress';\nimport {ServerBuilder} from './server.builder';\nimport {createValidationMiddleware} from '@/middleware/validation';\nimport {createRateLimitMiddleware} from '@/middleware/rate-limit';\nimport {createTracingMiddleware} from '@/middleware/tracing';\nimport {configureHealthChecks} from '@/middleware/health';\n\nexport function configureHono<TContext extends BaseContext>(\n builder: ServerBuilder<unknown, TContext>\n) {\n const app = new Hono<{\n Variables: {\n env: any;\n };\n }>();\n\n // Add environment to context for all middleware\n app.use('*', async (c, next) => {\n // Get environment from Cloudflare or set default\n const rawEnv = c.env || {};\n const env = rawEnv as any; // Type assertion for environment variables\n c.set('env', env);\n await next();\n });\n\n // Add request tracing first for all requests\n app.use('*', createTracingMiddleware());\n\n // Add compression for responses\n app.use('*', compress());\n\n // Add validation middleware\n app.use('*', createValidationMiddleware());\n\n // Add rate limiting\n app.use('*', createRateLimitMiddleware());\n\n // Configure health checks\n configureHealthChecks(app, {\n checks: {\n graphql: async () => true, // Check GraphQL schema is loaded\n },\n });\n\n // Configure CORS for development and production\n app.use(\n '/*',\n cors({\n origin: (origin, c) => {\n // Get environment from context\n const env = c.get('env') as any;\n const isProd = env?.NODE_ENV === 'production';\n const allowedOrigins = env.ALLOWED_ORIGINS\n ? typeof env.ALLOWED_ORIGINS === 'string'\n ? env.ALLOWED_ORIGINS.split(',').map((s) => s.trim())\n : env.ALLOWED_ORIGINS\n : ['http://localhost:3000'];\n\n // Allow all origins in development\n if (!isProd) {\n return origin || '*';\n }\n // In production, configure allowed origins\n return allowedOrigins.includes(origin) ? origin : allowedOrigins[0];\n },\n allowHeaders: [\n 'Content-Type',\n 'Authorization',\n 'x-apollo-operation-name',\n 'apollo-require-preflight',\n ],\n allowMethods: ['POST', 'GET', 'OPTIONS'],\n credentials: true,\n maxAge: 86400,\n })\n );\n\n // Add security headers\n app.use('*', async (c, next) => {\n await next();\n\n const env = c.get('env') as any;\n const isProd = env?.NODE_ENV === 'production';\n\n // Security headers for GraphQL endpoints\n c.header('X-Content-Type-Options', 'nosniff');\n c.header('X-Frame-Options', 'DENY');\n c.header('X-XSS-Protection', '1; mode=block');\n c.header('Referrer-Policy', 'strict-origin-when-cross-origin');\n\n // Remove server identification\n c.header('Server', 'GraphQL');\n\n // Content Security Policy for GraphQL\n if (isProd) {\n c.header(\n 'Content-Security-Policy',\n \"default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';\"\n );\n // HSTS for production\n c.header(\n 'Strict-Transport-Security',\n 'max-age=31536000; includeSubDomains; preload'\n );\n }\n });\n\n return app;\n}\n","import type {MiddlewareHandler} from 'hono';\nimport {AppError, ErrorCode} from '@/utils/error.util';\n\ninterface ValidationOptions {\n maxQueryDepth?: number;\n maxQueryComplexity?: number;\n maxAliasCount?: number;\n}\n\nexport function createValidationMiddleware(\n options: ValidationOptions = {}\n): MiddlewareHandler {\n return async (c, next) => {\n try {\n // Get environment from context\n const env = c.get('env');\n const maxQueryDepth = options.maxQueryDepth || env?.MAX_QUERY_DEPTH || 10;\n const maxQueryComplexity =\n options.maxQueryComplexity || env?.MAX_QUERY_COMPLEXITY || 1000;\n const maxAliasCount = options.maxAliasCount || 15;\n // Validate content type for GraphQL\n const contentType = c.req.header('content-type');\n if (\n c.req.method === 'POST' &&\n !contentType?.includes('application/json')\n ) {\n return c.json(\n {\n errors: [\n {\n message: 'Content-Type must be application/json',\n extensions: {code: 'BAD_REQUEST'},\n },\n ],\n },\n 400\n );\n }\n\n // Rate limiting headers check\n const clientId = c.req.header('x-client-id');\n if (!clientId && env?.NODE_ENV === 'production') {\n return c.json(\n {\n errors: [\n {\n message: 'Client identification required',\n extensions: {code: 'BAD_REQUEST'},\n },\n ],\n },\n 400\n );\n }\n\n await next();\n } catch (error) {\n console.error('Validation middleware error:', error);\n return c.json(\n {\n errors: [\n {\n message: 'Request validation failed',\n extensions: {code: 'INTERNAL_SERVER_ERROR'},\n },\n ],\n },\n 500\n );\n }\n };\n}\n","import type {MiddlewareHandler} from 'hono';\n\ninterface RateLimitOptions {\n windowMs?: number;\n max?: number;\n keyGenerator?: (c: any) => string;\n}\n\nexport function createRateLimitMiddleware(\n options: RateLimitOptions = {}\n): MiddlewareHandler {\n const {\n keyGenerator = (c) =>\n c.req.header('x-client-id') ||\n c.req.header('cf-connecting-ip') ||\n 'anonymous',\n } = options;\n\n return async (c, next) => {\n // Get environment from context\n const env = c.get('env');\n const windowMs = options.windowMs || env?.RATE_LIMIT_WINDOW_MS || 60 * 1000;\n const max = options.max || env?.RATE_LIMIT_MAX || 100;\n\n const key = keyGenerator(c);\n const rateLimitKey = `rate_limit:${key}`;\n\n // In Cloudflare Workers, use KV or Durable Objects for rate limiting\n // This is a simplified example\n if (c.env?.RATE_LIMIT_KV) {\n const current = await c.env.RATE_LIMIT_KV.get(rateLimitKey);\n const count = current ? parseInt(current, 10) : 0;\n\n if (count >= max) {\n return c.json(\n {\n errors: [\n {\n message: 'Too many requests',\n extensions: {\n code: 'RATE_LIMITED',\n retryAfter: windowMs / 1000,\n },\n },\n ],\n },\n 429,\n {\n 'Retry-After': String(windowMs / 1000),\n 'X-RateLimit-Limit': String(max),\n 'X-RateLimit-Remaining': '0',\n 'X-RateLimit-Reset': String(Date.now() + windowMs),\n }\n );\n }\n\n // Increment counter\n await c.env.RATE_LIMIT_KV.put(rateLimitKey, String(count + 1), {\n expirationTtl: windowMs / 1000,\n });\n\n // Add rate limit headers\n c.header('X-RateLimit-Limit', String(max));\n c.header('X-RateLimit-Remaining', String(max - count - 1));\n c.header('X-RateLimit-Reset', String(Date.now() + windowMs));\n }\n\n await next();\n };\n}\n","import type {MiddlewareHandler} from 'hono';\nimport {logger} from '@/logger';\n\nexport function createTracingMiddleware(): MiddlewareHandler {\n return async (c, next) => {\n // Get environment from context\n const env = c.get('env');\n // Extract or generate trace ID\n const traceId = c.req.header('x-trace-id') || generateTraceId();\n const spanId = generateSpanId();\n const parentSpanId = c.req.header('x-parent-span-id');\n const userId = c.get('userId');\n\n // Set global request context for pino logger\n globalThis.requestContext = {\n traceId,\n spanId,\n userId,\n };\n\n // Store in Hono context for other middleware\n c.set('traceId', traceId);\n c.set('spanId', spanId);\n\n // Add to response headers for correlation\n c.header('x-trace-id', traceId);\n c.header('x-span-id', spanId);\n\n const startTime = Date.now();\n\n try {\n await next();\n } finally {\n const duration = Date.now() - startTime;\n\n // Log request metrics using pino\n logger.info(\n {\n type: 'request',\n traceId,\n spanId,\n parentSpanId,\n method: c.req.method,\n path: c.req.path,\n status: c.res.status,\n duration,\n userAgent: c.req.header('user-agent'),\n ip:\n c.req.header('cf-connecting-ip') || c.req.header('x-forwarded-for'),\n },\n `${c.req.method} ${c.req.path} - ${c.res.status} (${duration}ms)`\n );\n\n // Add Server-Timing header for performance monitoring\n c.header('Server-Timing', `total;dur=${duration}`);\n\n // Clear global request context\n delete globalThis.requestContext;\n }\n };\n}\n\nfunction generateTraceId(): string {\n // Generate a 32-character hex string (128 bits)\n return Array.from(crypto.getRandomValues(new Uint8Array(16)))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n}\n\nfunction generateSpanId(): string {\n // Generate a 16-character hex string (64 bits)\n return Array.from(crypto.getRandomValues(new Uint8Array(8)))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n}\n","import type {Hono} from 'hono';\n\ninterface HealthCheckOptions {\n checks?: {\n [key: string]: () => Promise<boolean>;\n };\n}\n\nexport function configureHealthChecks(\n app: Hono<{\n Variables: {\n env: any;\n };\n }>,\n options: HealthCheckOptions = {}\n) {\n // Liveness probe - is the service running?\n app.get('/health', (c) => {\n return c.json({\n status: 'ok',\n timestamp: new Date().toISOString(),\n uptime: process.uptime ? process.uptime() : 0,\n });\n });\n\n // Readiness probe - is the service ready to accept traffic?\n app.get('/ready', async (c) => {\n const checks = options.checks || {};\n const results: Record<string, boolean> = {};\n let allHealthy = true;\n\n for (const [name, check] of Object.entries(checks)) {\n try {\n results[name] = await check();\n if (!results[name]) allHealthy = false;\n } catch (error) {\n results[name] = false;\n allHealthy = false;\n }\n }\n\n const status = allHealthy ? 200 : 503;\n return c.json(\n {\n status: allHealthy ? 'ready' : 'not_ready',\n checks: results,\n timestamp: new Date().toISOString(),\n },\n status\n );\n });\n\n // Metrics endpoint (for Prometheus)\n app.get('/metrics', (c) => {\n // In production, integrate with Prometheus client\n return c.text(`# HELP graphql_requests_total Total number of GraphQL requests\n# TYPE graphql_requests_total counter\ngraphql_requests_total 0\n\n# HELP graphql_errors_total Total number of GraphQL errors\n# TYPE graphql_errors_total counter\ngraphql_errors_total 0\n\n# HELP graphql_duration_seconds GraphQL request duration\n# TYPE graphql_duration_seconds histogram\ngraphql_duration_seconds_bucket{le=\"0.1\"} 0\ngraphql_duration_seconds_bucket{le=\"0.5\"} 0\ngraphql_duration_seconds_bucket{le=\"1\"} 0\ngraphql_duration_seconds_bucket{le=\"+Inf\"} 0\ngraphql_duration_seconds_sum 0\ngraphql_duration_seconds_count 0`);\n });\n}\n","import type {GraphQLError} from 'graphql';\nimport {ApolloServerErrorCode} from '@apollo/server/errors';\n\n// Unfortunately, this string constant is not exposed separately\nconst BAD_USER_INPUT_CODE = ApolloServerErrorCode.BAD_USER_INPUT;\n\nexport const getNonUserInputErrors = (errors: readonly GraphQLError[]) =>\n errors.filter((e) => e.extensions?.code !== BAD_USER_INPUT_CODE);\n","// import {CommonBaggageItems} from '@hiliosai/jaeger-apollo-plugin';\n\nimport type {GraphQLRequestContext} from '@apollo/server';\nimport {BaseContext} from '../context';\n\nexport enum CommonBaggageItems {\n ROOT_OP_NAME = 'root_op_name',\n}\n\nexport const getOpsName = (gqlCtx: GraphQLRequestContext<BaseContext>) =>\n gqlCtx.contextValue.rootSpan?.getBaggageItem(\n CommonBaggageItems.ROOT_OP_NAME\n ) ||\n gqlCtx.request.operationName ||\n gqlCtx.operationName ||\n 'UNKNOWN';\n","import {getNonUserInputErrors} from '@/utils/graphql.util';\nimport {getOpsName} from '@/utils/tracing.util';\nimport type {ApolloServerPlugin} from '@apollo/server';\nimport type {BaseContext} from '../context';\nimport {createLogger} from './index';\n\nconst getUserId = (gqlCtx: BaseContext) => gqlCtx.user?.id ?? 'UNKNOWN';\n\nexport function createApolloLoggingPlugin(): ApolloServerPlugin<BaseContext> {\n return {\n async requestDidStart(requestContext) {\n const start = Date.now();\n const operationName = requestContext.request.operationName;\n\n // Create a logger with request context\n const requestLogger = createLogger({\n source: 'apollo',\n operationName,\n });\n\n return {\n async didResolveOperation(gqlCtx) {\n const userId = getUserId(gqlCtx.contextValue);\n const operation = getOpsName(gqlCtx);\n\n requestLogger.info(\n {\n event: 'operation_resolved',\n operation,\n userId,\n operationName: gqlCtx.operationName,\n variables: gqlCtx.request.variables,\n },\n `Operation [${operation}] resolved for user [${userId}]`\n );\n },\n\n async willSendResponse(gqlCtx) {\n const errors = getNonUserInputErrors(gqlCtx.errors || []);\n const duration = Date.now() - start;\n const userId = getUserId(gqlCtx.contextValue);\n const operation = getOpsName(gqlCtx);\n\n if (errors.length > 0) {\n // Log errors with full context\n requestLogger.error(\n {\n event: 'operation_error',\n operation,\n userId,\n duration,\n errors: errors.map((e) => ({\n message: e.message,\n path: e.path,\n extensions: e.extensions,\n stack: e.stack,\n })),\n },\n `Operation [${operation}] failed with ${errors.length} error(s)`\n );\n }\n\n // Log completion with metrics\n requestLogger.info(\n {\n event: 'operation_complete',\n operation,\n userId,\n duration,\n success: errors.length === 0,\n errorCount: errors.length,\n },\n `Operation [${operation}] completed in ${duration}ms${errors.length > 0 ? ' with errors' : ' successfully'}`\n );\n },\n\n async didEncounterErrors(gqlCtx) {\n const errors = gqlCtx.errors || [];\n const userId = getUserId(gqlCtx.contextValue);\n\n requestLogger.error(\n {\n event: 'graphql_errors',\n userId,\n errors: errors.map((e) => ({\n message: e.message,\n path: e.path,\n extensions: e.extensions,\n })),\n },\n `GraphQL execution encountered ${errors.length} error(s)`\n );\n },\n };\n },\n };\n}\n","import type {BaseContext} from '@/context';\nimport {createApolloLoggingPlugin} from '@/logger/apollo.logger';\nimport {ApolloServerPluginLandingPageDisabled} from '@apollo/server/plugin/disabled';\nimport {ServerBuilder} from './server.builder';\n\nexport function configurePlugins<TContext extends BaseContext>(\n builder: ServerBuilder<unknown, TContext>\n) {\n // disable landing page\n builder.plugins.push(ApolloServerPluginLandingPageDisabled());\n\n // logger\n builder.plugins.push(createApolloLoggingPlugin());\n}\n","import {BaseContext} from '@/context';\nimport {logger} from '@/logger';\nimport {ServerBuilder, ServerConfig} from './server.builder';\n\nexport type BaseServerOptions = {\n /**\n * The version of the server\n *\n * @type {string}\n */\n version: string;\n /**\n * The name of the server\n *\n * @type {string}\n */\n name: string;\n\n /**\n * The port to listen on\n *\n * @type {number}\n */\n port?: number;\n\n /**\n * The hostname to listen on\n *\n * @type {string}\n */\n hostname?: string;\n};\n\nexport type ServerOptions<\n TDatasource,\n TContext extends BaseContext,\n> = BaseServerOptions & {\n config: ServerConfig<TDatasource, TContext>;\n};\n\nconst SERVICE_NAME_REGEX = /^[a-z0-9\\-_]+$/i;\n\nexport function createGraphQLServer<TDatasource, TContext extends BaseContext>(\n options: ServerOptions<TDatasource, TContext>\n) {\n if (!SERVICE_NAME_REGEX.test(options.name)) {\n throw new Error('Service name must be alphanumeric, hyphen, or underscore');\n }\n logger.info(`Creating GraphQL server ${options.name} v${options.version}`);\n return new ServerBuilder<TDatasource, TContext>(options.config);\n}\n","import {GraphQLError} from 'graphql';\nimport {ApolloServerErrorCode} from '@apollo/server/errors';\n\nexport enum ErrorCode {\n // Authentication & Authorization\n UNAUTHENTICATED = 'UNAUTHENTICATED',\n FORBIDDEN = 'FORBIDDEN',\n\n // Validation\n VALIDATION_FAILED = 'VALIDATION_FAILED',\n\n // Rate Limiting\n RATE_LIMITED = 'RATE_LIMITED',\n\n // External Service\n EXTERNAL_SERVICE_ERROR = 'EXTERNAL_SERVICE_ERROR',\n\n // Data\n NOT_FOUND = 'NOT_FOUND',\n CONFLICT = 'CONFLICT',\n}\n\nexport class AppError extends GraphQLError {\n constructor(\n message: string,\n code: ErrorCode | ApolloServerErrorCode,\n extensions?: Record<string, any>\n ) {\n super(message, {\n extensions: {\n code,\n ...extensions,\n },\n });\n }\n}\n\nexport function createErrorHandler(logger: any) {\n return (error: Error, context: any) => {\n const errorId = generateErrorId();\n\n logger.error({\n errorId,\n message: error.message,\n stack: error.stack,\n context: {\n user: context.user?.id,\n operation: context.operation?.name,\n },\n });\n\n if (error instanceof GraphQLError) {\n return error;\n }\n\n // Don't expose internal errors in production\n if (process.env.NODE_ENV === 'production') {\n return new AppError(\n 'Internal server error',\n ApolloServerErrorCode.INTERNAL_SERVER_ERROR,\n {errorId}\n );\n }\n\n return error;\n };\n}\n\nfunction generateErrorId(): string {\n return `err_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;\n}\n","import type {DocumentNode} from 'graphql';\n\nexport const createSchemaModule = (\n typeDefs: DocumentNode,\n resolvers?: any\n) => ({\n typeDefs,\n resolvers,\n});\n\nexport type SchemaModule = ReturnType<typeof createSchemaModule>;\nexport {gql} from 'graphql-tag';\n","import type {BaseContext} from '@/context';\nimport type {KVCache} from '@/cache';\n\nexport interface BaseDatasource<TContext extends BaseContext = BaseContext> {\n readonly name: string;\n context?: TContext;\n\n init?(): Promise<void> | void;\n connect?(): Promise<void> | void;\n disconnect?(): Promise<void> | void;\n healthCheck?(): Promise<boolean> | boolean;\n clear?(): Promise<void> | void;\n}\n\n/**\n * Abstract base class for all datasources in the GraphQL bootstrap\n * Provides common functionality like caching, logging, and lifecycle management\n */\nexport abstract class AbstractDatasource<\n TContext extends BaseContext = BaseContext,\n> implements BaseDatasource<TContext> {\n abstract readonly name: string;\n context: TContext;\n protected cache: KVCache;\n protected logger: TContext['logger'];\n\n constructor(cache: KVCache, context: TContext) {\n this.cache = cache;\n this.context = context;\n this.logger = context.logger;\n\n // Call initialize after construction\n this.initialize();\n }\n\n /**\n * Initialize datasource-specific configuration\n * Override this method to add custom initialization logic\n */\n protected initialize(): void {\n // Default implementation - override in subclasses\n this.logger?.info(`Initializing datasource: ${this.name}`);\n }\n\n async init(): Promise<void> {\n // Default implementation - override in subclasses\n this.logger?.info(`Initializing datasource: ${this.name}`);\n }\n\n async connect(): Promise<void> {\n // Default implementation - override in subclasses\n this.logger?.info(`Connecting datasource: ${this.name}`);\n }\n\n async disconnect(): Promise<void> {\n // Default implementation - override in subclasses\n this.logger?.info(`Disconnecting datasource: ${this.name}`);\n }\n\n async healthCheck(): Promise<boolean> {\n this.logger?.debug(`Health check for datasource: ${this.name}`);\n return true;\n }\n\n async clear(): Promise<void> {\n // Default implementation - override in subclasses\n this.logger?.info(`Clearing datasource: ${this.name}`);\n }\n\n /**\n * Helper method to get a cached result or fetch fresh data\n * Uses the enhanced KVCache memoize function\n */\n protected async cached<T>(\n key: string,\n fetchFn: () => Promise<T>,\n ttl?: number\n ): Promise<T> {\n return this.cache.memoize(key, {}, fetchFn, {ttl});\n }\n\n /**\n * Helper method to invalidate cache entries by pattern\n */\n protected async invalidateCache(pattern: string): Promise<number> {\n return this.cache.invalidate(pattern);\n }\n}\n","import type {BaseContext} from '@/context';\nimport type {KVCache} from '@/cache';\nimport {AbstractDatasource} from './base.datasource';\n\nexport interface RestClientOptions {\n baseURL: string;\n timeout?: number;\n headers?: Record<string, string>;\n retries?: number;\n}\n\n/**\n * REST datasource for making HTTP API calls with caching and error handling\n * Optimized for Cloudflare Workers environment\n */\nexport class RestDatasource<\n TContext extends BaseContext = BaseContext,\n> extends AbstractDatasource<TContext> {\n readonly name = 'rest';\n private baseURL: string;\n private timeout: number;\n private headers: Record<string, string>;\n private retries: number;\n\n constructor(cache: KVCache, context: TContext, options: RestClientOptions) {\n super(cache, context);\n this.baseURL = options.baseURL.replace(/\\/$/, ''); // Remove trailing slash\n this.timeout = options.timeout ?? 10000;\n this.headers = {\n 'Content-Type': 'application/json',\n 'User-Agent': 'cfw-graphql-bootstrap/1.0',\n ...options.headers,\n };\n this.retries = options.retries ?? 3;\n }\n\n async healthCheck(): Promise<boolean> {\n try {\n this.logger?.debug(`Health check for REST datasource: ${this.baseURL}`);\n const response = await this.get('/health');\n const isHealthy = response.status < 400;\n this.logger?.info(\n `REST datasource health check: ${isHealthy ? 'OK' : 'FAILED'}`\n );\n return isHealthy;\n } catch (error) {\n this.logger?.error('REST datasource health check failed:', error);\n return false;\n }\n }\n\n /**\n * GET request with caching\n */\n async get<T = any>(\n path: string,\n options?: {\n cache?: boolean;\n ttl?: number;\n params?: Record<string, string>;\n }\n ): Promise<T> {\n const url = this.buildURL(path, options?.params);\n const cacheKey = `rest:get:${url}`;\n\n if (options?.cache !== false) {\n return this.cached(\n cacheKey,\n () => this.fetchWithRetry(url, {method: 'GET'}),\n options?.ttl\n );\n }\n\n return this.fetchWithRetry(url, {method: 'GET'});\n }\n\n /**\n * POST request (no caching)\n */\n async post<T = any>(\n path: string,\n data?: any,\n options?: {\n invalidatePattern?: string;\n }\n ): Promise<T> {\n const url = this.buildURL(path);\n const result = await this.fetchWithRetry(url, {\n method: 'POST',\n body: data ? JSON.stringify(data) : undefined,\n });\n\n // Invalidate cache if pattern provided\n if (options?.invalidatePattern) {\n await this.invalidateCache(options.invalidatePattern);\n }\n\n return result;\n }\n\n /**\n * PUT request (no caching)\n */\n async put<T = any>(\n path: string,\n data?: any,\n options?: {\n invalidatePattern?: string;\n }\n ): Promise<T> {\n const url = this.buildURL(path);\n const result = await this.fetchWithRetry(url, {\n method: 'PUT',\n body: data ? JSON.stringify(data) : undefined,\n });\n\n // Invalidate cache if pattern provided\n if (options?.invalidatePattern) {\n await this.invalidateCache(options.invalidatePattern);\n }\n\n return result;\n }\n\n /**\n * DELETE request (no caching)\n */\n async delete<T = any>(\n path: string,\n options?: {\n invalidatePattern?: string;\n }\n ): Promise<T> {\n const url = this.buildURL(path);\n const result = await this.fetchWithRetry(url, {method: 'DELETE'});\n\n // Invalidate cache if pattern provided\n if (options?.invalidatePattern) {\n await this.invalidateCache(options.invalidatePattern);\n }\n\n return result;\n }\n\n private buildURL(path: string, params?: Record<string, string>): string {\n const url = `${this.baseURL}${path.startsWith('/') ? path : `/${path}`}`;\n\n if (params) {\n const searchParams = new URLSearchParams(params);\n return `${url}?${searchParams.toString()}`;\n }\n\n return url;\n }\n\n private async fetchWithRetry<T = any>(\n url: string,\n options: RequestInit,\n attempt = 1\n ): Promise<T> {\n try {\n this.logger?.debug(\n `[${attempt}/${this.retries}] ${options.method || 'GET'} ${url}`\n );\n\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n const response = await fetch(url, {\n ...options,\n headers: {\n ...this.headers,\n ...options.headers,\n },\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n\n this.logger?.debug(\n `✓ ${options.method || 'GET'} ${url} - ${response.status}`\n );\n return await response.json();\n } catch (error) {\n this.logger?.warn(\n `✗ ${options.method || 'GET'} ${url} - Attempt ${attempt} failed:`,\n error\n );\n\n if (attempt < this.retries && this.shouldRetry(error)) {\n const delay = Math.pow(2, attempt) * 1000;\n this.logger?.info(`Retrying in ${delay}ms...`);\n await this.delay(delay); // Exponential backoff\n return this.fetchWithRetry(url, options, attempt + 1);\n }\n\n this.logger?.error(`Failed after ${attempt} attempts:`, error);\n throw error;\n }\n }\n\n private shouldRetry(error: any): boolean {\n // Retry on network errors and 5xx status codes\n return (\n error.name === 'AbortError' ||\n error.message?.includes('fetch') ||\n (error.message?.includes('HTTP 5') ?? false)\n );\n }\n\n private delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n","import type {KVCache} from '@/cache';\nimport type {BaseContext} from '@/context';\nimport {AbstractDatasource} from './base.datasource';\n\n// Minimal Prisma Client interface for type safety\nexport interface PrismaClientLike {\n $connect(): Promise<void>;\n $disconnect(): Promise<void>;\n $queryRaw: any;\n $queryRawUnsafe(sql: string, ...values: any[]): Promise<any>;\n $executeRawUnsafe(sql: string, ...values: any[]): Promise<number>;\n}\n\n// PrismaD1 adapter type (imported dynamically)\nexport interface PrismaD1 {\n // We don't need to define the full interface since it's used opaquely\n // The actual implementation comes from '@prisma/adapter-d1'\n}\n\n// Global Prisma client cache for reuse\ndeclare global {\n var __prismaD1Clients: Map<string, any> | undefined;\n}\n\n/**\n * Abstract Prisma datasource optimized for Cloudflare D1\n * Automatically creates PrismaD1 adapter and requires user to implement createClient()\n *\n * @example\n * ```typescript\n * import { PrismaClient } from '@prisma/client';\n * import { PrismaD1 } from '@prisma/adapter-d1';\n *\n * class UserDatasource extends PrismaD1Datasource<BaseContext, PrismaClient> {\n * createClient(adapter: PrismaD1): PrismaClient {\n * // Called only ONCE per datasource class, then cached globally\n * console.log('Creating UserDatasource client'); // Will only log once\n * return new PrismaClient({ adapter });\n * }\n *\n * async getUser(id: string) {\n * return this.client.user.findUnique({ where: { id } });\n * }\n * }\n *\n * // Multiple instances share the same client efficiently:\n * datasources: (cache: KVCache, context: TContext) => ({\n * user: new UserDatasource(cache, context), // Client cached by class name\n * admin: new UserDatasource(cache, context), // Reuses same client!\n * })\n * ```\n */\nexport abstract class PrismaD1Datasource<\n TContext extends BaseContext = BaseContext,\n TPrismaClient extends PrismaClientLike = PrismaClientLike,\n> extends AbstractDatasource<TContext> {\n readonly name = 'prisma-d1';\n private _client: TPrismaClient | null = null;\n\n constructor(cache: KVCache, context: TContext) {\n super(cache, context);\n }\n\n /**\n * Abstract method to create Prisma client with D1 adapter\n * Called only once per datasource class, then cached globally\n */\n abstract createClient(adapter: PrismaD1): TPrismaClient;\n\n get client(): TPrismaClient {\n if (!this._client) {\n throw new Error('Prisma client not initialized. Call connect() first.');\n }\n return this._client;\n }\n\n async connect(): Promise<void> {\n this.logger.info('Connecting Prisma D1 datasource...');\n\n // Get D1 database from environment (automatically uses env.DB)\n const env = (this.context as any)?.env;\n if (!env?.DB) {\n const error =\n 'D1 database binding not found. Add to wrangler.toml:\\n' +\n '[[d1_databases]]\\n' +\n 'binding = \"DB\"\\n' +\n 'database_name = \"your-database-name\"\\n' +\n 'database_id = \"your-database-id\"';\n this.logger.error(error);\n throw new Error(error);\n }\n\n // Create cache key based on datasource constructor name\n const clientKey = this.constructor.name;\n\n // Initialize global client cache if needed\n if (!global.__prismaD1Clients) {\n global.__prismaD1Clients = new Map();\n }\n\n // Check if we have a cached client for this datasource class\n if (global.__prismaD1Clients.has(clientKey)) {\n this._client = global.__prismaD1Clients.get(clientKey);\n this.logger.debug(`Using cached Prisma client for ${clientKey}`);\n } else {\n this.logger.debug('Creating new PrismaD1 adapter and client...');\n\n // Create PrismaD1 adapter\n const d1Module = await import('@prisma/adapter-d1');\n const PrismaD1 = (d1Module as any).PrismaD1 ?? d1Module.default;\n const adapter = new PrismaD1(env.DB);\n\n // Create client only once per datasource class\n this._client = this.createClient(adapter);\n\n // Cache the client globally\n global.__prismaD1Clients.set(clientKey, this._client);\n this.logger.debug(`Cached new Prisma client for ${clientKey}`);\n }\n\n await this._client.$connect();\n this.logger.info('✓ Prisma D1 datasource connected');\n }\n\n // Helper method for proper resource cleanup in Workers context\n async disconnectWithContext(ctx?: {\n waitUntil: (promise: Promise<any>) => void;\n }): Promise<void> {\n if (!this._client) return;\n\n const disconnectPromise = this._client.$disconnect();\n\n // Use ctx.waitUntil() if available to ensure cleanup completes\n if (ctx?.waitUntil) {\n ctx.waitUntil(disconnectPromise);\n } else {\n await disconnectPromise;\n }\n }\n\n async disconnect(): Promise<void> {\n if (this._client) {\n await this._client.$disconnect();\n }\n }\n\n async healthCheck(): Promise<boolean> {\n try {\n this.logger.debug('Prisma D1 datasource health check...');\n if (this._client) {\n await this._client.$queryRaw`SELECT 1`;\n }\n this.logger.info('Prisma D1 datasource health check: OK');\n return true;\n } catch (error) {\n this.logger.error('Prisma D1 datasource health check failed:', error);\n return false;\n }\n }\n\n /**\n * Execute a cached query using raw SQL\n */\n async queryRaw<T = any>(\n sql: string,\n values?: any[],\n options?: {\n cache?: boolean;\n ttl?: number;\n }\n ): Promise<T> {\n const cacheKey = `prisma-d1:raw:${sql}:${JSON.stringify(values || [])}`;\n\n if (options?.cache !== false) {\n return this.cached(\n cacheKey,\n () => this._client!.$queryRawUnsafe(sql, ...(values || [])),\n options?.ttl\n );\n }\n\n return this._client!.$queryRawUnsafe(sql, ...(values || []));\n }\n\n /**\n * Execute a mutation and invalidate cache\n */\n async executeRaw(\n sql: string,\n values?: any[],\n options?: {\n invalidatePattern?: string;\n }\n ): Promise<number> {\n if (!this._client) {\n throw new Error('Prisma client not initialized. Call connect() first.');\n }\n\n const result = await this._client.$executeRawUnsafe(sql, ...(values || []));\n\n // Invalidate cache if pattern provided\n if (options?.invalidatePattern) {\n await this.invalidateCache(options.invalidatePattern);\n }\n\n return result;\n }\n}\n"],"mappings":";AAAA,OAAO,UAAU;AAGjB,IAAM,QAAQ,QAAQ,IAAI,aAAa;AACvC,IAAM,WAAW,QAAQ,IAAI,cAAc,QAAQ,UAAU;AAG7D,IAAM,cAAc;AAAA,EAClB,KAAK,CAAC,QAAa;AACjB,QAAI,CAAC,IAAK,QAAO;AACjB,WAAO;AAAA,MACL,MAAM,IAAI,aAAa,QAAQ,IAAI;AAAA,MACnC,SAAS,IAAI;AAAA,MACb,OAAO,IAAI;AAAA,MACX,MAAM,IAAI;AAAA,MACV,YAAY,IAAI;AAAA,IAClB;AAAA,EACF;AAAA,EACA,KAAK,CAAC,QAAiB;AACrB,QAAI,CAAC,IAAK,QAAO;AACjB,WAAO;AAAA,MACL,QAAQ,IAAI;AAAA,MACZ,KAAK,IAAI;AAAA,MACT,SAAS,OAAO,YAAY,IAAI,QAAQ,QAAQ,CAAC;AAAA,IACnD;AAAA,EACF;AAAA,EACA,KAAK,CAAC,QAAkB;AACtB,QAAI,CAAC,IAAK,QAAO;AACjB,WAAO;AAAA,MACL,YAAY,IAAI;AAAA,MAChB,SAAS,OAAO,YAAY,IAAI,QAAQ,QAAQ,CAAC;AAAA,IACnD;AAAA,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AE;AAAA,QAC1D,SAAS;AAAA,MACX;AAAA,IACF;AAEA,WAAO,KAAK,QAAS,gBAAgB,KAAK,GAAI,UAAU,CAAC,CAAE;AAAA,EAC7D;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WACJ,KACA,QACA,SAGiB;AACjB,QAAI,CAAC,KAAK,SAAS;AACjB,YAAM,IAAI,MAAM,sDAAsD;AAAA,IACxE;AAEA,UAAM,SAAS,MAAM,KAAK,QAAQ,kBAAkB,KAAK,GAAI,UAAU,CAAC,CAAE;AAG1E,QAAI,SAAS,mBAAmB;AAC9B,YAAM,KAAK,gBAAgB,QAAQ,iBAAiB;AAAA,IACtD;AAEA,WAAO;AAAA,EACT;AACF;","names":["cached","cached","ApolloServerErrorCode","ErrorCode"]}
|
|
1
|
+
{"version":3,"sources":["../src/logger/index.ts","../src/cache/kv-cache.ts","../src/cache/batching-datasource.ts","../src/cache/apollo-cache-adapter.ts","../src/cache/index.ts","../src/context/constants.ts","../src/context/auth.ts","../src/env/config.ts","../src/context/index.ts","../src/utils/builder.util.ts","../src/server/server.builder.ts","../src/datasources/apollo-plugin.datasource.ts","../src/server/hono.configure.ts","../src/middleware/validation.ts","../src/middleware/rate-limit.ts","../src/middleware/tracing.ts","../src/middleware/health.ts","../src/utils/graphql.util.ts","../src/utils/tracing.util.ts","../src/logger/apollo.logger.ts","../src/server/plugin.configure.ts","../src/server/index.ts","../src/utils/error.util.ts","../src/utils/schema.util.ts","../src/datasources/base.datasource.ts","../src/datasources/rest.datasource.ts","../src/datasources/prisma.datasource.ts"],"sourcesContent":["import pino from 'pino/browser';\n\n// Configuration for Cloudflare Workers environment\nconst isDev = process.env.NODE_ENV !== 'production';\nconst logLevel = process.env.LOG_LEVEL || (isDev ? 'debug' : 'info');\n\n// Custom serializers for Cloudflare Workers\nconst serializers = {\n err: (err: any) => {\n if (!err) return err;\n return {\n type: err.constructor?.name || err.name,\n message: err.message,\n stack: err.stack,\n code: err.code,\n statusCode: err.statusCode,\n };\n },\n req: (req: Request) => {\n if (!req) return req;\n return {\n method: req.method,\n url: req.url,\n headers: Object.fromEntries(req.headers.entries()),\n };\n },\n res: (res: Response) => {\n if (!res) return res;\n return {\n statusCode: res.status,\n headers: Object.fromEntries(res.headers.entries()),\n };\n },\n};\n\n// Create pino logger optimized for Cloudflare Workers\nexport const logger = pino({\n browser: {\n asObject: true,\n write: {\n info: (o: any) => {\n // In production, send to external logging service\n if (!isDev && globalThis.logshipper) {\n globalThis.logshipper.log(o);\n }\n console.log(JSON.stringify(o));\n },\n error: (o: any) => {\n if (!isDev && globalThis.logshipper) {\n globalThis.logshipper.log(o);\n }\n console.error(JSON.stringify(o));\n },\n debug: (o: any) => {\n if (isDev) {\n console.debug(JSON.stringify(o));\n }\n },\n warn: (o: any) => {\n if (!isDev && globalThis.logshipper) {\n globalThis.logshipper.log(o);\n }\n console.warn(JSON.stringify(o));\n },\n fatal: (o: any) => {\n if (!isDev && globalThis.logshipper) {\n globalThis.logshipper.log(o);\n }\n console.error(JSON.stringify(o));\n },\n trace: (o: any) => {\n if (isDev) {\n console.trace(JSON.stringify(o));\n }\n },\n },\n },\n level: logLevel,\n base: {\n env: process.env.NODE_ENV,\n service: 'graphql-subgraph',\n runtime: 'cloudflare-workers',\n },\n serializers,\n timestamp: () => `,\"timestamp\":\"${new Date().toISOString()}\"`,\n formatters: {\n level: (label: string) => {\n return {level: label.toUpperCase()};\n },\n log: (object: any) => {\n // Add request context if available\n if (globalThis.requestContext) {\n object.traceId = globalThis.requestContext.traceId;\n object.spanId = globalThis.requestContext.spanId;\n object.userId = globalThis.requestContext.userId;\n }\n return object;\n },\n },\n});\n\n// Helper for creating child loggers with context\nexport function createLogger(context: Record<string, any>) {\n return logger.child(context);\n}\n\n// Export pino types for TypeScript\nexport type Logger = typeof logger;\n\n// Declare global types for Cloudflare Workers\ndeclare global {\n var logshipper: {\n log: (data: any) => void;\n };\n var requestContext: {\n traceId?: string;\n spanId?: string;\n userId?: string;\n };\n}\n","/**\n * KV Cache implementation for Cloudflare Workers\n * Provides caching capabilities for GraphQL resolvers using Cloudflare KV\n */\n\nexport interface CacheOptions {\n ttl?: number; // Time to live in seconds\n namespace?: string; // Cache namespace prefix\n cacheKey?: string; // Custom cache key\n}\n\nexport class KVCache {\n private defaultTTL: number = 300; // 5 minutes default\n private defaultNamespace: string = 'cache';\n\n constructor(\n private kv: KVNamespace,\n defaultNamespace?: string\n ) {\n if (defaultNamespace) {\n this.defaultNamespace = defaultNamespace;\n }\n }\n\n /**\n * Get a value from cache\n */\n async get<T = any>(key: string): Promise<T | null> {\n try {\n const value = await this.kv.get(key);\n if (!value) return null;\n\n // Try to parse JSON, fallback to raw value\n try {\n return JSON.parse(value);\n } catch {\n return value as T;\n }\n } catch (error) {\n console.error(`Cache get error for key ${key}:`, error);\n return null;\n }\n }\n\n /**\n * Set a value in cache with metadata\n */\n async set(\n key: string,\n value: any,\n options: CacheOptions = {}\n ): Promise<void> {\n try {\n const serialized =\n typeof value === 'string' ? value : JSON.stringify(value);\n\n const ttl = options.ttl || this.defaultTTL;\n const kvOptions: KVNamespacePutOptions = {\n expirationTtl: ttl,\n metadata: {\n createdAt: new Date().toISOString(),\n ttl: ttl,\n namespace: options.namespace || this.defaultNamespace,\n },\n };\n\n await this.kv.put(key, serialized, kvOptions);\n } catch (error) {\n console.error(`Cache set error for key ${key}:`, error);\n }\n }\n\n /**\n * Delete a value from cache\n */\n async delete(key: string): Promise<void> {\n try {\n await this.kv.delete(key);\n } catch (error) {\n console.error(`Cache delete error for key ${key}:`, error);\n }\n }\n\n /**\n * Check if a key exists in cache\n */\n async has(key: string): Promise<boolean> {\n try {\n const value = await this.kv.get(key);\n return value !== null;\n } catch (error) {\n console.error(`Cache has error for key ${key}:`, error);\n return false;\n }\n }\n\n /**\n * Clear multiple keys matching a prefix\n */\n async clearPrefix(prefix: string): Promise<number> {\n try {\n const list = await this.kv.list({prefix});\n const promises = list.keys.map((key) => this.kv.delete(key.name));\n await Promise.all(promises);\n return list.keys.length;\n } catch (error) {\n console.error(`Cache clear prefix error for ${prefix}:`, error);\n return 0;\n }\n }\n\n /**\n * Invalidate cache by pattern\n */\n async invalidate(pattern: string): Promise<number> {\n return this.clearPrefix(pattern);\n }\n\n /**\n * Clear all cache in a namespace\n */\n async clearNamespace(namespace?: string): Promise<number> {\n const prefix = namespace ? `${namespace}:` : `${this.defaultNamespace}:`;\n return this.invalidate(prefix);\n }\n\n /**\n * Get or set a value with a factory function\n * Useful for cache-aside pattern\n */\n async getOrSet<T>(\n key: string,\n factory: () => Promise<T>,\n options: CacheOptions = {}\n ): Promise<T> {\n // Try to get from cache first\n const cached = await this.get<T>(key);\n if (cached !== null) {\n return cached;\n }\n\n // Fetch fresh value\n const fresh = await factory();\n\n // Cache the fresh value (non-blocking)\n this.set(key, fresh, options).catch((error) => {\n console.error(`Background cache write error for ${key}:`, error);\n });\n\n return fresh;\n }\n\n /**\n * Memoize function with automatic key generation\n */\n async memoize<T>(\n cacheKey: string,\n params: any,\n fetchFn: () => Promise<T>,\n options: CacheOptions = {}\n ): Promise<T> {\n const namespace = options.namespace || this.defaultNamespace;\n const key = this.generateKey(`${namespace}:${cacheKey}`, params);\n\n try {\n // Try to get from cache\n const cached = await this.get<T>(key);\n if (cached !== null) {\n return cached;\n }\n } catch (error) {\n console.warn(`Cache read error for ${key}:`, error);\n }\n\n // Cache miss - fetch data\n const data = await fetchFn();\n\n // Store in cache (non-blocking)\n this.set(key, data, options).catch((error) => {\n console.warn(`Cache write error for ${key}:`, error);\n });\n\n return data;\n }\n\n /**\n * Generate cache key with namespace and params\n */\n private generateKey(namespace: string, params: any): string {\n const sortedParams = Object.keys(params)\n .sort()\n .reduce((obj: any, key) => {\n if (params[key] !== undefined && params[key] !== null) {\n obj[key] = params[key];\n }\n return obj;\n }, {});\n\n const paramString = JSON.stringify(sortedParams);\n const hash = this.simpleHash(paramString);\n return `${namespace}:${hash}`;\n }\n\n /**\n * Simple hash function for generating cache keys\n */\n private simpleHash(str: string): string {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n const char = str.charCodeAt(i);\n hash = (hash << 5) - hash + char;\n hash = hash & hash; // Convert to 32bit integer\n }\n return Math.abs(hash).toString(36);\n }\n}\n\n/**\n * Create a cache key from multiple parts\n */\nexport function createCacheKey(\n ...parts: (string | number | undefined)[]\n): string {\n return parts\n .filter((part) => part !== undefined)\n .map((part) => String(part))\n .join(':');\n}\n\n/**\n * Cache key patterns for different data types\n */\nexport const CacheKeys = {\n user: (id: string) => createCacheKey('user', id),\n query: (name: string, variables?: string) =>\n createCacheKey('query', name, variables),\n list: (type: string, page?: number) => createCacheKey('list', type, page),\n permission: (userId: string, resource: string) =>\n createCacheKey('perm', userId, resource),\n} as const;\n","import DataLoader, {type BatchLoadFn, type Options} from 'dataloader';\nimport type {BaseContext} from '@/context';\nimport {KVCache} from './kv-cache';\n\n/**\n * Ensures that output items has the same order as input keys (dataloader requirement).\n * Returns error objects for non-existent ids.\n *\n * @param keys list of input keys\n * @param items list of output items\n * @param primaryKey name of the key-holding property\n */\nexport function ensureBatchOrder<\n K extends string | number,\n T extends Record<string, any>,\n>(keys: readonly K[], items: T[], primaryKey = 'id'): Array<T | Error> {\n const itemsMap = new Map<K, T>();\n\n // Build a map for O(1) lookups\n for (const item of items) {\n const key = item[primaryKey] as K;\n if (key !== undefined) {\n itemsMap.set(key, item);\n }\n }\n\n // Return items in the same order as keys\n return keys.map(\n (key) =>\n itemsMap.get(key) || new Error(`Missing value for ${primaryKey} ${key}`)\n );\n}\n\n/**\n * Ensures that output items has the same order as input keys (dataloader requirement).\n * Returns null for non-existent ids.\n *\n * @param keys list of input keys\n * @param items list of output items\n * @param primaryKey name of the key-holding property\n */\nexport function ensureBatchOrderNullable<\n K extends string | number,\n T extends Record<string, any>,\n>(keys: readonly K[], items: T[], primaryKey = 'id'): Array<T | null> {\n const itemsMap = new Map<K, T>();\n\n // Build a map for O(1) lookups\n for (const item of items) {\n const key = item[primaryKey] as K;\n if (key !== undefined) {\n itemsMap.set(key, item);\n }\n }\n\n // Return items in the same order as keys, with nulls for missing\n return keys.map((key) => itemsMap.get(key) || null);\n}\n\n/**\n * Base class for batching data sources with caching support.\n * Uses DataLoader for request batching and deduplication.\n *\n * @typeParam TContext - Apollo context type\n * @typeParam K - Primary key type\n * @typeParam V - Output item type\n * @typeParam CK - Cache key type (same as K by default)\n *\n * @example\n * ```typescript\n * export class UserBatchingDataSource extends BatchingDataSource<BaseContext, string, User> {\n * constructor() {\n * super(async (ids: readonly string[]) => {\n * const users = await fetchUsersFromDB(ids);\n * return ensureBatchOrder(ids, users);\n * });\n * }\n * }\n * ```\n */\nexport class BatchingDataSource<TContext extends BaseContext, K, V, CK = K> {\n protected context!: TContext;\n protected loader: DataLoader<K, V, CK>;\n protected cache?: KVCache;\n\n /**\n * Creates a new batching data source\n *\n * @param resolveBatch - Batch resolving function\n * @param options - DataLoader options\n * @param cacheNamespace - Optional namespace for KV caching\n */\n constructor(\n resolveBatch: BatchLoadFn<K, V>,\n options: Options<K, V, CK> = {},\n protected cacheNamespace?: string\n ) {\n // Bind context to the batch function\n const boundResolveBatch: BatchLoadFn<K, V> = async (keys) => {\n // If we have cache, try to load from cache first\n if (this.cache && this.cacheNamespace) {\n const results: Array<V | undefined> = [];\n const uncachedKeys: K[] = [];\n const uncachedIndexes: number[] = [];\n\n // Check cache for each key\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const cacheKey = `${this.cacheNamespace}:${String(key)}`;\n const cached = await this.cache.get<V>(cacheKey);\n\n if (cached !== null) {\n results[i] = cached;\n } else {\n uncachedKeys.push(key);\n uncachedIndexes.push(i);\n }\n }\n\n // If all items were cached, return them\n if (uncachedKeys.length === 0) {\n return results as V[];\n }\n\n // Fetch uncached items\n const freshItems = await resolveBatch.call(this, uncachedKeys);\n\n // Merge fresh items back and cache them\n for (let i = 0; i < uncachedIndexes.length; i++) {\n const index = uncachedIndexes[i];\n const item = freshItems[i] as V;\n const key = uncachedKeys[i];\n\n results[index] = item;\n\n // Cache the fresh item (non-blocking)\n if (!(item instanceof Error) && item !== null && item !== undefined) {\n const cacheKey = `${this.cacheNamespace}:${String(key)}`;\n this.cache.set(cacheKey, item, {ttl: 300}).catch((err) => {\n console.warn(`Failed to cache item ${cacheKey}:`, err);\n });\n }\n }\n\n return results as V[];\n }\n\n // No cache, just resolve normally\n return resolveBatch.call(this, keys);\n };\n\n this.loader = new DataLoader(boundResolveBatch, {\n ...options,\n // Default to caching within the request\n cache: options.cache !== false,\n });\n }\n\n /**\n * Initialize with Apollo context\n */\n initialize(config: {contextValue: TContext}) {\n this.context = config.contextValue;\n this.cache = config.contextValue.cache;\n }\n\n /**\n * Load a single item by key\n */\n async load(id: K): Promise<V> {\n return this.loader.load(id);\n }\n\n /**\n * Load multiple items by keys\n */\n async loadMany(ids: readonly K[]): Promise<Array<V | Error>> {\n return this.loader.loadMany(ids);\n }\n\n /**\n * Clear a single item from the DataLoader cache\n */\n clear(id: K): this {\n this.loader.clear(id);\n return this;\n }\n\n /**\n * Clear all items from the DataLoader cache\n */\n clearAll(): this {\n this.loader.clearAll();\n return this;\n }\n\n /**\n * Prime the cache with a specific value\n */\n prime(key: K, value: V): this {\n this.loader.prime(key, value);\n return this;\n }\n}\n\n/**\n * Factory function for creating batching data sources\n *\n * @example\n * ```typescript\n * const userDataSource = createBatchingDataSource<BaseContext, string, User>(\n * async (ids) => {\n * const users = await fetchUsersFromDB(ids);\n * return ensureBatchOrder(ids, users);\n * },\n * { cache: true },\n * 'users'\n * );\n * ```\n */\nexport function createBatchingDataSource<\n TContext extends BaseContext,\n K,\n V,\n CK = K,\n>(\n resolveBatch: BatchLoadFn<K, V>,\n options?: Options<K, V, CK>,\n cacheNamespace?: string\n): BatchingDataSource<TContext, K, V, CK> {\n return new BatchingDataSource(resolveBatch, options, cacheNamespace);\n}\n","/**\n * Apollo KeyValueCache adapter for Cloudflare KV\n *\n * Implements the Apollo Server KeyValueCache interface to work with\n * Cloudflare Workers KV storage.\n */\n\nimport type {\n KeyValueCache,\n KeyValueCacheSetOptions,\n} from '@apollo/utils.keyvaluecache';\nimport {KVCache} from './kv-cache';\n\n/**\n * Adapter that makes our KVCache compatible with Apollo's KeyValueCache interface\n *\n * Apollo Server uses this for:\n * - Response caching\n * - APQ (Automatic Persisted Queries)\n * - DataSource caching\n *\n * @example\n * ```typescript\n * const apolloCache = new ApolloKVAdapter(new KVCache(env.KV));\n *\n * const server = new ApolloServer({\n * cache: apolloCache,\n * // ... other options\n * });\n * ```\n */\nexport class ApolloKVAdapter implements KeyValueCache<string> {\n constructor(private kvCache: KVCache) {}\n\n /**\n * Get a value from cache\n * Apollo expects undefined for cache misses\n */\n async get(key: string): Promise<string | undefined> {\n const value = await this.kvCache.get<string>(key);\n // Apollo expects undefined, not null for cache misses\n return value === null ? undefined : value;\n }\n\n /**\n * Set a value in cache with TTL support\n * Apollo passes TTL in seconds via options\n */\n async set(\n key: string,\n value: string,\n options?: KeyValueCacheSetOptions\n ): Promise<void> {\n await this.kvCache.set(key, value, {\n ttl: options?.ttl, // Apollo's TTL is already in seconds\n });\n }\n\n /**\n * Delete a value from cache\n * Apollo expects boolean or void return\n */\n async delete(key: string): Promise<boolean | void> {\n await this.kvCache.delete(key);\n return true;\n }\n}\n\n/**\n * Factory function to create an Apollo-compatible cache from KV namespace\n *\n * @param kv - Cloudflare KV namespace binding\n * @returns Apollo-compatible KeyValueCache\n */\nexport function createApolloCache(kv: KVNamespace): KeyValueCache<string> {\n return new ApolloKVAdapter(new KVCache(kv));\n}\n\n/**\n * In-memory LRU cache for development/testing\n * Falls back to simple Map-based implementation\n */\nexport class InMemoryCache implements KeyValueCache<string> {\n private cache = new Map<string, {value: string; expires?: number}>();\n\n async get(key: string): Promise<string | undefined> {\n const item = this.cache.get(key);\n if (!item) return undefined;\n\n // Check expiration\n if (item.expires && Date.now() > item.expires) {\n this.cache.delete(key);\n return undefined;\n }\n\n return item.value;\n }\n\n async set(\n key: string,\n value: string,\n options?: KeyValueCacheSetOptions\n ): Promise<void> {\n const expires = options?.ttl\n ? Date.now() + options.ttl * 1000 // Convert seconds to milliseconds\n : undefined;\n\n this.cache.set(key, {value, expires});\n }\n\n async delete(key: string): Promise<boolean> {\n return this.cache.delete(key);\n }\n\n /**\n * Clear all cache entries\n */\n clear(): void {\n this.cache.clear();\n }\n}\n","/**\n * Cache module for GraphQL resolvers\n * Provides caching interface for Cloudflare Workers KV\n */\n\nimport {KVCache, createCacheKey, CacheKeys} from './kv-cache';\nimport type {CacheOptions} from './kv-cache';\nimport {\n BatchingDataSource,\n createBatchingDataSource,\n ensureBatchOrder,\n ensureBatchOrderNullable,\n} from './batching-datasource';\nimport {\n ApolloKVAdapter,\n createApolloCache,\n InMemoryCache,\n} from './apollo-cache-adapter';\n\nexport {KVCache, createCacheKey, CacheKeys};\nexport type {CacheOptions};\nexport {\n BatchingDataSource,\n createBatchingDataSource,\n ensureBatchOrder,\n ensureBatchOrderNullable,\n};\nexport {ApolloKVAdapter, createApolloCache, InMemoryCache};\n\n/**\n * Cache factory - creates KV cache if available\n */\nexport function createCache(env: Env): KVCache | null {\n // Check for KV namespace (Cloudflare Workers KV)\n if (env.KV) {\n return new KVCache(env.KV);\n }\n\n // No cache available\n return null;\n}\n\n/**\n * Decorator for caching resolver results\n */\nexport function cached(\n options: CacheOptions & {keyGenerator?: (...args: any[]) => string} = {}\n) {\n return function (\n target: any,\n propertyKey: string,\n descriptor: PropertyDescriptor\n ) {\n const originalMethod = descriptor.value;\n\n descriptor.value = async function (...args: any[]) {\n const context = args[2]; // GraphQL context is third argument\n const cache = context?.cache;\n\n if (!cache) {\n // No cache available, run original method\n return originalMethod.apply(this, args);\n }\n\n // Generate cache key\n const key = options.keyGenerator\n ? options.keyGenerator(...args)\n : createCacheKey(propertyKey, JSON.stringify(args[1])); // Use field name and arguments\n\n // Try cache-aside pattern\n return cache.getOrSet(\n key,\n () => originalMethod.apply(this, args),\n options\n );\n };\n\n return descriptor;\n };\n}\n\n/**\n * GraphQL DataLoader integration for batching and caching\n */\nexport class CachedDataLoader<K, V> {\n private loader: any; // DataLoader instance\n private cache: KVCache;\n\n constructor(\n batchFn: (keys: K[]) => Promise<V[]>,\n cache: KVCache,\n private options: CacheOptions = {}\n ) {\n this.cache = cache;\n\n // Initialize DataLoader with cache\n // Note: DataLoader is not included by default, install if needed\n // this.loader = new DataLoader(batchFn, { cache: this.createCacheMap() });\n }\n\n async load(key: K): Promise<V> {\n const cacheKey = createCacheKey('loader', String(key));\n\n return this.cache.getOrSet(\n cacheKey,\n async () => {\n // Fallback to batch function for single key\n // In production, use actual DataLoader\n return this.loader ? this.loader.load(key) : null;\n },\n this.options\n );\n }\n\n async loadMany(keys: K[]): Promise<V[]> {\n return Promise.all(keys.map((key) => this.load(key)));\n }\n\n async clear(key: K): Promise<void> {\n const cacheKey = createCacheKey('loader', String(key));\n await this.cache.delete(cacheKey);\n }\n\n async clearAll(): Promise<void> {\n await this.cache.clearPrefix('loader:');\n }\n}\n","export const Headers = {\n GATEWAY_USER: 'x-gateway-user',\n GATEWAY_USER_SIGNATURE: 'x-gateway-user-signature',\n AUTH: 'authorization',\n CLIENT_ID: 'x-client-id',\n} as const;\n","import type {ContextUser} from './types';\n\n/**\n * Verifies and parses user context from gateway headers\n * For Cloudflare Workers deployment, we use HMAC signature verification\n * to ensure the user data hasn't been tampered with\n */\nexport async function verifyAndParseUser(\n encodedUser: string | null,\n signature: string | null,\n secret: string\n): Promise<ContextUser | undefined> {\n if (!encodedUser || !signature) {\n return undefined;\n }\n\n try {\n // Verify HMAC signature\n const encoder = new TextEncoder();\n const key = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n {name: 'HMAC', hash: 'SHA-256'},\n false,\n ['verify']\n );\n\n const signatureBuffer = hexToBuffer(signature);\n const dataBuffer = encoder.encode(encodedUser);\n\n const isValid = await crypto.subtle.verify(\n 'HMAC',\n key,\n signatureBuffer,\n dataBuffer\n );\n\n if (!isValid) {\n console.error('Invalid user signature');\n return undefined;\n }\n\n // Parse the verified user data\n const user = JSON.parse(atob(encodedUser));\n return user;\n } catch (error) {\n console.error('Error verifying user:', error);\n return undefined;\n }\n}\n\nfunction hexToBuffer(hex: string): ArrayBuffer {\n const bytes = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);\n }\n // Return the ArrayBuffer directly, not SharedArrayBuffer\n return bytes.buffer as ArrayBuffer;\n}\n","/**\n * Environment configuration type\n */\nexport interface EnvConfig {\n // Core\n NODE_ENV: 'development' | 'test' | 'production';\n PORT: number;\n\n // Security\n GATEWAY_SECRET?: string;\n ALLOWED_ORIGINS: string[];\n\n // Logging\n LOG_LEVEL: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';\n\n // Rate limiting\n RATE_LIMIT_WINDOW_MS: number;\n RATE_LIMIT_MAX: number;\n\n // Monitoring\n ENABLE_METRICS: boolean;\n ENABLE_TRACING: boolean;\n\n // GraphQL\n MAX_QUERY_DEPTH: number;\n MAX_QUERY_COMPLEXITY: number;\n INTROSPECTION_ENABLED: boolean;\n\n // External services (optional)\n LOG_SERVICE_URL?: string;\n LOG_SERVICE_TOKEN?: string;\n}\n\n/**\n * Lightweight environment parser inspired by @ltv/env\n */\nclass EnvParser {\n constructor(private env: Record<string, any>) {}\n\n string(key: string): string | undefined;\n string(key: string, defaultValue: string): string;\n string(key: string, defaultValue?: string): string | undefined {\n const value = this.env[key];\n return value !== undefined && value !== '' ? String(value) : defaultValue;\n }\n\n int(key: string): number | undefined;\n int(key: string, defaultValue: number): number;\n int(key: string, defaultValue?: number): number | undefined {\n const value = this.env[key];\n if (value === undefined || value === '') return defaultValue;\n const parsed = parseInt(String(value), 10);\n return isNaN(parsed) ? defaultValue : parsed;\n }\n\n bool(key: string): boolean | undefined;\n bool(key: string, defaultValue: boolean): boolean;\n bool(key: string, defaultValue?: boolean): boolean | undefined {\n const value = this.env[key];\n if (value === undefined || value === '') return defaultValue;\n const str = String(value).toLowerCase();\n return str === 'true' || str === '1';\n }\n\n array(key: string): string[] | undefined;\n array(key: string, defaultValue: string[]): string[];\n array(key: string, defaultValue?: string[]): string[] | undefined {\n const value = this.env[key];\n if (value === undefined || value === '') return defaultValue;\n if (Array.isArray(value)) return value;\n return String(value)\n .split(',')\n .map((s) => s.trim())\n .filter(Boolean);\n }\n\n enum<T extends string>(key: string, validValues: T[]): T | undefined;\n enum<T extends string>(key: string, validValues: T[], defaultValue: T): T;\n enum<T extends string>(\n key: string,\n validValues: T[],\n defaultValue?: T\n ): T | undefined {\n const value = this.string(key);\n if (value && validValues.includes(value as T)) {\n return value as T;\n }\n return defaultValue;\n }\n}\n\n/**\n * Environment loader for Cloudflare Workers\n */\nexport class EnvironmentLoader {\n private config: EnvConfig | null = null;\n\n /**\n * Load environment from Cloudflare Workers env object\n */\n load(env: Record<string, any>): EnvConfig {\n const parser = new EnvParser(env);\n\n this.config = {\n NODE_ENV: parser.enum(\n 'NODE_ENV',\n ['development', 'test', 'production'],\n 'production'\n ),\n PORT: parser.int('PORT', 3344),\n GATEWAY_SECRET: parser.string('GATEWAY_SECRET'),\n ALLOWED_ORIGINS: parser.array('ALLOWED_ORIGINS', [\n 'http://localhost:3000',\n ]),\n LOG_LEVEL: parser.enum(\n 'LOG_LEVEL',\n ['trace', 'debug', 'info', 'warn', 'error', 'fatal'],\n 'info'\n ),\n RATE_LIMIT_WINDOW_MS: parser.int('RATE_LIMIT_WINDOW_MS', 60000),\n RATE_LIMIT_MAX: parser.int('RATE_LIMIT_MAX', 100),\n ENABLE_METRICS: parser.bool('ENABLE_METRICS', true),\n ENABLE_TRACING: parser.bool('ENABLE_TRACING', true),\n MAX_QUERY_DEPTH: parser.int('MAX_QUERY_DEPTH', 10),\n MAX_QUERY_COMPLEXITY: parser.int('MAX_QUERY_COMPLEXITY', 1000),\n INTROSPECTION_ENABLED: parser.bool('INTROSPECTION_ENABLED', false),\n LOG_SERVICE_URL: parser.string('LOG_SERVICE_URL'),\n LOG_SERVICE_TOKEN: parser.string('LOG_SERVICE_TOKEN'),\n };\n\n return this.config;\n }\n\n /**\n * Get current configuration\n */\n getConfig(): EnvConfig {\n if (!this.config) {\n throw new Error('Environment not loaded. Call load() first.');\n }\n return this.config;\n }\n\n /**\n * Helper getters for common checks\n */\n get isDev(): boolean {\n return this.config?.NODE_ENV === 'development';\n }\n\n get isTest(): boolean {\n return this.config?.NODE_ENV === 'test';\n }\n\n get isProd(): boolean {\n return this.config?.NODE_ENV === 'production';\n }\n}\n\n// Singleton instance\nexport const envLoader = new EnvironmentLoader();\n","import type {BaseContext as ApolloBaseContext} from '@apollo/server';\nimport type {ExecutionContext} from '@cloudflare/workers-types';\nimport type {CloudflareContextFunctionArgument} from '@as-integrations/cloudflare-workers';\nimport {logger} from '../logger';\nimport {Headers} from './constants';\nimport {verifyAndParseUser} from './auth';\nimport type {ContextUser} from './types';\nimport {createCache} from '@/cache';\nimport type {KVCache} from '@/cache';\nimport {envLoader, type EnvConfig} from '@/env';\n\nexport type {ContextUser} from './types';\n\n// TODO: Replace with actual jaeger types when available\nexport interface JaegerContext {\n rootSpan?: {\n getBaggageItem: (key: string) => string | undefined;\n };\n}\n\nexport interface BaseContext extends JaegerContext, ApolloBaseContext {\n user?: ContextUser;\n logger: typeof logger;\n executionCtx: ExecutionContext;\n cache?: KVCache; // KV cache for resolvers\n db?: D1Database; // D1 database binding for datasources\n env: EnvConfig; // Validated environment configuration\n\n /** @deprecated should not be used directly */\n authorization: string;\n clientId: string;\n}\n\nexport type ContextExtendFunction<T extends BaseContext> = (\n ctx: BaseContext,\n honoContext: CloudflareContextFunctionArgument<unknown>\n) => T | Promise<T>;\n\nasync function createBaseContext(\n honoContext: CloudflareContextFunctionArgument<any>\n): Promise<BaseContext> {\n const request = honoContext.request;\n const rawEnv = honoContext.env;\n\n // Load and validate environment configuration\n const env = envLoader.load(rawEnv);\n\n // Parse user from gateway headers with signature verification\n let user: ContextUser | undefined;\n\n // Check if this is a subgraph request from gateway\n const encodedUser = request.headers.get(Headers.GATEWAY_USER);\n if (encodedUser) {\n // In production, verify signature. In dev, allow without signature\n if (env.GATEWAY_SECRET) {\n const signature = request.headers.get(Headers.GATEWAY_USER_SIGNATURE);\n user = await verifyAndParseUser(\n encodedUser,\n signature,\n env.GATEWAY_SECRET\n );\n } else if (env.NODE_ENV !== 'production') {\n // Development mode: parse without verification\n try {\n user = JSON.parse(atob(encodedUser));\n } catch (e) {\n console.error('Failed to parse user in dev mode:', e);\n }\n }\n }\n\n // Create cache instance - KV is now required\n // Pass raw env for KV bindings, not the parsed config\n const cache = createCache(rawEnv) as KVCache | undefined;\n if (!cache) {\n // This should not happen as ServerBuilder validates KV exists\n logger.warn(\n 'KV cache not found in context - this should not happen if using ServerBuilder'\n );\n }\n\n // Get D1 database binding (optional - datasources will validate if needed)\n const db = rawEnv?.DB as D1Database | undefined;\n\n return {\n user,\n logger,\n cache,\n db, // Raw D1 binding for datasources\n env, // Pass validated env config\n executionCtx: honoContext.ctx,\n authorization: request.headers.get(Headers.AUTH) || '',\n clientId: request.headers.get(Headers.CLIENT_ID) || '',\n };\n}\n\nexport function createContextFunction<T extends BaseContext>(\n extendContext?: ContextExtendFunction<T>\n) {\n if (!extendContext) {\n return (honoContext: CloudflareContextFunctionArgument<unknown>) =>\n createBaseContext(honoContext);\n }\n\n return async (honoContext: CloudflareContextFunctionArgument<unknown>) => {\n const baseContext = await createBaseContext(honoContext);\n return extendContext(baseContext, honoContext);\n };\n}\n","export function assertDefined<T>(t: T | undefined, msg: string): t is T {\n if (t === undefined) {\n throw new Error('Assertion failed when configuring server: ' + msg);\n }\n return true;\n}\n","import {createApolloCache} from '@/cache';\nimport {\n createContextFunction,\n type BaseContext,\n type ContextExtendFunction,\n} from '@/context';\nimport {assertDefined} from '@/utils/builder.util';\nimport type {ApolloServerOptions, ApolloServerPlugin} from '@apollo/server';\nimport {ApolloServer} from '@apollo/server';\nimport {startServerAndCreateCloudflareWorkersHandler} from '@as-integrations/cloudflare-workers';\nimport type {GraphQLSchema} from 'graphql';\nimport type {Hono} from 'hono';\nimport {ApolloDataSources} from '../datasources/apollo-plugin.datasource';\nimport {configureHono} from './hono.configure';\nimport {configurePlugins} from './plugin.configure';\n\nexport type Runner = {\n fetch: typeof Hono.prototype.fetch;\n port?: number;\n};\n\nimport type {KVCache} from '@/cache';\n\nexport type ServerConfig<TDatasource, TContext extends BaseContext> = {\n path?: string;\n apollo: Partial<ApolloServerOptions<BaseContext>>;\n datasources: (cache: KVCache, context: TContext) => TDatasource;\n extendContext?: ContextExtendFunction<TContext>;\n};\n\nexport class ServerBuilder<TDatasource, TContext extends BaseContext> {\n readonly app: Hono<{\n Variables: {\n env: any;\n };\n }>;\n\n readonly schema: GraphQLSchema;\n readonly plugins: ApolloServerPlugin<BaseContext>[] = [];\n\n constructor(readonly config: ServerConfig<TDatasource, TContext>) {\n this.assert();\n\n // TODO: Configure metrics\n this.app = configureHono(this);\n this.schema = this.config.apollo.schema as GraphQLSchema;\n }\n\n configure(): Runner {\n const honoApp = this.app;\n configurePlugins(this);\n\n // Build plugins array with datasources\n const plugins: ApolloServerPlugin<TContext>[] = [...this.plugins];\n\n // Add datasources plugin (now required)\n plugins.push(\n ApolloDataSources({\n datasources: this.config.datasources as any,\n }) as any\n );\n\n // We need to create the Apollo server for each request to pass the correct cache\n const createHandler = (env: any) => {\n // Validate KV binding exists\n if (!env?.KV) {\n throw new Error(\n 'Missing required KV namespace binding. ' +\n 'Please add KV namespace binding in your wrangler.toml:\\n' +\n '[[kv_namespaces]]\\n' +\n 'binding = \"KV\"\\n' +\n 'id = \"your-kv-namespace-id\"'\n );\n }\n\n // Create Apollo cache from KV\n const apolloCache = createApolloCache(env.KV);\n\n // Create Apollo server with cache\n // We need to ensure we don't include gateway if schema is provided\n const {gateway, ...apolloConfigWithoutGateway} = this.config.apollo || {};\n\n const server = new ApolloServer<TContext>({\n ...apolloConfigWithoutGateway, // User config without gateway\n schema: this.schema, // Our schema\n plugins, // Our plugins\n cache: apolloCache, // Apollo cache for APQ and response caching (override any user cache)\n } as ApolloServerOptions<TContext>);\n\n return startServerAndCreateCloudflareWorkersHandler<any, any>(server, {\n context: async (c) =>\n createContextFunction(this.config.extendContext)(c),\n });\n };\n\n // Cache handlers per environment (for efficiency)\n const handlerCache = new WeakMap();\n\n const getOrCreateHandler = (env: any) => {\n if (!handlerCache.has(env)) {\n handlerCache.set(env, createHandler(env));\n }\n return handlerCache.get(env);\n };\n\n honoApp.all(this.config.path ?? '/', async (c) => {\n // Get or create handler for this environment\n const cfHandler = getOrCreateHandler(c.env);\n\n // In local development, executionCtx doesn't exist\n // In Cloudflare Workers, it's provided\n let executionCtx;\n try {\n executionCtx = c.executionCtx;\n } catch (e) {\n // Create a mock executionCtx for local development\n executionCtx = {\n waitUntil: (promise: Promise<any>) => promise,\n passThroughOnException: () => {},\n };\n }\n return cfHandler(c.req.raw, c.env, executionCtx);\n });\n\n return {\n async fetch(request, env, ctx) {\n return honoApp.fetch(request, env, ctx);\n },\n };\n }\n\n assert() {\n assertDefined(\n this.config.apollo.schema,\n 'Apollo server config must have a schema'\n );\n }\n}\n","import type {ApolloServerPlugin} from '@apollo/server';\nimport type {BaseContext} from '../context';\nimport type {ServerConfig} from '../server/server.builder';\nimport type {KVCache} from '../cache';\n\ntype DataSources = Record<string, any>;\ntype DataSourcesFn = <TContext extends BaseContext = BaseContext>(\n cache: KVCache,\n contextValue: TContext\n) => DataSources;\n\nexport type ComputedContext<\n TDatasource,\n TContext extends BaseContext,\n> = TContext & {\n datasources: ReturnType<\n NonNullable<ServerConfig<TDatasource, TContext>['datasources']>\n >;\n};\n\nexport const ApolloDataSources = <\n TDatasource,\n TContext extends BaseContext,\n>(options: {\n datasources: DataSourcesFn;\n}): ApolloServerPlugin<ComputedContext<TDatasource, TContext>> => ({\n requestDidStart: async (requestContext) => {\n // Get KVCache from context instead of Apollo's cache\n const kvCache = requestContext.contextValue.cache;\n if (!kvCache) {\n throw new Error(\n 'KVCache not found in context. This should not happen if using ServerBuilder.'\n );\n }\n\n const dataSources = options.datasources(\n kvCache,\n requestContext.contextValue\n );\n\n // Auto-connect datasources that have connect method\n const connectPromises = Object.values(dataSources).map(\n async (dataSource) => {\n if (dataSource && typeof dataSource.connect === 'function') {\n await dataSource.connect();\n }\n }\n );\n\n await Promise.all(connectPromises);\n\n requestContext.contextValue.datasources =\n dataSources as unknown as TDatasource;\n },\n});\n","import {BaseContext} from '@/context';\nimport {Hono} from 'hono';\nimport {cors} from 'hono/cors';\nimport {compress} from 'hono/compress';\nimport {ServerBuilder} from './server.builder';\nimport {createValidationMiddleware} from '@/middleware/validation';\nimport {createRateLimitMiddleware} from '@/middleware/rate-limit';\nimport {createTracingMiddleware} from '@/middleware/tracing';\nimport {configureHealthChecks} from '@/middleware/health';\n\nexport function configureHono<TContext extends BaseContext>(\n builder: ServerBuilder<unknown, TContext>\n) {\n const app = new Hono<{\n Variables: {\n env: any;\n };\n }>();\n\n // Add environment to context for all middleware\n app.use('*', async (c, next) => {\n // Get environment from Cloudflare or set default\n const rawEnv = c.env || {};\n const env = rawEnv as any; // Type assertion for environment variables\n c.set('env', env);\n await next();\n });\n\n // Add request tracing first for all requests\n app.use('*', createTracingMiddleware());\n\n // Add compression for responses\n app.use('*', compress());\n\n // Add validation middleware\n app.use('*', createValidationMiddleware());\n\n // Add rate limiting\n app.use('*', createRateLimitMiddleware());\n\n // Configure health checks\n configureHealthChecks(app, {\n checks: {\n graphql: async () => true, // Check GraphQL schema is loaded\n },\n });\n\n // Configure CORS for development and production\n app.use(\n '/*',\n cors({\n origin: (origin, c) => {\n // Get environment from context\n const env = c.get('env') as any;\n const isProd = env?.NODE_ENV === 'production';\n const allowedOrigins = env.ALLOWED_ORIGINS\n ? typeof env.ALLOWED_ORIGINS === 'string'\n ? env.ALLOWED_ORIGINS.split(',').map((s) => s.trim())\n : env.ALLOWED_ORIGINS\n : ['http://localhost:3000'];\n\n // Allow all origins in development\n if (!isProd) {\n return origin || '*';\n }\n // In production, configure allowed origins\n return allowedOrigins.includes(origin) ? origin : allowedOrigins[0];\n },\n allowHeaders: [\n 'Content-Type',\n 'Authorization',\n 'x-apollo-operation-name',\n 'apollo-require-preflight',\n ],\n allowMethods: ['POST', 'GET', 'OPTIONS'],\n credentials: true,\n maxAge: 86400,\n })\n );\n\n // Add security headers\n app.use('*', async (c, next) => {\n await next();\n\n const env = c.get('env') as any;\n const isProd = env?.NODE_ENV === 'production';\n\n // Security headers for GraphQL endpoints\n c.header('X-Content-Type-Options', 'nosniff');\n c.header('X-Frame-Options', 'DENY');\n c.header('X-XSS-Protection', '1; mode=block');\n c.header('Referrer-Policy', 'strict-origin-when-cross-origin');\n\n // Remove server identification\n c.header('Server', 'GraphQL');\n\n // Content Security Policy for GraphQL\n if (isProd) {\n c.header(\n 'Content-Security-Policy',\n \"default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';\"\n );\n // HSTS for production\n c.header(\n 'Strict-Transport-Security',\n 'max-age=31536000; includeSubDomains; preload'\n );\n }\n });\n\n return app;\n}\n","import type {MiddlewareHandler} from 'hono';\nimport {AppError, ErrorCode} from '@/utils/error.util';\n\ninterface ValidationOptions {\n maxQueryDepth?: number;\n maxQueryComplexity?: number;\n maxAliasCount?: number;\n}\n\nexport function createValidationMiddleware(\n options: ValidationOptions = {}\n): MiddlewareHandler {\n return async (c, next) => {\n try {\n // Get environment from context\n const env = c.get('env');\n const maxQueryDepth = options.maxQueryDepth || env?.MAX_QUERY_DEPTH || 10;\n const maxQueryComplexity =\n options.maxQueryComplexity || env?.MAX_QUERY_COMPLEXITY || 1000;\n const maxAliasCount = options.maxAliasCount || 15;\n // Validate content type for GraphQL\n const contentType = c.req.header('content-type');\n if (\n c.req.method === 'POST' &&\n !contentType?.includes('application/json')\n ) {\n return c.json(\n {\n errors: [\n {\n message: 'Content-Type must be application/json',\n extensions: {code: 'BAD_REQUEST'},\n },\n ],\n },\n 400\n );\n }\n\n // Rate limiting headers check\n const clientId = c.req.header('x-client-id');\n if (!clientId && env?.NODE_ENV === 'production') {\n return c.json(\n {\n errors: [\n {\n message: 'Client identification required',\n extensions: {code: 'BAD_REQUEST'},\n },\n ],\n },\n 400\n );\n }\n\n await next();\n } catch (error) {\n console.error('Validation middleware error:', error);\n return c.json(\n {\n errors: [\n {\n message: 'Request validation failed',\n extensions: {code: 'INTERNAL_SERVER_ERROR'},\n },\n ],\n },\n 500\n );\n }\n };\n}\n","import type {MiddlewareHandler} from 'hono';\n\ninterface RateLimitOptions {\n windowMs?: number;\n max?: number;\n keyGenerator?: (c: any) => string;\n}\n\nexport function createRateLimitMiddleware(\n options: RateLimitOptions = {}\n): MiddlewareHandler {\n const {\n keyGenerator = (c) =>\n c.req.header('x-client-id') ||\n c.req.header('cf-connecting-ip') ||\n 'anonymous',\n } = options;\n\n return async (c, next) => {\n // Get environment from context\n const env = c.get('env');\n const windowMs = options.windowMs || env?.RATE_LIMIT_WINDOW_MS || 60 * 1000;\n const max = options.max || env?.RATE_LIMIT_MAX || 100;\n\n const key = keyGenerator(c);\n const rateLimitKey = `rate_limit:${key}`;\n\n // In Cloudflare Workers, use KV or Durable Objects for rate limiting\n // This is a simplified example\n if (c.env?.RATE_LIMIT_KV) {\n const current = await c.env.RATE_LIMIT_KV.get(rateLimitKey);\n const count = current ? parseInt(current, 10) : 0;\n\n if (count >= max) {\n return c.json(\n {\n errors: [\n {\n message: 'Too many requests',\n extensions: {\n code: 'RATE_LIMITED',\n retryAfter: windowMs / 1000,\n },\n },\n ],\n },\n 429,\n {\n 'Retry-After': String(windowMs / 1000),\n 'X-RateLimit-Limit': String(max),\n 'X-RateLimit-Remaining': '0',\n 'X-RateLimit-Reset': String(Date.now() + windowMs),\n }\n );\n }\n\n // Increment counter\n await c.env.RATE_LIMIT_KV.put(rateLimitKey, String(count + 1), {\n expirationTtl: windowMs / 1000,\n });\n\n // Add rate limit headers\n c.header('X-RateLimit-Limit', String(max));\n c.header('X-RateLimit-Remaining', String(max - count - 1));\n c.header('X-RateLimit-Reset', String(Date.now() + windowMs));\n }\n\n await next();\n };\n}\n","import type {MiddlewareHandler} from 'hono';\nimport {logger} from '@/logger';\n\nexport function createTracingMiddleware(): MiddlewareHandler {\n return async (c, next) => {\n // Get environment from context\n const env = c.get('env');\n // Extract or generate trace ID\n const traceId = c.req.header('x-trace-id') || generateTraceId();\n const spanId = generateSpanId();\n const parentSpanId = c.req.header('x-parent-span-id');\n const userId = c.get('userId');\n\n // Set global request context for pino logger\n globalThis.requestContext = {\n traceId,\n spanId,\n userId,\n };\n\n // Store in Hono context for other middleware\n c.set('traceId', traceId);\n c.set('spanId', spanId);\n\n // Add to response headers for correlation\n c.header('x-trace-id', traceId);\n c.header('x-span-id', spanId);\n\n const startTime = Date.now();\n\n try {\n await next();\n } finally {\n const duration = Date.now() - startTime;\n\n // Log request metrics using pino\n logger.info(\n {\n type: 'request',\n traceId,\n spanId,\n parentSpanId,\n method: c.req.method,\n path: c.req.path,\n status: c.res.status,\n duration,\n userAgent: c.req.header('user-agent'),\n ip:\n c.req.header('cf-connecting-ip') || c.req.header('x-forwarded-for'),\n },\n `${c.req.method} ${c.req.path} - ${c.res.status} (${duration}ms)`\n );\n\n // Add Server-Timing header for performance monitoring\n c.header('Server-Timing', `total;dur=${duration}`);\n\n // Clear global request context\n delete globalThis.requestContext;\n }\n };\n}\n\nfunction generateTraceId(): string {\n // Generate a 32-character hex string (128 bits)\n return Array.from(crypto.getRandomValues(new Uint8Array(16)))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n}\n\nfunction generateSpanId(): string {\n // Generate a 16-character hex string (64 bits)\n return Array.from(crypto.getRandomValues(new Uint8Array(8)))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n}\n","import type {Hono} from 'hono';\n\ninterface HealthCheckOptions {\n checks?: {\n [key: string]: () => Promise<boolean>;\n };\n}\n\nexport function configureHealthChecks(\n app: Hono<{\n Variables: {\n env: any;\n };\n }>,\n options: HealthCheckOptions = {}\n) {\n // Liveness probe - is the service running?\n app.get('/health', (c) => {\n return c.json({\n status: 'ok',\n timestamp: new Date().toISOString(),\n uptime: process.uptime ? process.uptime() : 0,\n });\n });\n\n // Readiness probe - is the service ready to accept traffic?\n app.get('/ready', async (c) => {\n const checks = options.checks || {};\n const results: Record<string, boolean> = {};\n let allHealthy = true;\n\n for (const [name, check] of Object.entries(checks)) {\n try {\n results[name] = await check();\n if (!results[name]) allHealthy = false;\n } catch (error) {\n results[name] = false;\n allHealthy = false;\n }\n }\n\n const status = allHealthy ? 200 : 503;\n return c.json(\n {\n status: allHealthy ? 'ready' : 'not_ready',\n checks: results,\n timestamp: new Date().toISOString(),\n },\n status\n );\n });\n\n // Metrics endpoint (for Prometheus)\n app.get('/metrics', (c) => {\n // In production, integrate with Prometheus client\n return c.text(`# HELP graphql_requests_total Total number of GraphQL requests\n# TYPE graphql_requests_total counter\ngraphql_requests_total 0\n\n# HELP graphql_errors_total Total number of GraphQL errors\n# TYPE graphql_errors_total counter\ngraphql_errors_total 0\n\n# HELP graphql_duration_seconds GraphQL request duration\n# TYPE graphql_duration_seconds histogram\ngraphql_duration_seconds_bucket{le=\"0.1\"} 0\ngraphql_duration_seconds_bucket{le=\"0.5\"} 0\ngraphql_duration_seconds_bucket{le=\"1\"} 0\ngraphql_duration_seconds_bucket{le=\"+Inf\"} 0\ngraphql_duration_seconds_sum 0\ngraphql_duration_seconds_count 0`);\n });\n}\n","import type {GraphQLError} from 'graphql';\nimport {ApolloServerErrorCode} from '@apollo/server/errors';\n\n// Unfortunately, this string constant is not exposed separately\nconst BAD_USER_INPUT_CODE = ApolloServerErrorCode.BAD_USER_INPUT;\n\nexport const getNonUserInputErrors = (errors: readonly GraphQLError[]) =>\n errors.filter((e) => e.extensions?.code !== BAD_USER_INPUT_CODE);\n","// import {CommonBaggageItems} from '@hiliosai/jaeger-apollo-plugin';\n\nimport type {GraphQLRequestContext} from '@apollo/server';\nimport {BaseContext} from '../context';\n\nexport enum CommonBaggageItems {\n ROOT_OP_NAME = 'root_op_name',\n}\n\nexport const getOpsName = (gqlCtx: GraphQLRequestContext<BaseContext>) =>\n gqlCtx.contextValue.rootSpan?.getBaggageItem(\n CommonBaggageItems.ROOT_OP_NAME\n ) ||\n gqlCtx.request.operationName ||\n gqlCtx.operationName ||\n 'UNKNOWN';\n","import {getNonUserInputErrors} from '@/utils/graphql.util';\nimport {getOpsName} from '@/utils/tracing.util';\nimport type {ApolloServerPlugin} from '@apollo/server';\nimport type {BaseContext} from '../context';\nimport {createLogger} from './index';\n\nconst getUserId = (gqlCtx: BaseContext) => gqlCtx.user?.id ?? 'UNKNOWN';\n\nexport function createApolloLoggingPlugin(): ApolloServerPlugin<BaseContext> {\n return {\n async requestDidStart(requestContext) {\n const start = Date.now();\n const operationName = requestContext.request.operationName;\n\n // Create a logger with request context\n const requestLogger = createLogger({\n source: 'apollo',\n operationName,\n });\n\n return {\n async didResolveOperation(gqlCtx) {\n const userId = getUserId(gqlCtx.contextValue);\n const operation = getOpsName(gqlCtx);\n\n requestLogger.info(\n {\n event: 'operation_resolved',\n operation,\n userId,\n operationName: gqlCtx.operationName,\n variables: gqlCtx.request.variables,\n },\n `Operation [${operation}] resolved for user [${userId}]`\n );\n },\n\n async willSendResponse(gqlCtx) {\n const errors = getNonUserInputErrors(gqlCtx.errors || []);\n const duration = Date.now() - start;\n const userId = getUserId(gqlCtx.contextValue);\n const operation = getOpsName(gqlCtx);\n\n if (errors.length > 0) {\n // Log errors with full context\n requestLogger.error(\n {\n event: 'operation_error',\n operation,\n userId,\n duration,\n errors: errors.map((e) => ({\n message: e.message,\n path: e.path,\n extensions: e.extensions,\n stack: e.stack,\n })),\n },\n `Operation [${operation}] failed with ${errors.length} error(s)`\n );\n }\n\n // Log completion with metrics\n requestLogger.info(\n {\n event: 'operation_complete',\n operation,\n userId,\n duration,\n success: errors.length === 0,\n errorCount: errors.length,\n },\n `Operation [${operation}] completed in ${duration}ms${errors.length > 0 ? ' with errors' : ' successfully'}`\n );\n },\n\n async didEncounterErrors(gqlCtx) {\n const errors = gqlCtx.errors || [];\n const userId = getUserId(gqlCtx.contextValue);\n\n requestLogger.error(\n {\n event: 'graphql_errors',\n userId,\n errors: errors.map((e) => ({\n message: e.message,\n path: e.path,\n extensions: e.extensions,\n })),\n },\n `GraphQL execution encountered ${errors.length} error(s)`\n );\n },\n };\n },\n };\n}\n","import type {BaseContext} from '@/context';\nimport {createApolloLoggingPlugin} from '@/logger/apollo.logger';\nimport {ApolloServerPluginLandingPageDisabled} from '@apollo/server/plugin/disabled';\nimport {ServerBuilder} from './server.builder';\n\nexport function configurePlugins<TContext extends BaseContext>(\n builder: ServerBuilder<unknown, TContext>\n) {\n // disable landing page\n builder.plugins.push(ApolloServerPluginLandingPageDisabled());\n\n // logger\n builder.plugins.push(createApolloLoggingPlugin());\n}\n","import {BaseContext} from '@/context';\nimport {logger} from '@/logger';\nimport {ServerBuilder, ServerConfig} from './server.builder';\n\nexport type BaseServerOptions = {\n /**\n * The version of the server\n *\n * @type {string}\n */\n version: string;\n /**\n * The name of the server\n *\n * @type {string}\n */\n name: string;\n\n /**\n * The port to listen on\n *\n * @type {number}\n */\n port?: number;\n\n /**\n * The hostname to listen on\n *\n * @type {string}\n */\n hostname?: string;\n};\n\nexport type ServerOptions<\n TDatasource,\n TContext extends BaseContext,\n> = BaseServerOptions & {\n config: ServerConfig<TDatasource, TContext>;\n};\n\nconst SERVICE_NAME_REGEX = /^[a-z0-9\\-_]+$/i;\n\nexport function createGraphQLServer<TDatasource, TContext extends BaseContext>(\n options: ServerOptions<TDatasource, TContext>\n) {\n if (!SERVICE_NAME_REGEX.test(options.name)) {\n throw new Error('Service name must be alphanumeric, hyphen, or underscore');\n }\n logger.info(`Creating GraphQL server ${options.name} v${options.version}`);\n return new ServerBuilder<TDatasource, TContext>(options.config);\n}\n","import {GraphQLError} from 'graphql';\nimport {ApolloServerErrorCode} from '@apollo/server/errors';\n\nexport enum ErrorCode {\n // Authentication & Authorization\n UNAUTHENTICATED = 'UNAUTHENTICATED',\n FORBIDDEN = 'FORBIDDEN',\n\n // Validation\n VALIDATION_FAILED = 'VALIDATION_FAILED',\n\n // Rate Limiting\n RATE_LIMITED = 'RATE_LIMITED',\n\n // External Service\n EXTERNAL_SERVICE_ERROR = 'EXTERNAL_SERVICE_ERROR',\n\n // Data\n NOT_FOUND = 'NOT_FOUND',\n CONFLICT = 'CONFLICT',\n}\n\nexport class AppError extends GraphQLError {\n constructor(\n message: string,\n code: ErrorCode | ApolloServerErrorCode,\n extensions?: Record<string, any>\n ) {\n super(message, {\n extensions: {\n code,\n ...extensions,\n },\n });\n }\n}\n\nexport function createErrorHandler(logger: any) {\n return (error: Error, context: any) => {\n const errorId = generateErrorId();\n\n logger.error({\n errorId,\n message: error.message,\n stack: error.stack,\n context: {\n user: context.user?.id,\n operation: context.operation?.name,\n },\n });\n\n if (error instanceof GraphQLError) {\n return error;\n }\n\n // Don't expose internal errors in production\n if (process.env.NODE_ENV === 'production') {\n return new AppError(\n 'Internal server error',\n ApolloServerErrorCode.INTERNAL_SERVER_ERROR,\n {errorId}\n );\n }\n\n return error;\n };\n}\n\nfunction generateErrorId(): string {\n return `err_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;\n}\n","import type {DocumentNode} from 'graphql';\n\nexport const createSchemaModule = (\n typeDefs: DocumentNode,\n resolvers?: any\n) => ({\n typeDefs,\n resolvers,\n});\n\nexport type SchemaModule = ReturnType<typeof createSchemaModule>;\nexport {gql} from 'graphql-tag';\n","import type {BaseContext} from '@/context';\nimport type {KVCache} from '@/cache';\n\nexport interface BaseDatasource<TContext extends BaseContext = BaseContext> {\n readonly name: string;\n context?: TContext;\n\n init?(): Promise<void> | void;\n connect?(): Promise<void> | void;\n disconnect?(): Promise<void> | void;\n healthCheck?(): Promise<boolean> | boolean;\n clear?(): Promise<void> | void;\n}\n\n/**\n * Abstract base class for all datasources in the GraphQL bootstrap\n * Provides common functionality like caching, logging, and lifecycle management\n */\nexport abstract class AbstractDatasource<\n TContext extends BaseContext = BaseContext,\n> implements BaseDatasource<TContext> {\n abstract readonly name: string;\n context: TContext;\n protected cache: KVCache;\n protected logger: TContext['logger'];\n\n constructor(cache: KVCache, context: TContext) {\n this.cache = cache;\n this.context = context;\n this.logger = context.logger;\n\n // Call initialize after construction\n this.initialize();\n }\n\n /**\n * Initialize datasource-specific configuration\n * Override this method to add custom initialization logic\n */\n protected initialize(): void {\n // Default implementation - override in subclasses\n this.logger?.info(`Initializing datasource: ${this.name}`);\n }\n\n async init(): Promise<void> {\n // Default implementation - override in subclasses\n this.logger?.info(`Initializing datasource: ${this.name}`);\n }\n\n async connect(): Promise<void> {\n // Default implementation - override in subclasses\n this.logger?.info(`Connecting datasource: ${this.name}`);\n }\n\n async disconnect(): Promise<void> {\n // Default implementation - override in subclasses\n this.logger?.info(`Disconnecting datasource: ${this.name}`);\n }\n\n async healthCheck(): Promise<boolean> {\n this.logger?.debug(`Health check for datasource: ${this.name}`);\n return true;\n }\n\n async clear(): Promise<void> {\n // Default implementation - override in subclasses\n this.logger?.info(`Clearing datasource: ${this.name}`);\n }\n\n /**\n * Helper method to get a cached result or fetch fresh data\n * Uses the enhanced KVCache memoize function\n */\n protected async cached<T>(\n key: string,\n fetchFn: () => Promise<T>,\n ttl?: number\n ): Promise<T> {\n return this.cache.memoize(key, {}, fetchFn, {ttl});\n }\n\n /**\n * Helper method to invalidate cache entries by pattern\n */\n protected async invalidateCache(pattern: string): Promise<number> {\n return this.cache.invalidate(pattern);\n }\n}\n","import type {BaseContext} from '@/context';\nimport type {KVCache} from '@/cache';\nimport {AbstractDatasource} from './base.datasource';\n\nexport interface RestClientOptions {\n baseURL: string;\n timeout?: number;\n headers?: Record<string, string>;\n retries?: number;\n}\n\n/**\n * REST datasource for making HTTP API calls with caching and error handling\n * Optimized for Cloudflare Workers environment\n */\nexport class RestDatasource<\n TContext extends BaseContext = BaseContext,\n> extends AbstractDatasource<TContext> {\n readonly name = 'rest';\n private baseURL: string;\n private timeout: number;\n private headers: Record<string, string>;\n private retries: number;\n\n constructor(cache: KVCache, context: TContext, options: RestClientOptions) {\n super(cache, context);\n this.baseURL = options.baseURL.replace(/\\/$/, ''); // Remove trailing slash\n this.timeout = options.timeout ?? 10000;\n this.headers = {\n 'Content-Type': 'application/json',\n 'User-Agent': 'cfw-graphql-bootstrap/1.0',\n ...options.headers,\n };\n this.retries = options.retries ?? 3;\n }\n\n async healthCheck(): Promise<boolean> {\n try {\n this.logger?.debug(`Health check for REST datasource: ${this.baseURL}`);\n const response = await this.get('/health');\n const isHealthy = response.status < 400;\n this.logger?.info(\n `REST datasource health check: ${isHealthy ? 'OK' : 'FAILED'}`\n );\n return isHealthy;\n } catch (error) {\n this.logger?.error('REST datasource health check failed:', error);\n return false;\n }\n }\n\n /**\n * GET request with caching\n */\n async get<T = any>(\n path: string,\n options?: {\n cache?: boolean;\n ttl?: number;\n params?: Record<string, string>;\n }\n ): Promise<T> {\n const url = this.buildURL(path, options?.params);\n const cacheKey = `rest:get:${url}`;\n\n if (options?.cache !== false) {\n return this.cached(\n cacheKey,\n () => this.fetchWithRetry(url, {method: 'GET'}),\n options?.ttl\n );\n }\n\n return this.fetchWithRetry(url, {method: 'GET'});\n }\n\n /**\n * POST request (no caching)\n */\n async post<T = any>(\n path: string,\n data?: any,\n options?: {\n invalidatePattern?: string;\n }\n ): Promise<T> {\n const url = this.buildURL(path);\n const result = await this.fetchWithRetry(url, {\n method: 'POST',\n body: data ? JSON.stringify(data) : undefined,\n });\n\n // Invalidate cache if pattern provided\n if (options?.invalidatePattern) {\n await this.invalidateCache(options.invalidatePattern);\n }\n\n return result;\n }\n\n /**\n * PUT request (no caching)\n */\n async put<T = any>(\n path: string,\n data?: any,\n options?: {\n invalidatePattern?: string;\n }\n ): Promise<T> {\n const url = this.buildURL(path);\n const result = await this.fetchWithRetry(url, {\n method: 'PUT',\n body: data ? JSON.stringify(data) : undefined,\n });\n\n // Invalidate cache if pattern provided\n if (options?.invalidatePattern) {\n await this.invalidateCache(options.invalidatePattern);\n }\n\n return result;\n }\n\n /**\n * DELETE request (no caching)\n */\n async delete<T = any>(\n path: string,\n options?: {\n invalidatePattern?: string;\n }\n ): Promise<T> {\n const url = this.buildURL(path);\n const result = await this.fetchWithRetry(url, {method: 'DELETE'});\n\n // Invalidate cache if pattern provided\n if (options?.invalidatePattern) {\n await this.invalidateCache(options.invalidatePattern);\n }\n\n return result;\n }\n\n private buildURL(path: string, params?: Record<string, string>): string {\n const url = `${this.baseURL}${path.startsWith('/') ? path : `/${path}`}`;\n\n if (params) {\n const searchParams = new URLSearchParams(params);\n return `${url}?${searchParams.toString()}`;\n }\n\n return url;\n }\n\n private async fetchWithRetry<T = any>(\n url: string,\n options: RequestInit,\n attempt = 1\n ): Promise<T> {\n try {\n this.logger?.debug(\n `[${attempt}/${this.retries}] ${options.method || 'GET'} ${url}`\n );\n\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n const response = await fetch(url, {\n ...options,\n headers: {\n ...this.headers,\n ...options.headers,\n },\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n\n this.logger?.debug(\n `✓ ${options.method || 'GET'} ${url} - ${response.status}`\n );\n return await response.json();\n } catch (error) {\n this.logger?.warn(\n `✗ ${options.method || 'GET'} ${url} - Attempt ${attempt} failed:`,\n error\n );\n\n if (attempt < this.retries && this.shouldRetry(error)) {\n const delay = Math.pow(2, attempt) * 1000;\n this.logger?.info(`Retrying in ${delay}ms...`);\n await this.delay(delay); // Exponential backoff\n return this.fetchWithRetry(url, options, attempt + 1);\n }\n\n this.logger?.error(`Failed after ${attempt} attempts:`, error);\n throw error;\n }\n }\n\n private shouldRetry(error: any): boolean {\n // Retry on network errors and 5xx status codes\n return (\n error.name === 'AbortError' ||\n error.message?.includes('fetch') ||\n (error.message?.includes('HTTP 5') ?? false)\n );\n }\n\n private delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n","import type {KVCache} from '@/cache';\nimport type {BaseContext} from '@/context';\nimport {AbstractDatasource} from './base.datasource';\n\n// Minimal Prisma Client interface for type safety\nexport interface PrismaClientLike {\n $connect(): Promise<void>;\n $disconnect(): Promise<void>;\n $queryRaw: any;\n $queryRawUnsafe(sql: string, ...values: any[]): Promise<any>;\n $executeRawUnsafe(sql: string, ...values: any[]): Promise<number>;\n}\n\n// PrismaD1 adapter type (imported dynamically)\nexport interface PrismaD1 {\n // We don't need to define the full interface since it's used opaquely\n // The actual implementation comes from '@prisma/adapter-d1'\n}\n\n// Global Prisma client cache for reuse\ndeclare global {\n var __prismaD1Clients: Map<string, any> | undefined;\n}\n\n/**\n * Abstract Prisma datasource optimized for Cloudflare D1\n * Automatically creates PrismaD1 adapter and requires user to implement createClient()\n *\n * @example\n * ```typescript\n * import { PrismaClient } from '@prisma/client';\n * import { PrismaD1 } from '@prisma/adapter-d1';\n *\n * class UserDatasource extends PrismaD1Datasource<BaseContext, PrismaClient> {\n * createClient(adapter: PrismaD1): PrismaClient {\n * // Called only ONCE per datasource class, then cached globally\n * console.log('Creating UserDatasource client'); // Will only log once\n * return new PrismaClient({ adapter });\n * }\n *\n * async getUser(id: string) {\n * return this.client.user.findUnique({ where: { id } });\n * }\n * }\n *\n * // Multiple instances share the same client efficiently:\n * datasources: (cache: KVCache, context: TContext) => ({\n * user: new UserDatasource(cache, context), // Client cached by class name\n * admin: new UserDatasource(cache, context), // Reuses same client!\n * })\n * ```\n */\nexport abstract class PrismaD1Datasource<\n TContext extends BaseContext = BaseContext,\n TPrismaClient extends PrismaClientLike = PrismaClientLike,\n> extends AbstractDatasource<TContext> {\n readonly name = 'prisma-d1';\n private _client: TPrismaClient | null = null;\n\n constructor(cache: KVCache, context: TContext) {\n super(cache, context);\n }\n\n /**\n * Abstract method to create Prisma client with D1 adapter\n * Called only once per datasource class, then cached globally\n */\n abstract createClient(adapter: PrismaD1): TPrismaClient;\n\n get client(): TPrismaClient {\n if (!this._client) {\n throw new Error('Prisma client not initialized. Call connect() first.');\n }\n return this._client;\n }\n\n async connect(): Promise<void> {\n this.logger.info('Connecting Prisma D1 datasource...');\n\n // Get D1 database binding from context\n if (!this.context.db) {\n const error =\n 'D1 database binding not found. Add to wrangler.toml:\\n' +\n '[[d1_databases]]\\n' +\n 'binding = \"DB\"\\n' +\n 'database_name = \"your-database-name\"\\n' +\n 'database_id = \"your-database-id\"';\n this.logger.error(error);\n throw new Error(error);\n }\n\n // Create cache key based on datasource constructor name\n const clientKey = this.constructor.name;\n\n // Initialize global client cache if needed\n if (!global.__prismaD1Clients) {\n global.__prismaD1Clients = new Map();\n }\n\n // Check if we have a cached client for this datasource class\n if (global.__prismaD1Clients.has(clientKey)) {\n this._client = global.__prismaD1Clients.get(clientKey);\n this.logger.debug(`Using cached Prisma client for ${clientKey}`);\n } else {\n this.logger.debug('Creating new PrismaD1 adapter and client...');\n\n // Create PrismaD1 adapter\n const d1Module = await import('@prisma/adapter-d1');\n const PrismaD1 = (d1Module as any).PrismaD1 ?? d1Module.default;\n const adapter = new PrismaD1(this.context.db);\n\n // Create client only once per datasource class\n this._client = this.createClient(adapter);\n\n // Cache the client globally\n global.__prismaD1Clients.set(clientKey, this._client);\n this.logger.debug(`Cached new Prisma client for ${clientKey}`);\n }\n\n await this._client.$connect();\n this.logger.info('✓ Prisma D1 datasource connected');\n }\n\n // Helper method for proper resource cleanup in Workers context\n async disconnectWithContext(ctx?: {\n waitUntil: (promise: Promise<any>) => void;\n }): Promise<void> {\n if (!this._client) return;\n\n const disconnectPromise = this._client.$disconnect();\n\n // Use ctx.waitUntil() if available to ensure cleanup completes\n if (ctx?.waitUntil) {\n ctx.waitUntil(disconnectPromise);\n } else {\n await disconnectPromise;\n }\n }\n\n async disconnect(): Promise<void> {\n if (this._client) {\n await this._client.$disconnect();\n }\n }\n\n async healthCheck(): Promise<boolean> {\n try {\n this.logger.debug('Prisma D1 datasource health check...');\n if (this._client) {\n await this._client.$queryRaw`SELECT 1`;\n }\n this.logger.info('Prisma D1 datasource health check: OK');\n return true;\n } catch (error) {\n this.logger.error('Prisma D1 datasource health check failed:', error);\n return false;\n }\n }\n\n /**\n * Execute a cached query using raw SQL\n */\n async queryRaw<T = any>(\n sql: string,\n values?: any[],\n options?: {\n cache?: boolean;\n ttl?: number;\n }\n ): Promise<T> {\n const cacheKey = `prisma-d1:raw:${sql}:${JSON.stringify(values || [])}`;\n\n if (options?.cache !== false) {\n return this.cached(\n cacheKey,\n () => this._client!.$queryRawUnsafe(sql, ...(values || [])),\n options?.ttl\n );\n }\n\n return this._client!.$queryRawUnsafe(sql, ...(values || []));\n }\n\n /**\n * Execute a mutation and invalidate cache\n */\n async executeRaw(\n sql: string,\n values?: any[],\n options?: {\n invalidatePattern?: string;\n }\n ): Promise<number> {\n if (!this._client) {\n throw new Error('Prisma client not initialized. Call connect() first.');\n }\n\n const result = await this._client.$executeRawUnsafe(sql, ...(values || []));\n\n // Invalidate cache if pattern provided\n if (options?.invalidatePattern) {\n await this.invalidateCache(options.invalidatePattern);\n }\n\n return result;\n }\n}\n"],"mappings":";AAAA,OAAO,UAAU;AAGjB,IAAM,QAAQ,QAAQ,IAAI,aAAa;AACvC,IAAM,WAAW,QAAQ,IAAI,cAAc,QAAQ,UAAU;AAG7D,IAAM,cAAc;AAAA,EAClB,KAAK,CAAC,QAAa;AACjB,QAAI,CAAC,IAAK,QAAO;AACjB,WAAO;AAAA,MACL,MAAM,IAAI,aAAa,QAAQ,IAAI;AAAA,MACnC,SAAS,IAAI;AAAA,MACb,OAAO,IAAI;AAAA,MACX,MAAM,IAAI;AAAA,MACV,YAAY,IAAI;AAAA,IAClB;AAAA,EACF;AAAA,EACA,KAAK,CAAC,QAAiB;AACrB,QAAI,CAAC,IAAK,QAAO;AACjB,WAAO;AAAA,MACL,QAAQ,IAAI;AAAA,MACZ,KAAK,IAAI;AAAA,MACT,SAAS,OAAO,YAAY,IAAI,QAAQ,QAAQ,CA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