@geekmidas/constructs 3.0.11 → 3.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/dist/{Construct-B14miJ6P.cjs → Construct-DXfLPGwg.cjs} +5 -42
- package/dist/{Construct-B14miJ6P.cjs.map → Construct-DXfLPGwg.cjs.map} +1 -1
- package/dist/{HonoEndpointAdaptor-DhphPq5r.cjs → HonoEndpointAdaptor-DFdgCwYU.cjs} +16 -16
- package/dist/{HonoEndpointAdaptor-DhphPq5r.cjs.map → HonoEndpointAdaptor-DFdgCwYU.cjs.map} +1 -1
- package/dist/adaptors/aws.cjs +13 -12
- package/dist/adaptors/aws.cjs.map +1 -1
- package/dist/adaptors/hono.cjs +5 -5
- package/dist/adaptors/testing.cjs +12 -11
- package/dist/adaptors/testing.cjs.map +1 -1
- package/dist/adaptors/trpc.cjs +65 -0
- package/dist/adaptors/trpc.cjs.map +1 -0
- package/dist/adaptors/trpc.d.cts +85 -0
- package/dist/adaptors/trpc.d.cts.map +1 -0
- package/dist/adaptors/trpc.d.mts +85 -0
- package/dist/adaptors/trpc.d.mts.map +1 -0
- package/dist/adaptors/trpc.mjs +63 -0
- package/dist/adaptors/trpc.mjs.map +1 -0
- package/dist/chunk-DWy1uDak.cjs +39 -0
- package/dist/crons/index.cjs +5 -4
- package/dist/crons/index.cjs.map +1 -1
- package/dist/endpoints/index.cjs +7 -6
- package/dist/endpoints/index.cjs.map +1 -1
- package/dist/functions/index.cjs +2 -2
- package/dist/{functions-DiaRAdfp.cjs → functions-CX21wstW.cjs} +11 -10
- package/dist/{functions-DiaRAdfp.cjs.map → functions-CX21wstW.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/{lazyAccessors-Bc1u42WC.cjs → lazyAccessors-zNy6P6Cg.cjs} +11 -10
- package/dist/{lazyAccessors-Bc1u42WC.cjs.map → lazyAccessors-zNy6P6Cg.cjs.map} +1 -1
- package/dist/{processAudits-CUko08pi.cjs → processAudits-B_a9bDPs.cjs} +3 -3
- package/dist/{processAudits-CUko08pi.cjs.map → processAudits-B_a9bDPs.cjs.map} +1 -1
- package/dist/subscribers/index.cjs +3 -2
- package/dist/subscribers/index.cjs.map +1 -1
- package/package.json +109 -49
- package/src/adaptors/__tests__/trpc.spec.ts +213 -0
- package/src/adaptors/trpc.ts +192 -0
- package/tsdown.config.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.cjs","names":["endpoints: Endpoint<any, any, any, any, any, any>[]","options: CreateMswHandlersOptions","id: string","ctxOptions: RegisterContextOptions","EnvironmentParser","ServiceDiscovery","serviceDefs: Service[]","handlers: HttpHandler[]","http","Hono","name: string","value: string","options?: CookieOptions","_endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditAction,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>","EnvironmentParser","endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditAction,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>","serviceDiscovery: ServiceDiscovery<any>","ctx: TestRequestAdaptor<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>","ForbiddenError","auditContext: AuditExecutionContext<TAuditAction> | undefined","actor: AuditActor","DefaultAuditor","ResponseBuilder","metadata","output","result","headers: Record<string, string | string[]>","setCookieValues: string[]","cookie","_fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tany\n\t\t>","EnvironmentParser","fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tany\n\t\t>","serviceDiscovery: ServiceDiscovery<any>","ctx: TestFunctionRequest<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTDatabase,\n\t\t\tTAuditAction\n\t\t>","services: ServiceRecord<TServices>","db: TDatabase | undefined","auditor: Auditor<TAuditAction> | undefined","DefaultAuditor","EnvironmentParser","subscriber: Subscriber<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTSubscribedEvents\n\t\t>","serviceDiscovery: ServiceDiscovery<any>","request: TestSubscriberRequest<\n\t\t\tTEventPublisher,\n\t\t\tTSubscribedEvents,\n\t\t\tTServices\n\t\t>","services: ServiceRecord<TServices>","output: any","events: ExtractEventPayloads<TEventPublisher, TSubscribedEvents>[]","event: any"],"sources":["../../src/endpoints/MswEndpointAdaptor.ts","../../src/endpoints/TestEndpointAdaptor.ts","../../src/functions/TestFunctionAdaptor.ts","../../src/subscribers/TestSubscriberAdaptor.ts"],"sourcesContent":["import { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Service } from '@geekmidas/services';\nimport { ServiceDiscovery } from '@geekmidas/services';\nimport { Hono } from 'hono';\nimport { type HttpHandler, http } from 'msw';\nimport type { Endpoint } from './Endpoint';\nimport { HonoEndpoint } from './HonoEndpointAdaptor';\n\n/**\n * Header used to identify which test context a request belongs to.\n * Each concurrent test registers its own context (services, db transaction, etc.)\n * and the MSW handler looks it up by this header value.\n */\nexport const TEST_CONTEXT_HEADER = 'x-test-context-id';\n\n/**\n * Per-test context containing an isolated ServiceDiscovery instance.\n * Registered in the context map and looked up per-request via the context ID header.\n */\nexport interface MswTestContext {\n\tserviceDiscovery: ServiceDiscovery<any>;\n}\n\n/**\n * Options for creating MSW handlers from endpoint constructs.\n *\n * @example\n * ```typescript\n * import { createMswHandlers, registerTestContext } from '@geekmidas/constructs/testing';\n * import { setupServer } from 'msw/node';\n *\n * // Create handlers once (global)\n * const { handlers, registerContext, removeContext } = createMswHandlers(\n * [getUsers, createUser],\n * { baseURL: 'http://localhost:3000' },\n * );\n * const server = setupServer(...handlers);\n *\n * // Per test: register an isolated context with its own services/transaction\n * it('should list users', async ({ db }) => {\n * const contextId = crypto.randomUUID();\n * registerContext(contextId, {\n * services: { database: db, auth: mockAuth },\n * });\n *\n * const api = createApi({\n * baseURL: 'http://localhost:3000',\n * headers: { [TEST_CONTEXT_HEADER]: contextId },\n * });\n *\n * const result = await api('GET /users');\n * expect(result).toBeDefined();\n *\n * removeContext(contextId);\n * });\n * ```\n */\nexport interface CreateMswHandlersOptions {\n\t/** Base URL the client fetches from (e.g., 'http://localhost:3000') */\n\tbaseURL: string;\n}\n\n/**\n * Options for registering a per-test context.\n * Follows the same pattern as TestRequestAdaptor — services, database,\n * publisher, and auditorStorage are provided explicitly.\n */\nexport interface RegisterContextOptions {\n\t/** Service instances keyed by serviceName */\n\tservices?: Record<string, unknown>;\n\t/** Database instance — required when endpoints use .database() */\n\tdatabase?: unknown;\n\t/** Event publisher service definition */\n\tpublisher?: Service;\n\t/** Audit storage instance — required when endpoints use .auditor() */\n\tauditorStorage?: unknown;\n}\n\nconst MSW_HTTP_METHODS = [\n\t'get',\n\t'post',\n\t'put',\n\t'patch',\n\t'delete',\n\t'options',\n] as const;\n\ntype MswHttpMethod = (typeof MSW_HTTP_METHODS)[number];\n\n/**\n * Result of creating MSW handlers from endpoint constructs.\n */\nexport interface CreateMswHandlersResult {\n\t/** MSW handlers to pass to setupServer() */\n\thandlers: HttpHandler[];\n\t/** Register an isolated context for a test */\n\tregisterContext: (id: string, options: RegisterContextOptions) => void;\n}\n\n/**\n * Creates MSW HTTP handlers from endpoint constructs.\n *\n * Mounts endpoints on a Hono app and creates MSW handlers that intercept\n * fetch requests and route them through `app.request()` — giving frontend\n * tests full endpoint behavior (validation, auth, sessions) without HTTP.\n *\n * Each test registers its own isolated context via `registerContext()`,\n * which is resolved per-request using the `x-test-context-id` header.\n * This allows concurrent tests with their own transactions and services.\n *\n * @param endpoints - Array of endpoint constructs to create handlers for\n * @param options - Configuration including baseURL\n * @returns MSW handlers, the Hono app, and context management functions\n */\nexport function createMswHandlers(\n\tendpoints: Endpoint<any, any, any, any, any, any>[],\n\toptions: CreateMswHandlersOptions,\n): CreateMswHandlersResult {\n\tconst { baseURL } = options;\n\tconst contexts = new Map<string, MswTestContext>();\n\n\t/**\n\t * Register an isolated context for a test.\n\t * Creates a fresh ServiceDiscovery and pre-registers all provided services.\n\t */\n\tfunction registerContext(id: string, ctxOptions: RegisterContextOptions) {\n\t\tconst envParser = new EnvironmentParser({});\n\t\tconst serviceDiscovery = new ServiceDiscovery(envParser);\n\n\t\tconst serviceDefs: Service[] = [];\n\n\t\t// Register explicit services\n\t\tif (ctxOptions.services) {\n\t\t\tfor (const [name, instance] of Object.entries(ctxOptions.services)) {\n\t\t\t\tserviceDefs.push({\n\t\t\t\t\tserviceName: name,\n\t\t\t\t\tregister: () => instance,\n\t\t\t\t} as Service);\n\t\t\t}\n\t\t}\n\n\t\t// Register database service from endpoint metadata\n\t\tif (ctxOptions.database !== undefined) {\n\t\t\tfor (const endpoint of endpoints) {\n\t\t\t\tif (endpoint.databaseService) {\n\t\t\t\t\tserviceDefs.push({\n\t\t\t\t\t\tserviceName: endpoint.databaseService.serviceName,\n\t\t\t\t\t\tregister: () => ctxOptions.database,\n\t\t\t\t\t} as Service);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Register publisher service\n\t\tif (ctxOptions.publisher) {\n\t\t\tserviceDefs.push(ctxOptions.publisher);\n\t\t}\n\n\t\t// Register auditor storage service from endpoint metadata\n\t\tif (ctxOptions.auditorStorage !== undefined) {\n\t\t\tfor (const endpoint of endpoints) {\n\t\t\t\tif (endpoint.auditorStorageService) {\n\t\t\t\t\tserviceDefs.push({\n\t\t\t\t\t\tserviceName: endpoint.auditorStorageService.serviceName,\n\t\t\t\t\t\tregister: () => ctxOptions.auditorStorage,\n\t\t\t\t\t} as Service);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (serviceDefs.length > 0) {\n\t\t\tserviceDiscovery.register(serviceDefs);\n\t\t}\n\n\t\tcontexts.set(id, { serviceDiscovery });\n\t}\n\n\t// Create a Hono app per-request that uses the correct ServiceDiscovery.\n\t// We use a wrapper app that resolves the context from the header,\n\t// then delegates to a context-specific Hono app.\n\tconst handlers: HttpHandler[] = [];\n\n\tfor (const endpoint of endpoints) {\n\t\tconst method = endpoint.method.toLowerCase() as MswHttpMethod;\n\t\tif (!MSW_HTTP_METHODS.includes(method)) continue;\n\n\t\tconst mswUrl = `${baseURL}${endpoint.route}`;\n\t\tconst mswMethod = http[method];\n\n\t\thandlers.push(\n\t\t\tmswMethod(mswUrl, async ({ request }) => {\n\t\t\t\tconst contextId = request.headers.get(TEST_CONTEXT_HEADER);\n\t\t\t\tconst ctx = contextId ? contexts.get(contextId) : undefined;\n\n\t\t\t\tif (!ctx) {\n\t\t\t\t\treturn new Response(\n\t\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\t\terror: 'Missing or unknown test context ID',\n\t\t\t\t\t\t\thint: `Set the '${TEST_CONTEXT_HEADER}' header to a registered context ID`,\n\t\t\t\t\t\t}),\n\t\t\t\t\t\t{ status: 500, headers: { 'content-type': 'application/json' } },\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Build a fresh Hono app with this context's ServiceDiscovery\n\t\t\t\tconst app = new Hono();\n\t\t\t\tHonoEndpoint.addRoute(endpoint, ctx.serviceDiscovery as any, app);\n\n\t\t\t\tconst response = await app.request(request);\n\n\t\t\t\treturn new Response(response.body, {\n\t\t\t\t\tstatus: response.status,\n\t\t\t\t\tstatusText: response.statusText,\n\t\t\t\t\theaders: response.headers,\n\t\t\t\t});\n\t\t\t}),\n\t\t);\n\t}\n\n\treturn {\n\t\thandlers,\n\t\tregisterContext,\n\t};\n}\n","import type {\n\tAuditActor,\n\tAuditableAction,\n\tAuditStorage,\n} from '@geekmidas/audit';\nimport { DefaultAuditor } from '@geekmidas/audit';\nimport { EnvironmentParser } from '@geekmidas/envkit';\nimport { ForbiddenError } from '@geekmidas/errors';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type {\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport {\n\trunWithRequestContext,\n\ttype Service,\n\tServiceDiscovery,\n\ttype ServiceRecord,\n} from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { publishConstructEvents } from '../publisher';\nimport type { HttpMethod } from '../types';\nimport type { MappedAudit } from './audit';\nimport {\n\ttype CookieOptions,\n\tEndpoint,\n\ttype EndpointSchemas,\n\tResponseBuilder,\n} from './Endpoint';\nimport {\n\tcreateCookieHeaderAccessor,\n\tcreateObjectHeaders,\n} from './lazyAccessors';\nimport {\n\ttype AuditExecutionContext,\n\texecuteWithAuditTransaction,\n} from './processAudits';\n\nexport type TestHttpResponse<TBody = any> = {\n\tbody: TBody;\n\tstatus: number;\n\theaders: Record<string, string | string[]>;\n};\n\n/**\n * Serializes a cookie into a Set-Cookie header string\n */\nfunction serializeCookie(\n\tname: string,\n\tvalue: string,\n\toptions?: CookieOptions,\n): string {\n\tlet cookieString = `${name}=${value}`;\n\n\tif (options) {\n\t\tif (options.maxAge !== undefined) {\n\t\t\tcookieString += `; Max-Age=${options.maxAge}`;\n\t\t}\n\t\tif (options.expires) {\n\t\t\tcookieString += `; Expires=${options.expires.toUTCString()}`;\n\t\t}\n\t\tif (options.domain) {\n\t\t\tcookieString += `; Domain=${options.domain}`;\n\t\t}\n\t\tif (options.path) {\n\t\t\tcookieString += `; Path=${options.path}`;\n\t\t}\n\t\tif (options.httpOnly) {\n\t\t\tcookieString += '; HttpOnly';\n\t\t}\n\t\tif (options.secure) {\n\t\t\tcookieString += '; Secure';\n\t\t}\n\t\tif (options.sameSite) {\n\t\t\tcookieString += `; SameSite=${options.sameSite}`;\n\t\t}\n\t}\n\n\treturn cookieString;\n}\n\nexport class TestEndpointAdaptor<\n\tTRoute extends string,\n\tTMethod extends HttpMethod,\n\tTInput extends EndpointSchemas = {},\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> {\n\tstatic getDefaultServiceDiscover<\n\t\tTRoute extends string,\n\t\tTMethod extends HttpMethod,\n\t\tTInput extends EndpointSchemas = {},\n\t\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\t\tTServices extends Service[] = [],\n\t\tTLogger extends Logger = Logger,\n\t\tTSession = unknown,\n\t\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\t\tTEventPublisherServiceName extends string = string,\n\t\tTAuditStorage extends AuditStorage | undefined = undefined,\n\t\tTAuditStorageServiceName extends string = string,\n\t\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\t\tstring,\n\t\t\tunknown\n\t\t>,\n\t\tTDatabase = undefined,\n\t\tTDatabaseServiceName extends string = string,\n\t>(\n\t\t_endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditAction,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>,\n\t) {\n\t\treturn ServiceDiscovery.getInstance(new EnvironmentParser({}));\n\t}\n\tconstructor(\n\t\tprivate readonly endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditAction,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>,\n\t\tprivate serviceDiscovery: ServiceDiscovery<any> = TestEndpointAdaptor.getDefaultServiceDiscover(\n\t\t\tendpoint,\n\t\t),\n\t) {}\n\n\tasync fullRequest(\n\t\tctx: TestRequestAdaptor<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>,\n\t): Promise<TestHttpResponse<InferStandardSchema<TOutSchema>>> {\n\t\tconst body = await this.endpoint.parseInput((ctx as any).body, 'body');\n\t\tconst query = await this.endpoint.parseInput((ctx as any).query, 'query');\n\t\tconst params = await this.endpoint.parseInput(\n\t\t\t(ctx as any).params,\n\t\t\t'params',\n\t\t);\n\n\t\t// Lazy accessors - defer parsing until needed\n\t\tconst header = createObjectHeaders(ctx.headers);\n\t\tconst cookie = createCookieHeaderAccessor(ctx.headers.cookie);\n\n\t\t// Request context setup\n\t\tconst startTime = Date.now();\n\t\tconst requestId =\n\t\t\t(ctx as any).requestId ??\n\t\t\tctx.headers['x-request-id'] ??\n\t\t\tcrypto.randomUUID();\n\n\t\tconst logger = this.endpoint.logger.child({\n\t\t\trequestId,\n\t\t\troute: this.endpoint.route,\n\t\t\thost: ctx.headers.host,\n\t\t\tmethod: this.endpoint.method,\n\t\t}) as TLogger;\n\n\t\t// Get database from context for session extraction\n\t\tconst rawDb = (ctx as any).database as TDatabase;\n\n\t\t// Wrap handler execution in request context\n\t\treturn runWithRequestContext({ logger, requestId, startTime }, async () => {\n\t\t\tconst session = await this.endpoint.getSession({\n\t\t\t\tlogger,\n\t\t\t\tservices: ctx.services,\n\t\t\t\theader,\n\t\t\t\tcookie,\n\t\t\t\t...(rawDb !== undefined && { db: rawDb }),\n\t\t\t} as any);\n\n\t\t\t// Check authorization\n\t\t\tconst isAuthorized = await this.endpoint.authorize({\n\t\t\t\theader,\n\t\t\t\tcookie,\n\t\t\t\tservices: ctx.services,\n\t\t\t\tlogger,\n\t\t\t\tsession,\n\t\t\t\t...(rawDb !== undefined && { db: rawDb }),\n\t\t\t\tbody,\n\t\t\t\tquery,\n\t\t\t\tparams,\n\t\t\t} as any);\n\n\t\t\tif (!isAuthorized) {\n\t\t\t\tlogger.warn('Forbidden access attempt');\n\t\t\t\tthrow new ForbiddenError(\n\t\t\t\t\t'Forbidden access to the endpoint',\n\t\t\t\t\t'You do not have permission to access this resource.',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Create audit context if audit storage is provided\n\t\t\t// The auditorStorage instance is required when endpoint uses .auditor()\n\t\t\tconst auditorStorage = (ctx as any).auditorStorage as TAuditStorage;\n\t\t\tlet auditContext: AuditExecutionContext<TAuditAction> | undefined;\n\n\t\t\tif (auditorStorage) {\n\t\t\t\t// Extract actor if configured\n\t\t\t\tlet actor: AuditActor = { id: 'system', type: 'system' };\n\t\t\t\tif (this.endpoint.actorExtractor) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tactor = await this.endpoint.actorExtractor({\n\t\t\t\t\t\t\tservices: ctx.services as any,\n\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t\theader,\n\t\t\t\t\t\t\tcookie,\n\t\t\t\t\t\t\tlogger,\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tlogger.error(error as Error, 'Failed to extract actor for audits');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst auditor = new DefaultAuditor<TAuditAction>({\n\t\t\t\t\tactor,\n\t\t\t\t\tstorage: auditorStorage as AuditStorage,\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tendpoint: this.endpoint.route,\n\t\t\t\t\t\tmethod: this.endpoint.method,\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tauditContext = { auditor, storage: auditorStorage as AuditStorage };\n\t\t\t}\n\n\t\t\t// Warn if declarative audits are configured but no audit storage\n\t\t\tconst audits = this.endpoint.audits as MappedAudit<\n\t\t\t\tTAuditAction,\n\t\t\t\tTOutSchema\n\t\t\t>[];\n\t\t\tif (!auditContext && audits?.length) {\n\t\t\t\tlogger.warn('No auditor storage service available');\n\t\t\t}\n\n\t\t\t// Execute handler with automatic audit transaction support\n\t\t\tconst result = await executeWithAuditTransaction(\n\t\t\t\tauditContext,\n\t\t\t\tasync (auditor) => {\n\t\t\t\t\t// Use audit transaction as db if available (when storage has same database)\n\t\t\t\t\t// For testing, the tester controls whether to use transactional auditing\n\t\t\t\t\tconst trx = auditor?.getTransaction?.();\n\t\t\t\t\tconst db = trx ?? rawDb;\n\n\t\t\t\t\tconst responseBuilder = new ResponseBuilder();\n\t\t\t\t\tconst response = await this.endpoint.handler(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbody,\n\t\t\t\t\t\t\tquery,\n\t\t\t\t\t\t\tparams,\n\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t\tservices: ctx.services,\n\t\t\t\t\t\t\tlogger,\n\t\t\t\t\t\t\theader,\n\t\t\t\t\t\t\tcookie,\n\t\t\t\t\t\t\tauditor,\n\t\t\t\t\t\t\tdb,\n\t\t\t\t\t\t} as any,\n\t\t\t\t\t\tresponseBuilder,\n\t\t\t\t\t);\n\n\t\t\t\t\t// Check if response has metadata\n\t\t\t\t\tlet data = response;\n\t\t\t\t\tlet metadata = responseBuilder.getMetadata();\n\n\t\t\t\t\tif (Endpoint.hasMetadata(response)) {\n\t\t\t\t\t\tdata = response.data;\n\t\t\t\t\t\tmetadata = response.metadata;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst output = await this.endpoint.parseOutput(data);\n\n\t\t\t\t\treturn { output, metadata, responseBuilder };\n\t\t\t\t},\n\t\t\t\t// Process declarative audits after handler (inside transaction)\n\t\t\t\tasync (result, auditor) => {\n\t\t\t\t\tif (!audits?.length) return;\n\n\t\t\t\t\tfor (const audit of audits) {\n\t\t\t\t\t\tif (audit.when && !audit.when(result.output as any)) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst payload = audit.payload(result.output as any);\n\t\t\t\t\t\tconst entityId = audit.entityId?.(result.output as any);\n\t\t\t\t\t\tauditor.audit(audit.type as any, payload as any, {\n\t\t\t\t\t\t\ttable: audit.table,\n\t\t\t\t\t\t\tentityId,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t// Pass rawDb so storage can reuse existing transactions\n\t\t\t\t{ db: rawDb },\n\t\t\t);\n\n\t\t\tconst { output, metadata } = result;\n\n\t\t\tctx.publisher && (await this.serviceDiscovery.register([ctx.publisher]));\n\t\t\tawait publishConstructEvents(\n\t\t\t\tthis.endpoint,\n\t\t\t\toutput,\n\t\t\t\tthis.serviceDiscovery,\n\t\t\t);\n\n\t\t\t// Convert cookies to Set-Cookie headers\n\t\t\tconst headers: Record<string, string | string[]> = {\n\t\t\t\t...(metadata.headers || {}),\n\t\t\t};\n\n\t\t\tif (metadata.cookies && metadata.cookies.size > 0) {\n\t\t\t\tconst setCookieValues: string[] = [];\n\t\t\t\tfor (const [name, cookie] of metadata.cookies.entries()) {\n\t\t\t\t\tsetCookieValues.push(\n\t\t\t\t\t\tserializeCookie(name, cookie.value, cookie.options),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\theaders['set-cookie'] = setCookieValues;\n\t\t\t}\n\n\t\t\t// Return HTTP response format\n\t\t\treturn {\n\t\t\t\tbody: output,\n\t\t\t\tstatus: metadata.status || 200,\n\t\t\t\theaders,\n\t\t\t};\n\t\t});\n\t}\n\n\tasync request(\n\t\tctx: TestRequestAdaptor<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>,\n\t): Promise<InferStandardSchema<TOutSchema>> {\n\t\tconst response = await this.fullRequest(ctx);\n\t\treturn response.body;\n\t}\n}\n\n/**\n * Conditional audit storage requirement - required when TAuditStorage is configured\n */\ntype AuditStorageRequirement<\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n> = TAuditStorage extends undefined\n\t? {}\n\t: {\n\t\t\t/** Audit storage instance - required when endpoint uses .auditor() */\n\t\t\tauditorStorage: TAuditStorage;\n\t\t};\n\n/**\n * Conditional database requirement - required when TDatabase is configured\n */\ntype DatabaseRequirement<TDatabase = undefined> = TDatabase extends undefined\n\t? {}\n\t: {\n\t\t\t/** Database instance - required when endpoint uses .database() */\n\t\t\tdatabase: TDatabase;\n\t\t};\n\nexport type TestRequestAdaptor<\n\tTInput extends EndpointSchemas = {},\n\tTServices extends Service[] = [],\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\t_TAuditStorageServiceName extends string = string,\n\tTDatabase = undefined,\n\t_TDatabaseServiceName extends string = string,\n> = {\n\tservices: ServiceRecord<TServices>;\n\theaders: Record<string, string>;\n\tpublisher?: Service<TEventPublisherServiceName, TEventPublisher>;\n} & InferComposableStandardSchema<TInput> &\n\tAuditStorageRequirement<TAuditStorage> &\n\tDatabaseRequirement<TDatabase>;\n","import type { AuditableAction, Auditor, AuditStorage } from '@geekmidas/audit';\nimport { DefaultAuditor } from '@geekmidas/audit';\nimport { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type {\n\tComposableStandardSchema,\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport {\n\trunWithRequestContext,\n\ttype Service,\n\tServiceDiscovery,\n\ttype ServiceRecord,\n} from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { publishEvents } from '../publisher';\nimport type { Function } from './Function';\nimport { FunctionBuilder } from './FunctionBuilder';\n\nexport class TestFunctionAdaptor<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> {\n\tstatic getDefaultServiceDiscovery<\n\t\tTInput extends ComposableStandardSchema | undefined = undefined,\n\t\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\t\tTServices extends Service[] = [],\n\t\tTLogger extends Logger = Logger,\n\t\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\t\tTEventPublisherServiceName extends string = string,\n\t\tTAuditStorage extends AuditStorage | undefined = undefined,\n\t\tTAuditStorageServiceName extends string = string,\n\t\tTDatabase = undefined,\n\t\tTDatabaseServiceName extends string = string,\n\t\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\t\tstring,\n\t\t\tunknown\n\t\t>,\n\t>(\n\t\t_fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tany\n\t\t>,\n\t) {\n\t\treturn ServiceDiscovery.getInstance(new EnvironmentParser({}));\n\t}\n\n\tconstructor(\n\t\tprivate readonly fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tany\n\t\t>,\n\t\tprivate serviceDiscovery: ServiceDiscovery<any> = TestFunctionAdaptor.getDefaultServiceDiscovery(\n\t\t\tfn,\n\t\t),\n\t) {}\n\n\tasync invoke(\n\t\tctx: TestFunctionRequest<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTDatabase,\n\t\t\tTAuditAction\n\t\t>,\n\t): Promise<InferStandardSchema<TOutSchema>> {\n\t\t// Parse input if schema is provided\n\n\t\tconst parsedInput = await FunctionBuilder.parseComposableStandardSchema(\n\t\t\tctx.input,\n\t\t\tthis.fn.input,\n\t\t);\n\n\t\t// Create logger with context\n\t\tconst logger = this.fn.logger.child({\n\t\t\ttest: true,\n\t\t}) as TLogger;\n\n\t\t// Register services (use provided services or register from function)\n\t\tlet services: ServiceRecord<TServices>;\n\t\tif (ctx.services) {\n\t\t\tservices = ctx.services;\n\t\t} else {\n\t\t\tservices = await this.serviceDiscovery.register(this.fn.services);\n\t\t}\n\n\t\t// Resolve database (use provided db or register from function)\n\t\tlet db: TDatabase | undefined;\n\t\tif ('db' in ctx && ctx.db !== undefined) {\n\t\t\tdb = ctx.db;\n\t\t} else if (this.fn.databaseService) {\n\t\t\tconst dbServices = await this.serviceDiscovery.register([\n\t\t\t\tthis.fn.databaseService,\n\t\t\t]);\n\t\t\tdb = dbServices[\n\t\t\t\tthis.fn.databaseService.serviceName as keyof typeof dbServices\n\t\t\t] as TDatabase;\n\t\t}\n\n\t\t// Resolve auditor (use provided auditor or create from function)\n\t\tlet auditor: Auditor<TAuditAction> | undefined;\n\t\tif ('auditor' in ctx && ctx.auditor !== undefined) {\n\t\t\tauditor = ctx.auditor;\n\t\t} else if (this.fn.auditorStorageService) {\n\t\t\tconst auditServices = await this.serviceDiscovery.register([\n\t\t\t\tthis.fn.auditorStorageService,\n\t\t\t]);\n\t\t\tconst storage = auditServices[\n\t\t\t\tthis.fn.auditorStorageService.serviceName as keyof typeof auditServices\n\t\t\t] as AuditStorage;\n\n\t\t\tauditor = new DefaultAuditor<TAuditAction>({\n\t\t\t\tactor: { id: 'system', type: 'system' },\n\t\t\t\tstorage,\n\t\t\t\tmetadata: {\n\t\t\t\t\tfunction: this.fn.type,\n\t\t\t\t\ttest: true,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Wrap execution in request context for service access via context.getLogger()\n\t\tconst requestId = `test-${Date.now()}`;\n\t\tconst startTime = Date.now();\n\n\t\treturn runWithRequestContext({ logger, requestId, startTime }, async () => {\n\t\t\t// Execute the function\n\t\t\tconst response = await this.fn.fn({\n\t\t\t\tinput: parsedInput,\n\t\t\t\tservices,\n\t\t\t\tlogger,\n\t\t\t\tdb,\n\t\t\t\tauditor,\n\t\t\t} as any);\n\n\t\t\t// Parse output if schema is provided\n\t\t\tconst output = await this.fn.parseOutput(response);\n\n\t\t\t// Flush audits if any were recorded\n\t\t\tif (auditor) {\n\t\t\t\tconst records = auditor.getRecords();\n\t\t\t\tif (records.length > 0) {\n\t\t\t\t\tlogger.debug(\n\t\t\t\t\t\t{ auditCount: records.length },\n\t\t\t\t\t\t'Flushing function audits',\n\t\t\t\t\t);\n\t\t\t\t\tawait auditor.flush();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Register publisher service if provided in context\n\n\t\t\tawait publishEvents(\n\t\t\t\tlogger,\n\t\t\t\tthis.serviceDiscovery,\n\t\t\t\tthis.fn.events,\n\t\t\t\toutput,\n\t\t\t\tthis.fn.publisherService,\n\t\t\t);\n\n\t\t\treturn output;\n\t\t}) as Promise<InferStandardSchema<TOutSchema>>;\n\t}\n}\n\nexport type TestFunctionRequest<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTDatabase = undefined,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> = {\n\tinput: InferComposableStandardSchema<TInput>;\n\tservices: ServiceRecord<TServices>;\n\tpublisher?: Service<TEventPublisherServiceName, TEventPublisher>;\n\tdb?: TDatabase;\n\tauditor?: Auditor<TAuditAction>;\n} & InferComposableStandardSchema<{ input: TInput }>;\n","import { EnvironmentParser } from '@geekmidas/envkit';\nimport type {\n\tEventPublisher,\n\tExtractPublisherMessage,\n} from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport { runWithRequestContext, ServiceDiscovery } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { publishEvents } from '../publisher';\nimport type { Subscriber } from './Subscriber';\n\n// Helper type to extract payload types for subscribed events\ntype ExtractEventPayloads<\n\tTPublisher extends EventPublisher<any> | undefined,\n\tTEventTypes extends any[],\n> = TPublisher extends EventPublisher<any>\n\t? Extract<ExtractPublisherMessage<TPublisher>, { type: TEventTypes[number] }>\n\t: never;\n\nexport class TestSubscriberAdaptor<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTSubscribedEvents extends\n\t\tExtractPublisherMessage<TEventPublisher>['type'][] = ExtractPublisherMessage<TEventPublisher>['type'][],\n> {\n\tstatic getDefaultServiceDiscovery() {\n\t\treturn ServiceDiscovery.getInstance(new EnvironmentParser({}));\n\t}\n\n\tconstructor(\n\t\tprivate readonly subscriber: Subscriber<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTSubscribedEvents\n\t\t>,\n\t\tprivate serviceDiscovery: ServiceDiscovery<any> = TestSubscriberAdaptor.getDefaultServiceDiscovery(),\n\t) {}\n\n\tasync invoke(\n\t\trequest: TestSubscriberRequest<\n\t\t\tTEventPublisher,\n\t\t\tTSubscribedEvents,\n\t\t\tTServices\n\t\t>,\n\t): Promise<InferStandardSchema<OutSchema>> {\n\t\t// Create logger with test context\n\t\tconst logger = this.subscriber.logger.child({\n\t\t\ttest: true,\n\t\t}) as TLogger;\n\n\t\t// Resolve services (use provided or auto-register)\n\t\tlet services: ServiceRecord<TServices>;\n\t\tif (request.services) {\n\t\t\tservices = request.services;\n\t\t} else {\n\t\t\tservices = await this.serviceDiscovery.register(this.subscriber.services);\n\t\t}\n\n\t\t// Filter events to only subscribed types\n\t\tconst filteredEvents = this.filterEvents(request.events);\n\n\t\t// Return early if no events after filtering (mirrors AWSLambdaSubscriber)\n\t\tif (filteredEvents.length === 0) {\n\t\t\treturn { batchItemFailures: [] } as any;\n\t\t}\n\n\t\t// Wrap execution in request context for service access via context.getLogger()\n\t\tconst requestId = `test-${Date.now()}`;\n\t\tconst startTime = Date.now();\n\n\t\treturn runWithRequestContext({ logger, requestId, startTime }, async () => {\n\t\t\t// Execute the subscriber handler\n\t\t\tconst result = await this.subscriber.handler({\n\t\t\t\tevents: filteredEvents,\n\t\t\t\tservices,\n\t\t\t\tlogger,\n\t\t\t});\n\n\t\t\t// Validate output if schema is provided\n\t\t\tlet output: any = result;\n\t\t\tif (this.subscriber.outputSchema && result) {\n\t\t\t\tconst validationResult =\n\t\t\t\t\tawait this.subscriber.outputSchema['~standard'].validate(result);\n\n\t\t\t\tif (validationResult.issues) {\n\t\t\t\t\tthrow new Error('Subscriber output validation failed');\n\t\t\t\t}\n\n\t\t\t\toutput = validationResult.value;\n\t\t\t}\n\n\t\t\t// Publish events if configured\n\t\t\tawait publishEvents(\n\t\t\t\tlogger,\n\t\t\t\tthis.serviceDiscovery,\n\t\t\t\tthis.subscriber.events,\n\t\t\t\toutput,\n\t\t\t\tthis.subscriber.publisherService,\n\t\t\t);\n\n\t\t\treturn output;\n\t\t}) as Promise<InferStandardSchema<OutSchema>>;\n\t}\n\n\tprivate filterEvents(\n\t\tevents: ExtractEventPayloads<TEventPublisher, TSubscribedEvents>[],\n\t): ExtractEventPayloads<TEventPublisher, TSubscribedEvents>[] {\n\t\tif (!this.subscriber.subscribedEvents) {\n\t\t\treturn events;\n\t\t}\n\n\t\treturn events.filter((event: any) =>\n\t\t\tthis.subscriber.subscribedEvents!.includes(event.type),\n\t\t);\n\t}\n}\n\nexport type TestSubscriberRequest<\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTSubscribedEvents extends any[] = [],\n\tTServices extends Service[] = [],\n> = {\n\tevents: ExtractEventPayloads<TEventPublisher, TSubscribedEvents>[];\n\tservices?: ServiceRecord<TServices>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAaA,MAAa,sBAAsB;AAiEnC,MAAM,mBAAmB;CACxB;CACA;CACA;CACA;CACA;CACA;AACA;;;;;;;;;;;;;;;;AA6BD,SAAgB,kBACfA,WACAC,SAC0B;CAC1B,MAAM,EAAE,SAAS,GAAG;CACpB,MAAM,2BAAW,IAAI;;;;;CAMrB,SAAS,gBAAgBC,IAAYC,YAAoC;EACxE,MAAM,YAAY,IAAIC,qCAAkB,CAAE;EAC1C,MAAM,mBAAmB,IAAIC,sCAAiB;EAE9C,MAAMC,cAAyB,CAAE;AAGjC,MAAI,WAAW,SACd,MAAK,MAAM,CAAC,MAAM,SAAS,IAAI,OAAO,QAAQ,WAAW,SAAS,CACjE,aAAY,KAAK;GAChB,aAAa;GACb,UAAU,MAAM;EAChB,EAAY;AAKf,MAAI,WAAW,qBACd;QAAK,MAAM,YAAY,UACtB,KAAI,SAAS,iBAAiB;AAC7B,gBAAY,KAAK;KAChB,aAAa,SAAS,gBAAgB;KACtC,UAAU,MAAM,WAAW;IAC3B,EAAY;AACb;GACA;EACD;AAIF,MAAI,WAAW,UACd,aAAY,KAAK,WAAW,UAAU;AAIvC,MAAI,WAAW,2BACd;QAAK,MAAM,YAAY,UACtB,KAAI,SAAS,uBAAuB;AACnC,gBAAY,KAAK;KAChB,aAAa,SAAS,sBAAsB;KAC5C,UAAU,MAAM,WAAW;IAC3B,EAAY;AACb;GACA;EACD;AAGF,MAAI,YAAY,SAAS,EACxB,kBAAiB,SAAS,YAAY;AAGvC,WAAS,IAAI,IAAI,EAAE,iBAAkB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K0C;EAE1C,MAAM,SAAS,KAAK,WAAW,OAAO,MAAM,EAC3C,MAAM,KACN,EAAC;EAGF,IAAIC;AACJ,MAAI,QAAQ,SACX,YAAW,QAAQ;MAEnB,YAAW,MAAM,KAAK,iBAAiB,SAAS,KAAK,WAAW,SAAS;EAI1E,MAAM,iBAAiB,KAAK,aAAa,QAAQ,OAAO;AAGxD,MAAI,eAAe,WAAW,EAC7B,QAAO,EAAE,mBAAmB,CAAE,EAAE;EAIjC,MAAM,aAAa,OAAO,KAAK,KAAK,CAAC;EACrC,MAAM,YAAY,KAAK,KAAK;AAE5B,SAAO,gDAAsB;GAAE;GAAQ;GAAW;EAAW,GAAE,YAAY;GAE1E,MAAM,SAAS,MAAM,KAAK,WAAW,QAAQ;IAC5C,QAAQ;IACR;IACA;GACA,EAAC;GAGF,IAAIC,SAAc;AAClB,OAAI,KAAK,WAAW,gBAAgB,QAAQ;IAC3C,MAAM,mBACL,MAAM,KAAK,WAAW,aAAa,aAAa,SAAS,OAAO;AAEjE,QAAI,iBAAiB,OACpB,OAAM,IAAI,MAAM;AAGjB,aAAS,iBAAiB;GAC1B;AAGD,SAAM,oCACL,QACA,KAAK,kBACL,KAAK,WAAW,QAChB,QACA,KAAK,WAAW,iBAChB;AAED,UAAO;EACP,EAAC;CACF;CAED,AAAQ,aACPC,QAC6D;AAC7D,OAAK,KAAK,WAAW,iBACpB,QAAO;AAGR,SAAO,OAAO,OAAO,CAACC,UACrB,KAAK,WAAW,iBAAkB,SAAS,MAAM,KAAK,CACtD;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"testing.cjs","names":["endpoints: Endpoint<any, any, any, any, any, any>[]","options: CreateMswHandlersOptions","id: string","ctxOptions: RegisterContextOptions","EnvironmentParser","ServiceDiscovery","serviceDefs: Service[]","handlers: HttpHandler[]","http","Hono","name: string","value: string","options?: CookieOptions","_endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditAction,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>","EnvironmentParser","endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditAction,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>","serviceDiscovery: ServiceDiscovery<any>","ctx: TestRequestAdaptor<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>","ForbiddenError","auditContext: AuditExecutionContext<TAuditAction> | undefined","actor: AuditActor","DefaultAuditor","ResponseBuilder","metadata","output","result","headers: Record<string, string | string[]>","setCookieValues: string[]","cookie","_fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tany\n\t\t>","EnvironmentParser","fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tany\n\t\t>","serviceDiscovery: ServiceDiscovery<any>","ctx: TestFunctionRequest<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTDatabase,\n\t\t\tTAuditAction\n\t\t>","services: ServiceRecord<TServices>","db: TDatabase | undefined","auditor: Auditor<TAuditAction> | undefined","DefaultAuditor","EnvironmentParser","subscriber: Subscriber<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTSubscribedEvents\n\t\t>","serviceDiscovery: ServiceDiscovery<any>","request: TestSubscriberRequest<\n\t\t\tTEventPublisher,\n\t\t\tTSubscribedEvents,\n\t\t\tTServices\n\t\t>","services: ServiceRecord<TServices>","output: any","events: ExtractEventPayloads<TEventPublisher, TSubscribedEvents>[]","event: any"],"sources":["../../src/endpoints/MswEndpointAdaptor.ts","../../src/endpoints/TestEndpointAdaptor.ts","../../src/functions/TestFunctionAdaptor.ts","../../src/subscribers/TestSubscriberAdaptor.ts"],"sourcesContent":["import { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Service } from '@geekmidas/services';\nimport { ServiceDiscovery } from '@geekmidas/services';\nimport { Hono } from 'hono';\nimport { type HttpHandler, http } from 'msw';\nimport type { Endpoint } from './Endpoint';\nimport { HonoEndpoint } from './HonoEndpointAdaptor';\n\n/**\n * Header used to identify which test context a request belongs to.\n * Each concurrent test registers its own context (services, db transaction, etc.)\n * and the MSW handler looks it up by this header value.\n */\nexport const TEST_CONTEXT_HEADER = 'x-test-context-id';\n\n/**\n * Per-test context containing an isolated ServiceDiscovery instance.\n * Registered in the context map and looked up per-request via the context ID header.\n */\nexport interface MswTestContext {\n\tserviceDiscovery: ServiceDiscovery<any>;\n}\n\n/**\n * Options for creating MSW handlers from endpoint constructs.\n *\n * @example\n * ```typescript\n * import { createMswHandlers, registerTestContext } from '@geekmidas/constructs/testing';\n * import { setupServer } from 'msw/node';\n *\n * // Create handlers once (global)\n * const { handlers, registerContext, removeContext } = createMswHandlers(\n * [getUsers, createUser],\n * { baseURL: 'http://localhost:3000' },\n * );\n * const server = setupServer(...handlers);\n *\n * // Per test: register an isolated context with its own services/transaction\n * it('should list users', async ({ db }) => {\n * const contextId = crypto.randomUUID();\n * registerContext(contextId, {\n * services: { database: db, auth: mockAuth },\n * });\n *\n * const api = createApi({\n * baseURL: 'http://localhost:3000',\n * headers: { [TEST_CONTEXT_HEADER]: contextId },\n * });\n *\n * const result = await api('GET /users');\n * expect(result).toBeDefined();\n *\n * removeContext(contextId);\n * });\n * ```\n */\nexport interface CreateMswHandlersOptions {\n\t/** Base URL the client fetches from (e.g., 'http://localhost:3000') */\n\tbaseURL: string;\n}\n\n/**\n * Options for registering a per-test context.\n * Follows the same pattern as TestRequestAdaptor — services, database,\n * publisher, and auditorStorage are provided explicitly.\n */\nexport interface RegisterContextOptions {\n\t/** Service instances keyed by serviceName */\n\tservices?: Record<string, unknown>;\n\t/** Database instance — required when endpoints use .database() */\n\tdatabase?: unknown;\n\t/** Event publisher service definition */\n\tpublisher?: Service;\n\t/** Audit storage instance — required when endpoints use .auditor() */\n\tauditorStorage?: unknown;\n}\n\nconst MSW_HTTP_METHODS = [\n\t'get',\n\t'post',\n\t'put',\n\t'patch',\n\t'delete',\n\t'options',\n] as const;\n\ntype MswHttpMethod = (typeof MSW_HTTP_METHODS)[number];\n\n/**\n * Result of creating MSW handlers from endpoint constructs.\n */\nexport interface CreateMswHandlersResult {\n\t/** MSW handlers to pass to setupServer() */\n\thandlers: HttpHandler[];\n\t/** Register an isolated context for a test */\n\tregisterContext: (id: string, options: RegisterContextOptions) => void;\n}\n\n/**\n * Creates MSW HTTP handlers from endpoint constructs.\n *\n * Mounts endpoints on a Hono app and creates MSW handlers that intercept\n * fetch requests and route them through `app.request()` — giving frontend\n * tests full endpoint behavior (validation, auth, sessions) without HTTP.\n *\n * Each test registers its own isolated context via `registerContext()`,\n * which is resolved per-request using the `x-test-context-id` header.\n * This allows concurrent tests with their own transactions and services.\n *\n * @param endpoints - Array of endpoint constructs to create handlers for\n * @param options - Configuration including baseURL\n * @returns MSW handlers, the Hono app, and context management functions\n */\nexport function createMswHandlers(\n\tendpoints: Endpoint<any, any, any, any, any, any>[],\n\toptions: CreateMswHandlersOptions,\n): CreateMswHandlersResult {\n\tconst { baseURL } = options;\n\tconst contexts = new Map<string, MswTestContext>();\n\n\t/**\n\t * Register an isolated context for a test.\n\t * Creates a fresh ServiceDiscovery and pre-registers all provided services.\n\t */\n\tfunction registerContext(id: string, ctxOptions: RegisterContextOptions) {\n\t\tconst envParser = new EnvironmentParser({});\n\t\tconst serviceDiscovery = new ServiceDiscovery(envParser);\n\n\t\tconst serviceDefs: Service[] = [];\n\n\t\t// Register explicit services\n\t\tif (ctxOptions.services) {\n\t\t\tfor (const [name, instance] of Object.entries(ctxOptions.services)) {\n\t\t\t\tserviceDefs.push({\n\t\t\t\t\tserviceName: name,\n\t\t\t\t\tregister: () => instance,\n\t\t\t\t} as Service);\n\t\t\t}\n\t\t}\n\n\t\t// Register database service from endpoint metadata\n\t\tif (ctxOptions.database !== undefined) {\n\t\t\tfor (const endpoint of endpoints) {\n\t\t\t\tif (endpoint.databaseService) {\n\t\t\t\t\tserviceDefs.push({\n\t\t\t\t\t\tserviceName: endpoint.databaseService.serviceName,\n\t\t\t\t\t\tregister: () => ctxOptions.database,\n\t\t\t\t\t} as Service);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Register publisher service\n\t\tif (ctxOptions.publisher) {\n\t\t\tserviceDefs.push(ctxOptions.publisher);\n\t\t}\n\n\t\t// Register auditor storage service from endpoint metadata\n\t\tif (ctxOptions.auditorStorage !== undefined) {\n\t\t\tfor (const endpoint of endpoints) {\n\t\t\t\tif (endpoint.auditorStorageService) {\n\t\t\t\t\tserviceDefs.push({\n\t\t\t\t\t\tserviceName: endpoint.auditorStorageService.serviceName,\n\t\t\t\t\t\tregister: () => ctxOptions.auditorStorage,\n\t\t\t\t\t} as Service);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (serviceDefs.length > 0) {\n\t\t\tserviceDiscovery.register(serviceDefs);\n\t\t}\n\n\t\tcontexts.set(id, { serviceDiscovery });\n\t}\n\n\t// Create a Hono app per-request that uses the correct ServiceDiscovery.\n\t// We use a wrapper app that resolves the context from the header,\n\t// then delegates to a context-specific Hono app.\n\tconst handlers: HttpHandler[] = [];\n\n\tfor (const endpoint of endpoints) {\n\t\tconst method = endpoint.method.toLowerCase() as MswHttpMethod;\n\t\tif (!MSW_HTTP_METHODS.includes(method)) continue;\n\n\t\tconst mswUrl = `${baseURL}${endpoint.route}`;\n\t\tconst mswMethod = http[method];\n\n\t\thandlers.push(\n\t\t\tmswMethod(mswUrl, async ({ request }) => {\n\t\t\t\tconst contextId = request.headers.get(TEST_CONTEXT_HEADER);\n\t\t\t\tconst ctx = contextId ? contexts.get(contextId) : undefined;\n\n\t\t\t\tif (!ctx) {\n\t\t\t\t\treturn new Response(\n\t\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\t\terror: 'Missing or unknown test context ID',\n\t\t\t\t\t\t\thint: `Set the '${TEST_CONTEXT_HEADER}' header to a registered context ID`,\n\t\t\t\t\t\t}),\n\t\t\t\t\t\t{ status: 500, headers: { 'content-type': 'application/json' } },\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Build a fresh Hono app with this context's ServiceDiscovery\n\t\t\t\tconst app = new Hono();\n\t\t\t\tHonoEndpoint.addRoute(endpoint, ctx.serviceDiscovery as any, app);\n\n\t\t\t\tconst response = await app.request(request);\n\n\t\t\t\treturn new Response(response.body, {\n\t\t\t\t\tstatus: response.status,\n\t\t\t\t\tstatusText: response.statusText,\n\t\t\t\t\theaders: response.headers,\n\t\t\t\t});\n\t\t\t}),\n\t\t);\n\t}\n\n\treturn {\n\t\thandlers,\n\t\tregisterContext,\n\t};\n}\n","import type {\n\tAuditActor,\n\tAuditableAction,\n\tAuditStorage,\n} from '@geekmidas/audit';\nimport { DefaultAuditor } from '@geekmidas/audit';\nimport { EnvironmentParser } from '@geekmidas/envkit';\nimport { ForbiddenError } from '@geekmidas/errors';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type {\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport {\n\trunWithRequestContext,\n\ttype Service,\n\tServiceDiscovery,\n\ttype ServiceRecord,\n} from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { publishConstructEvents } from '../publisher';\nimport type { HttpMethod } from '../types';\nimport type { MappedAudit } from './audit';\nimport {\n\ttype CookieOptions,\n\tEndpoint,\n\ttype EndpointSchemas,\n\tResponseBuilder,\n} from './Endpoint';\nimport {\n\tcreateCookieHeaderAccessor,\n\tcreateObjectHeaders,\n} from './lazyAccessors';\nimport {\n\ttype AuditExecutionContext,\n\texecuteWithAuditTransaction,\n} from './processAudits';\n\nexport type TestHttpResponse<TBody = any> = {\n\tbody: TBody;\n\tstatus: number;\n\theaders: Record<string, string | string[]>;\n};\n\n/**\n * Serializes a cookie into a Set-Cookie header string\n */\nfunction serializeCookie(\n\tname: string,\n\tvalue: string,\n\toptions?: CookieOptions,\n): string {\n\tlet cookieString = `${name}=${value}`;\n\n\tif (options) {\n\t\tif (options.maxAge !== undefined) {\n\t\t\tcookieString += `; Max-Age=${options.maxAge}`;\n\t\t}\n\t\tif (options.expires) {\n\t\t\tcookieString += `; Expires=${options.expires.toUTCString()}`;\n\t\t}\n\t\tif (options.domain) {\n\t\t\tcookieString += `; Domain=${options.domain}`;\n\t\t}\n\t\tif (options.path) {\n\t\t\tcookieString += `; Path=${options.path}`;\n\t\t}\n\t\tif (options.httpOnly) {\n\t\t\tcookieString += '; HttpOnly';\n\t\t}\n\t\tif (options.secure) {\n\t\t\tcookieString += '; Secure';\n\t\t}\n\t\tif (options.sameSite) {\n\t\t\tcookieString += `; SameSite=${options.sameSite}`;\n\t\t}\n\t}\n\n\treturn cookieString;\n}\n\nexport class TestEndpointAdaptor<\n\tTRoute extends string,\n\tTMethod extends HttpMethod,\n\tTInput extends EndpointSchemas = {},\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTSession = unknown,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> {\n\tstatic getDefaultServiceDiscover<\n\t\tTRoute extends string,\n\t\tTMethod extends HttpMethod,\n\t\tTInput extends EndpointSchemas = {},\n\t\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\t\tTServices extends Service[] = [],\n\t\tTLogger extends Logger = Logger,\n\t\tTSession = unknown,\n\t\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\t\tTEventPublisherServiceName extends string = string,\n\t\tTAuditStorage extends AuditStorage | undefined = undefined,\n\t\tTAuditStorageServiceName extends string = string,\n\t\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\t\tstring,\n\t\t\tunknown\n\t\t>,\n\t\tTDatabase = undefined,\n\t\tTDatabaseServiceName extends string = string,\n\t>(\n\t\t_endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditAction,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>,\n\t) {\n\t\treturn ServiceDiscovery.getInstance(new EnvironmentParser({}));\n\t}\n\tconstructor(\n\t\tprivate readonly endpoint: Endpoint<\n\t\t\tTRoute,\n\t\t\tTMethod,\n\t\t\tTInput,\n\t\t\tTOutSchema,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTSession,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditAction,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>,\n\t\tprivate serviceDiscovery: ServiceDiscovery<any> = TestEndpointAdaptor.getDefaultServiceDiscover(\n\t\t\tendpoint,\n\t\t),\n\t) {}\n\n\tasync fullRequest(\n\t\tctx: TestRequestAdaptor<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>,\n\t): Promise<TestHttpResponse<InferStandardSchema<TOutSchema>>> {\n\t\tconst body = await this.endpoint.parseInput((ctx as any).body, 'body');\n\t\tconst query = await this.endpoint.parseInput((ctx as any).query, 'query');\n\t\tconst params = await this.endpoint.parseInput(\n\t\t\t(ctx as any).params,\n\t\t\t'params',\n\t\t);\n\n\t\t// Lazy accessors - defer parsing until needed\n\t\tconst header = createObjectHeaders(ctx.headers);\n\t\tconst cookie = createCookieHeaderAccessor(ctx.headers.cookie);\n\n\t\t// Request context setup\n\t\tconst startTime = Date.now();\n\t\tconst requestId =\n\t\t\t(ctx as any).requestId ??\n\t\t\tctx.headers['x-request-id'] ??\n\t\t\tcrypto.randomUUID();\n\n\t\tconst logger = this.endpoint.logger.child({\n\t\t\trequestId,\n\t\t\troute: this.endpoint.route,\n\t\t\thost: ctx.headers.host,\n\t\t\tmethod: this.endpoint.method,\n\t\t}) as TLogger;\n\n\t\t// Get database from context for session extraction\n\t\tconst rawDb = (ctx as any).database as TDatabase;\n\n\t\t// Wrap handler execution in request context\n\t\treturn runWithRequestContext({ logger, requestId, startTime }, async () => {\n\t\t\tconst session = await this.endpoint.getSession({\n\t\t\t\tlogger,\n\t\t\t\tservices: ctx.services,\n\t\t\t\theader,\n\t\t\t\tcookie,\n\t\t\t\t...(rawDb !== undefined && { db: rawDb }),\n\t\t\t} as any);\n\n\t\t\t// Check authorization\n\t\t\tconst isAuthorized = await this.endpoint.authorize({\n\t\t\t\theader,\n\t\t\t\tcookie,\n\t\t\t\tservices: ctx.services,\n\t\t\t\tlogger,\n\t\t\t\tsession,\n\t\t\t\t...(rawDb !== undefined && { db: rawDb }),\n\t\t\t\tbody,\n\t\t\t\tquery,\n\t\t\t\tparams,\n\t\t\t} as any);\n\n\t\t\tif (!isAuthorized) {\n\t\t\t\tlogger.warn('Forbidden access attempt');\n\t\t\t\tthrow new ForbiddenError(\n\t\t\t\t\t'Forbidden access to the endpoint',\n\t\t\t\t\t'You do not have permission to access this resource.',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Create audit context if audit storage is provided\n\t\t\t// The auditorStorage instance is required when endpoint uses .auditor()\n\t\t\tconst auditorStorage = (ctx as any).auditorStorage as TAuditStorage;\n\t\t\tlet auditContext: AuditExecutionContext<TAuditAction> | undefined;\n\n\t\t\tif (auditorStorage) {\n\t\t\t\t// Extract actor if configured\n\t\t\t\tlet actor: AuditActor = { id: 'system', type: 'system' };\n\t\t\t\tif (this.endpoint.actorExtractor) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tactor = await this.endpoint.actorExtractor({\n\t\t\t\t\t\t\tservices: ctx.services as any,\n\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t\theader,\n\t\t\t\t\t\t\tcookie,\n\t\t\t\t\t\t\tlogger,\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tlogger.error(error as Error, 'Failed to extract actor for audits');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst auditor = new DefaultAuditor<TAuditAction>({\n\t\t\t\t\tactor,\n\t\t\t\t\tstorage: auditorStorage as AuditStorage,\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tendpoint: this.endpoint.route,\n\t\t\t\t\t\tmethod: this.endpoint.method,\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tauditContext = { auditor, storage: auditorStorage as AuditStorage };\n\t\t\t}\n\n\t\t\t// Warn if declarative audits are configured but no audit storage\n\t\t\tconst audits = this.endpoint.audits as MappedAudit<\n\t\t\t\tTAuditAction,\n\t\t\t\tTOutSchema\n\t\t\t>[];\n\t\t\tif (!auditContext && audits?.length) {\n\t\t\t\tlogger.warn('No auditor storage service available');\n\t\t\t}\n\n\t\t\t// Execute handler with automatic audit transaction support\n\t\t\tconst result = await executeWithAuditTransaction(\n\t\t\t\tauditContext,\n\t\t\t\tasync (auditor) => {\n\t\t\t\t\t// Use audit transaction as db if available (when storage has same database)\n\t\t\t\t\t// For testing, the tester controls whether to use transactional auditing\n\t\t\t\t\tconst trx = auditor?.getTransaction?.();\n\t\t\t\t\tconst db = trx ?? rawDb;\n\n\t\t\t\t\tconst responseBuilder = new ResponseBuilder();\n\t\t\t\t\tconst response = await this.endpoint.handler(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbody,\n\t\t\t\t\t\t\tquery,\n\t\t\t\t\t\t\tparams,\n\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t\tservices: ctx.services,\n\t\t\t\t\t\t\tlogger,\n\t\t\t\t\t\t\theader,\n\t\t\t\t\t\t\tcookie,\n\t\t\t\t\t\t\tauditor,\n\t\t\t\t\t\t\tdb,\n\t\t\t\t\t\t} as any,\n\t\t\t\t\t\tresponseBuilder,\n\t\t\t\t\t);\n\n\t\t\t\t\t// Check if response has metadata\n\t\t\t\t\tlet data = response;\n\t\t\t\t\tlet metadata = responseBuilder.getMetadata();\n\n\t\t\t\t\tif (Endpoint.hasMetadata(response)) {\n\t\t\t\t\t\tdata = response.data;\n\t\t\t\t\t\tmetadata = response.metadata;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst output = await this.endpoint.parseOutput(data);\n\n\t\t\t\t\treturn { output, metadata, responseBuilder };\n\t\t\t\t},\n\t\t\t\t// Process declarative audits after handler (inside transaction)\n\t\t\t\tasync (result, auditor) => {\n\t\t\t\t\tif (!audits?.length) return;\n\n\t\t\t\t\tfor (const audit of audits) {\n\t\t\t\t\t\tif (audit.when && !audit.when(result.output as any)) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst payload = audit.payload(result.output as any);\n\t\t\t\t\t\tconst entityId = audit.entityId?.(result.output as any);\n\t\t\t\t\t\tauditor.audit(audit.type as any, payload as any, {\n\t\t\t\t\t\t\ttable: audit.table,\n\t\t\t\t\t\t\tentityId,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t// Pass rawDb so storage can reuse existing transactions\n\t\t\t\t{ db: rawDb },\n\t\t\t);\n\n\t\t\tconst { output, metadata } = result;\n\n\t\t\tctx.publisher && (await this.serviceDiscovery.register([ctx.publisher]));\n\t\t\tawait publishConstructEvents(\n\t\t\t\tthis.endpoint,\n\t\t\t\toutput,\n\t\t\t\tthis.serviceDiscovery,\n\t\t\t);\n\n\t\t\t// Convert cookies to Set-Cookie headers\n\t\t\tconst headers: Record<string, string | string[]> = {\n\t\t\t\t...(metadata.headers || {}),\n\t\t\t};\n\n\t\t\tif (metadata.cookies && metadata.cookies.size > 0) {\n\t\t\t\tconst setCookieValues: string[] = [];\n\t\t\t\tfor (const [name, cookie] of metadata.cookies.entries()) {\n\t\t\t\t\tsetCookieValues.push(\n\t\t\t\t\t\tserializeCookie(name, cookie.value, cookie.options),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\theaders['set-cookie'] = setCookieValues;\n\t\t\t}\n\n\t\t\t// Return HTTP response format\n\t\t\treturn {\n\t\t\t\tbody: output,\n\t\t\t\tstatus: metadata.status || 200,\n\t\t\t\theaders,\n\t\t\t};\n\t\t});\n\t}\n\n\tasync request(\n\t\tctx: TestRequestAdaptor<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>,\n\t): Promise<InferStandardSchema<TOutSchema>> {\n\t\tconst response = await this.fullRequest(ctx);\n\t\treturn response.body;\n\t}\n}\n\n/**\n * Conditional audit storage requirement - required when TAuditStorage is configured\n */\ntype AuditStorageRequirement<\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n> = TAuditStorage extends undefined\n\t? {}\n\t: {\n\t\t\t/** Audit storage instance - required when endpoint uses .auditor() */\n\t\t\tauditorStorage: TAuditStorage;\n\t\t};\n\n/**\n * Conditional database requirement - required when TDatabase is configured\n */\ntype DatabaseRequirement<TDatabase = undefined> = TDatabase extends undefined\n\t? {}\n\t: {\n\t\t\t/** Database instance - required when endpoint uses .database() */\n\t\t\tdatabase: TDatabase;\n\t\t};\n\nexport type TestRequestAdaptor<\n\tTInput extends EndpointSchemas = {},\n\tTServices extends Service[] = [],\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\t_TAuditStorageServiceName extends string = string,\n\tTDatabase = undefined,\n\t_TDatabaseServiceName extends string = string,\n> = {\n\tservices: ServiceRecord<TServices>;\n\theaders: Record<string, string>;\n\tpublisher?: Service<TEventPublisherServiceName, TEventPublisher>;\n} & InferComposableStandardSchema<TInput> &\n\tAuditStorageRequirement<TAuditStorage> &\n\tDatabaseRequirement<TDatabase>;\n","import type { AuditableAction, Auditor, AuditStorage } from '@geekmidas/audit';\nimport { DefaultAuditor } from '@geekmidas/audit';\nimport { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type {\n\tComposableStandardSchema,\n\tInferComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport {\n\trunWithRequestContext,\n\ttype Service,\n\tServiceDiscovery,\n\ttype ServiceRecord,\n} from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { publishEvents } from '../publisher';\nimport type { Function } from './Function';\nimport { FunctionBuilder } from './FunctionBuilder';\n\nexport class TestFunctionAdaptor<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTAuditStorageServiceName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> {\n\tstatic getDefaultServiceDiscovery<\n\t\tTInput extends ComposableStandardSchema | undefined = undefined,\n\t\tTOutSchema extends StandardSchemaV1 | undefined = undefined,\n\t\tTServices extends Service[] = [],\n\t\tTLogger extends Logger = Logger,\n\t\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\t\tTEventPublisherServiceName extends string = string,\n\t\tTAuditStorage extends AuditStorage | undefined = undefined,\n\t\tTAuditStorageServiceName extends string = string,\n\t\tTDatabase = undefined,\n\t\tTDatabaseServiceName extends string = string,\n\t\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\t\tstring,\n\t\t\tunknown\n\t\t>,\n\t>(\n\t\t_fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tany\n\t\t>,\n\t) {\n\t\treturn ServiceDiscovery.getInstance(new EnvironmentParser({}));\n\t}\n\n\tconstructor(\n\t\tprivate readonly fn: Function<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tTOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTAuditStorage,\n\t\t\tTAuditStorageServiceName,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName,\n\t\t\tTAuditAction,\n\t\t\tany\n\t\t>,\n\t\tprivate serviceDiscovery: ServiceDiscovery<any> = TestFunctionAdaptor.getDefaultServiceDiscovery(\n\t\t\tfn,\n\t\t),\n\t) {}\n\n\tasync invoke(\n\t\tctx: TestFunctionRequest<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTDatabase,\n\t\t\tTAuditAction\n\t\t>,\n\t): Promise<InferStandardSchema<TOutSchema>> {\n\t\t// Parse input if schema is provided\n\n\t\tconst parsedInput = await FunctionBuilder.parseComposableStandardSchema(\n\t\t\tctx.input,\n\t\t\tthis.fn.input,\n\t\t);\n\n\t\t// Create logger with context\n\t\tconst logger = this.fn.logger.child({\n\t\t\ttest: true,\n\t\t}) as TLogger;\n\n\t\t// Register services (use provided services or register from function)\n\t\tlet services: ServiceRecord<TServices>;\n\t\tif (ctx.services) {\n\t\t\tservices = ctx.services;\n\t\t} else {\n\t\t\tservices = await this.serviceDiscovery.register(this.fn.services);\n\t\t}\n\n\t\t// Resolve database (use provided db or register from function)\n\t\tlet db: TDatabase | undefined;\n\t\tif ('db' in ctx && ctx.db !== undefined) {\n\t\t\tdb = ctx.db;\n\t\t} else if (this.fn.databaseService) {\n\t\t\tconst dbServices = await this.serviceDiscovery.register([\n\t\t\t\tthis.fn.databaseService,\n\t\t\t]);\n\t\t\tdb = dbServices[\n\t\t\t\tthis.fn.databaseService.serviceName as keyof typeof dbServices\n\t\t\t] as TDatabase;\n\t\t}\n\n\t\t// Resolve auditor (use provided auditor or create from function)\n\t\tlet auditor: Auditor<TAuditAction> | undefined;\n\t\tif ('auditor' in ctx && ctx.auditor !== undefined) {\n\t\t\tauditor = ctx.auditor;\n\t\t} else if (this.fn.auditorStorageService) {\n\t\t\tconst auditServices = await this.serviceDiscovery.register([\n\t\t\t\tthis.fn.auditorStorageService,\n\t\t\t]);\n\t\t\tconst storage = auditServices[\n\t\t\t\tthis.fn.auditorStorageService.serviceName as keyof typeof auditServices\n\t\t\t] as AuditStorage;\n\n\t\t\tauditor = new DefaultAuditor<TAuditAction>({\n\t\t\t\tactor: { id: 'system', type: 'system' },\n\t\t\t\tstorage,\n\t\t\t\tmetadata: {\n\t\t\t\t\tfunction: this.fn.type,\n\t\t\t\t\ttest: true,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Wrap execution in request context for service access via context.getLogger()\n\t\tconst requestId = `test-${Date.now()}`;\n\t\tconst startTime = Date.now();\n\n\t\treturn runWithRequestContext({ logger, requestId, startTime }, async () => {\n\t\t\t// Execute the function\n\t\t\tconst response = await this.fn.fn({\n\t\t\t\tinput: parsedInput,\n\t\t\t\tservices,\n\t\t\t\tlogger,\n\t\t\t\tdb,\n\t\t\t\tauditor,\n\t\t\t} as any);\n\n\t\t\t// Parse output if schema is provided\n\t\t\tconst output = await this.fn.parseOutput(response);\n\n\t\t\t// Flush audits if any were recorded\n\t\t\tif (auditor) {\n\t\t\t\tconst records = auditor.getRecords();\n\t\t\t\tif (records.length > 0) {\n\t\t\t\t\tlogger.debug(\n\t\t\t\t\t\t{ auditCount: records.length },\n\t\t\t\t\t\t'Flushing function audits',\n\t\t\t\t\t);\n\t\t\t\t\tawait auditor.flush();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Register publisher service if provided in context\n\n\t\t\tawait publishEvents(\n\t\t\t\tlogger,\n\t\t\t\tthis.serviceDiscovery,\n\t\t\t\tthis.fn.events,\n\t\t\t\toutput,\n\t\t\t\tthis.fn.publisherService,\n\t\t\t);\n\n\t\t\treturn output;\n\t\t}) as Promise<InferStandardSchema<TOutSchema>>;\n\t}\n}\n\nexport type TestFunctionRequest<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTDatabase = undefined,\n\tTAuditAction extends AuditableAction<string, unknown> = AuditableAction<\n\t\tstring,\n\t\tunknown\n\t>,\n> = {\n\tinput: InferComposableStandardSchema<TInput>;\n\tservices: ServiceRecord<TServices>;\n\tpublisher?: Service<TEventPublisherServiceName, TEventPublisher>;\n\tdb?: TDatabase;\n\tauditor?: Auditor<TAuditAction>;\n} & InferComposableStandardSchema<{ input: TInput }>;\n","import { EnvironmentParser } from '@geekmidas/envkit';\nimport type {\n\tEventPublisher,\n\tExtractPublisherMessage,\n} from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport { runWithRequestContext, ServiceDiscovery } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { publishEvents } from '../publisher';\nimport type { Subscriber } from './Subscriber';\n\n// Helper type to extract payload types for subscribed events\ntype ExtractEventPayloads<\n\tTPublisher extends EventPublisher<any> | undefined,\n\tTEventTypes extends any[],\n> = TPublisher extends EventPublisher<any>\n\t? Extract<ExtractPublisherMessage<TPublisher>, { type: TEventTypes[number] }>\n\t: never;\n\nexport class TestSubscriberAdaptor<\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTEventPublisherServiceName extends string = string,\n\tTSubscribedEvents extends\n\t\tExtractPublisherMessage<TEventPublisher>['type'][] = ExtractPublisherMessage<TEventPublisher>['type'][],\n> {\n\tstatic getDefaultServiceDiscovery() {\n\t\treturn ServiceDiscovery.getInstance(new EnvironmentParser({}));\n\t}\n\n\tconstructor(\n\t\tprivate readonly subscriber: Subscriber<\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTEventPublisher,\n\t\t\tTEventPublisherServiceName,\n\t\t\tTSubscribedEvents\n\t\t>,\n\t\tprivate serviceDiscovery: ServiceDiscovery<any> = TestSubscriberAdaptor.getDefaultServiceDiscovery(),\n\t) {}\n\n\tasync invoke(\n\t\trequest: TestSubscriberRequest<\n\t\t\tTEventPublisher,\n\t\t\tTSubscribedEvents,\n\t\t\tTServices\n\t\t>,\n\t): Promise<InferStandardSchema<OutSchema>> {\n\t\t// Create logger with test context\n\t\tconst logger = this.subscriber.logger.child({\n\t\t\ttest: true,\n\t\t}) as TLogger;\n\n\t\t// Resolve services (use provided or auto-register)\n\t\tlet services: ServiceRecord<TServices>;\n\t\tif (request.services) {\n\t\t\tservices = request.services;\n\t\t} else {\n\t\t\tservices = await this.serviceDiscovery.register(this.subscriber.services);\n\t\t}\n\n\t\t// Filter events to only subscribed types\n\t\tconst filteredEvents = this.filterEvents(request.events);\n\n\t\t// Return early if no events after filtering (mirrors AWSLambdaSubscriber)\n\t\tif (filteredEvents.length === 0) {\n\t\t\treturn { batchItemFailures: [] } as any;\n\t\t}\n\n\t\t// Wrap execution in request context for service access via context.getLogger()\n\t\tconst requestId = `test-${Date.now()}`;\n\t\tconst startTime = Date.now();\n\n\t\treturn runWithRequestContext({ logger, requestId, startTime }, async () => {\n\t\t\t// Execute the subscriber handler\n\t\t\tconst result = await this.subscriber.handler({\n\t\t\t\tevents: filteredEvents,\n\t\t\t\tservices,\n\t\t\t\tlogger,\n\t\t\t});\n\n\t\t\t// Validate output if schema is provided\n\t\t\tlet output: any = result;\n\t\t\tif (this.subscriber.outputSchema && result) {\n\t\t\t\tconst validationResult =\n\t\t\t\t\tawait this.subscriber.outputSchema['~standard'].validate(result);\n\n\t\t\t\tif (validationResult.issues) {\n\t\t\t\t\tthrow new Error('Subscriber output validation failed');\n\t\t\t\t}\n\n\t\t\t\toutput = validationResult.value;\n\t\t\t}\n\n\t\t\t// Publish events if configured\n\t\t\tawait publishEvents(\n\t\t\t\tlogger,\n\t\t\t\tthis.serviceDiscovery,\n\t\t\t\tthis.subscriber.events,\n\t\t\t\toutput,\n\t\t\t\tthis.subscriber.publisherService,\n\t\t\t);\n\n\t\t\treturn output;\n\t\t}) as Promise<InferStandardSchema<OutSchema>>;\n\t}\n\n\tprivate filterEvents(\n\t\tevents: ExtractEventPayloads<TEventPublisher, TSubscribedEvents>[],\n\t): ExtractEventPayloads<TEventPublisher, TSubscribedEvents>[] {\n\t\tif (!this.subscriber.subscribedEvents) {\n\t\t\treturn events;\n\t\t}\n\n\t\treturn events.filter((event: any) =>\n\t\t\tthis.subscriber.subscribedEvents!.includes(event.type),\n\t\t);\n\t}\n}\n\nexport type TestSubscriberRequest<\n\tTEventPublisher extends EventPublisher<any> | undefined = undefined,\n\tTSubscribedEvents extends any[] = [],\n\tTServices extends Service[] = [],\n> = {\n\tevents: ExtractEventPayloads<TEventPublisher, TSubscribedEvents>[];\n\tservices?: ServiceRecord<TServices>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAaA,MAAa,sBAAsB;AAiEnC,MAAM,mBAAmB;CACxB;CACA;CACA;CACA;CACA;CACA;AACA;;;;;;;;;;;;;;;;AA6BD,SAAgB,kBACfA,WACAC,SAC0B;CAC1B,MAAM,EAAE,SAAS,GAAG;CACpB,MAAM,2BAAW,IAAI;;;;;CAMrB,SAAS,gBAAgBC,IAAYC,YAAoC;EACxE,MAAM,YAAY,IAAIC,qCAAkB,CAAE;EAC1C,M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Q;IAC3C,MAAM,mBACL,MAAM,KAAK,WAAW,aAAa,aAAa,SAAS,OAAO;AAEjE,QAAI,iBAAiB,OACpB,OAAM,IAAI,MAAM;AAGjB,aAAS,iBAAiB;GAC1B;AAGD,SAAM,oCACL,QACA,KAAK,kBACL,KAAK,WAAW,QAChB,QACA,KAAK,WAAW,iBAChB;AAED,UAAO;EACP,EAAC;CACF;CAED,AAAQ,aACPC,QAC6D;AAC7D,OAAK,KAAK,WAAW,iBACpB,QAAO;AAGR,SAAO,OAAO,OAAO,CAACC,UACrB,KAAK,WAAW,iBAAkB,SAAS,MAAM,KAAK,CACtD;CACD;AACD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const require_chunk = require('../chunk-DWy1uDak.cjs');
|
|
2
|
+
const __geekmidas_services = require_chunk.__toESM(require("@geekmidas/services"));
|
|
3
|
+
|
|
4
|
+
//#region src/adaptors/trpc.ts
|
|
5
|
+
function createServicesMiddleware(mw, envParser) {
|
|
6
|
+
return (services) => {
|
|
7
|
+
const builder = mw(async (opts) => {
|
|
8
|
+
const ctx = opts.ctx;
|
|
9
|
+
const discovery = ctx.serviceDiscovery ?? __geekmidas_services.ServiceDiscovery.getInstance(envParser ?? (() => {
|
|
10
|
+
throw new Error("createServicesMiddleware: no `envParser` provided and `ctx.serviceDiscovery` is missing. Pass an EnvironmentParser to createServicesMiddleware(), or attach a ServiceDiscovery instance to the tRPC context.");
|
|
11
|
+
})());
|
|
12
|
+
const requestId = ctx.requestId ?? crypto.randomUUID();
|
|
13
|
+
const startTime = ctx.startTime ?? Date.now();
|
|
14
|
+
return (0, __geekmidas_services.runWithRequestContext)({
|
|
15
|
+
logger: ctx.logger,
|
|
16
|
+
requestId,
|
|
17
|
+
startTime
|
|
18
|
+
}, async () => {
|
|
19
|
+
const resolved = await discovery.register(services);
|
|
20
|
+
return opts.next({ ctx: {
|
|
21
|
+
...opts.ctx,
|
|
22
|
+
...resolved
|
|
23
|
+
} });
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
const middlewares = builder._middlewares;
|
|
27
|
+
if (middlewares?.length) {
|
|
28
|
+
const last = middlewares[middlewares.length - 1];
|
|
29
|
+
if (last) last._services = services;
|
|
30
|
+
}
|
|
31
|
+
return builder;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a tRPC middleware that establishes a request context for downstream
|
|
36
|
+
* code without resolving any services. Useful when services aren't needed on
|
|
37
|
+
* a procedure but the handler (or libraries it calls) still wants to read
|
|
38
|
+
* `serviceContext.getLogger()` / `getRequestId()` / `getRequestStartTime()`.
|
|
39
|
+
*
|
|
40
|
+
* `requestId` and `startTime` are pulled from the tRPC context when present,
|
|
41
|
+
* otherwise generated (`crypto.randomUUID()` and `Date.now()`).
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const withRequestContext = createRequestContextMiddleware(t.middleware);
|
|
46
|
+
* export const baseProcedure = t.procedure.use(withRequestContext);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
function createRequestContextMiddleware(mw) {
|
|
50
|
+
return mw(async (opts) => {
|
|
51
|
+
const ctx = opts.ctx;
|
|
52
|
+
const requestId = ctx.requestId ?? crypto.randomUUID();
|
|
53
|
+
const startTime = ctx.startTime ?? Date.now();
|
|
54
|
+
return (0, __geekmidas_services.runWithRequestContext)({
|
|
55
|
+
logger: ctx.logger,
|
|
56
|
+
requestId,
|
|
57
|
+
startTime
|
|
58
|
+
}, () => opts.next());
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
exports.createRequestContextMiddleware = createRequestContextMiddleware;
|
|
64
|
+
exports.createServicesMiddleware = createServicesMiddleware;
|
|
65
|
+
//# sourceMappingURL=trpc.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trpc.cjs","names":["mw: CreateMiddleware<TContext, TMeta>","envParser?: EnvironmentParser<{}>","services: [...T]"],"sources":["../../src/adaptors/trpc.ts"],"sourcesContent":["import type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport {\n\trunWithRequestContext,\n\ttype Service,\n\tServiceDiscovery,\n\ttype ServiceRecord,\n} from '@geekmidas/services';\nimport type {\n\tTRPCMiddlewareBuilder,\n\tTRPCMiddlewareFunction,\n} from '@trpc/server';\n\n/**\n * Shape of `t.middleware` from `@trpc/server`. We accept this rather than the\n * initialized `t` object so callers retain ownership of their tRPC instance\n * (no double-initialization, no opinion on context/meta shape).\n */\ntype CreateMiddleware<TContext, TMeta> = <$ContextOverrides>(\n\tfn: TRPCMiddlewareFunction<\n\t\tTContext,\n\t\tTMeta,\n\t\tobject,\n\t\t$ContextOverrides,\n\t\tunknown\n\t>,\n) => TRPCMiddlewareBuilder<TContext, TMeta, $ContextOverrides, unknown>;\n\n/**\n * Result of `createServicesMiddleware`: a function that accepts a service\n * tuple and returns a tRPC middleware that merges resolved services onto the\n * context.\n */\nexport type ServicesMiddleware<\n\tTContext extends object,\n\tTMeta extends object,\n> = <const T extends Service[]>(\n\tservices: [...T],\n) => TRPCMiddlewareBuilder<TContext, TMeta, ServiceRecord<T>, unknown>;\n\n/**\n * Context shape required by `createServicesMiddleware` overload 2.\n * Procedures that pull services via context-stored discovery must expose it\n * under `serviceDiscovery`.\n */\nexport interface ContextWithServiceDiscovery {\n\tserviceDiscovery: ServiceDiscovery;\n}\n\n/**\n * Minimum context required for request-context propagation. `logger` must be\n * present so services can call `serviceContext.getLogger()`. `requestId` and\n * `startTime` are auto-generated if missing.\n */\nexport interface ContextWithLogger {\n\tlogger: Logger;\n\trequestId?: string;\n\tstartTime?: number;\n}\n\n/**\n * Create a tRPC middleware that:\n *\n * 1. Resolves the requested services via `ServiceDiscovery`.\n * 2. Wraps the downstream call in `runWithRequestContext` so any code reached\n * by the procedure (including service method implementations) can read the\n * current logger/request id via `serviceContext`.\n * 3. Merges the resolved services onto the tRPC context so handlers can access\n * them by service name (`ctx.database`, `ctx.cache`, ...).\n *\n * Two overloads:\n * - Pass an `envParser` to create a per-request `ServiceDiscovery` instance.\n * - Omit `envParser` to read `ctx.serviceDiscovery` from the tRPC context.\n *\n * @example\n * ```ts\n * import { initTRPC } from '@trpc/server';\n * import { createServicesMiddleware } from '@geekmidas/constructs/trpc';\n *\n * const t = initTRPC.context<Context>().create();\n * const withServices = createServicesMiddleware(t.middleware, envParser);\n *\n * export const authedProcedure = t.procedure.use(\n * withServices([databaseService, cacheService]),\n * );\n * ```\n */\nexport function createServicesMiddleware<\n\tTContext extends ContextWithLogger & object,\n\tTMeta extends object,\n>(\n\tmw: CreateMiddleware<TContext, TMeta>,\n\tenvParser: EnvironmentParser<{}>,\n): ServicesMiddleware<TContext, TMeta>;\nexport function createServicesMiddleware<\n\tTContext extends ContextWithLogger & ContextWithServiceDiscovery & object,\n\tTMeta extends object,\n>(mw: CreateMiddleware<TContext, TMeta>): ServicesMiddleware<TContext, TMeta>;\nexport function createServicesMiddleware<\n\tTContext extends ContextWithLogger & object,\n\tTMeta extends object,\n>(\n\tmw: CreateMiddleware<TContext, TMeta>,\n\tenvParser?: EnvironmentParser<{}>,\n): ServicesMiddleware<TContext, TMeta> {\n\treturn (<const T extends Service[]>(services: [...T]) => {\n\t\tconst builder = mw(async (opts) => {\n\t\t\tconst ctx = opts.ctx as TContext & Partial<ContextWithServiceDiscovery>;\n\n\t\t\tconst discovery =\n\t\t\t\tctx.serviceDiscovery ??\n\t\t\t\tServiceDiscovery.getInstance(\n\t\t\t\t\tenvParser ??\n\t\t\t\t\t\t(() => {\n\t\t\t\t\t\t\t// Hit only if overload 2 was selected but ctx.serviceDiscovery is\n\t\t\t\t\t\t\t// missing at runtime — surface the mistake immediately rather\n\t\t\t\t\t\t\t// than letting an undefined env parser fail deep inside register.\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t'createServicesMiddleware: no `envParser` provided and ' +\n\t\t\t\t\t\t\t\t\t'`ctx.serviceDiscovery` is missing. Pass an EnvironmentParser ' +\n\t\t\t\t\t\t\t\t\t'to createServicesMiddleware(), or attach a ServiceDiscovery ' +\n\t\t\t\t\t\t\t\t\t'instance to the tRPC context.',\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t})(),\n\t\t\t\t);\n\n\t\t\tconst requestId = ctx.requestId ?? crypto.randomUUID();\n\t\t\tconst startTime = ctx.startTime ?? Date.now();\n\n\t\t\treturn runWithRequestContext(\n\t\t\t\t{ logger: ctx.logger, requestId, startTime },\n\t\t\t\tasync () => {\n\t\t\t\t\tconst resolved = await discovery.register(services);\n\t\t\t\t\treturn opts.next({\n\t\t\t\t\t\tctx: { ...opts.ctx, ...resolved } as typeof opts.ctx &\n\t\t\t\t\t\t\tServiceRecord<T>,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\n\t\t// Tag the inner middleware function with the requested services so external\n\t\t// tooling (e.g. detect-procedures route generators) can introspect a\n\t\t// procedure's service dependencies without re-executing middleware.\n\t\tconst middlewares = (\n\t\t\tbuilder as unknown as { _middlewares?: Array<{ _services?: Service[] }> }\n\t\t)._middlewares;\n\t\tif (middlewares?.length) {\n\t\t\tconst last = middlewares[middlewares.length - 1];\n\t\t\tif (last) last._services = services as unknown as Service[];\n\t\t}\n\n\t\treturn builder as TRPCMiddlewareBuilder<\n\t\t\tTContext,\n\t\t\tTMeta,\n\t\t\tServiceRecord<T>,\n\t\t\tunknown\n\t\t>;\n\t}) as ServicesMiddleware<TContext, TMeta>;\n}\n\n/**\n * Create a tRPC middleware that establishes a request context for downstream\n * code without resolving any services. Useful when services aren't needed on\n * a procedure but the handler (or libraries it calls) still wants to read\n * `serviceContext.getLogger()` / `getRequestId()` / `getRequestStartTime()`.\n *\n * `requestId` and `startTime` are pulled from the tRPC context when present,\n * otherwise generated (`crypto.randomUUID()` and `Date.now()`).\n *\n * @example\n * ```ts\n * const withRequestContext = createRequestContextMiddleware(t.middleware);\n * export const baseProcedure = t.procedure.use(withRequestContext);\n * ```\n */\nexport function createRequestContextMiddleware<\n\tTContext extends ContextWithLogger & object,\n\tTMeta extends object,\n>(\n\tmw: CreateMiddleware<TContext, TMeta>,\n): TRPCMiddlewareBuilder<TContext, TMeta, object, unknown> {\n\treturn mw(async (opts) => {\n\t\tconst ctx = opts.ctx as TContext;\n\t\tconst requestId = ctx.requestId ?? crypto.randomUUID();\n\t\tconst startTime = ctx.startTime ?? Date.now();\n\t\treturn runWithRequestContext(\n\t\t\t{ logger: ctx.logger, requestId, startTime },\n\t\t\t() => opts.next(),\n\t\t);\n\t});\n}\n"],"mappings":";;;;AAkGA,SAAgB,yBAIfA,IACAC,WACsC;AACtC,QAAQ,CAA4BC,aAAqB;EACxD,MAAM,UAAU,GAAG,OAAO,SAAS;GAClC,MAAM,MAAM,KAAK;GAEjB,MAAM,YACL,IAAI,oBACJ,sCAAiB,YAChB,aACC,CAAC,MAAM;AAIN,UAAM,IAAI,MACT;GAKD,IAAG,CACL;GAEF,MAAM,YAAY,IAAI,aAAa,OAAO,YAAY;GACtD,MAAM,YAAY,IAAI,aAAa,KAAK,KAAK;AAE7C,UAAO,gDACN;IAAE,QAAQ,IAAI;IAAQ;IAAW;GAAW,GAC5C,YAAY;IACX,MAAM,WAAW,MAAM,UAAU,SAAS,SAAS;AACnD,WAAO,KAAK,KAAK,EAChB,KAAK;KAAE,GAAG,KAAK;KAAK,GAAG;IAAU,EAEjC,EAAC;GACF,EACD;EACD,EAAC;EAKF,MAAM,cACL,QACC;AACF,MAAI,aAAa,QAAQ;GACxB,MAAM,OAAO,YAAY,YAAY,SAAS;AAC9C,OAAI,KAAM,MAAK,YAAY;EAC3B;AAED,SAAO;CAMP;AACD;;;;;;;;;;;;;;;;AAiBD,SAAgB,+BAIfF,IAC0D;AAC1D,QAAO,GAAG,OAAO,SAAS;EACzB,MAAM,MAAM,KAAK;EACjB,MAAM,YAAY,IAAI,aAAa,OAAO,YAAY;EACtD,MAAM,YAAY,IAAI,aAAa,KAAK,KAAK;AAC7C,SAAO,gDACN;GAAE,QAAQ,IAAI;GAAQ;GAAW;EAAW,GAC5C,MAAM,KAAK,MAAM,CACjB;CACD,EAAC;AACF"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { EnvironmentParser } from "@geekmidas/envkit";
|
|
2
|
+
import { Logger } from "@geekmidas/logger";
|
|
3
|
+
import { Service, ServiceDiscovery, ServiceRecord } from "@geekmidas/services";
|
|
4
|
+
import { TRPCMiddlewareBuilder, TRPCMiddlewareFunction } from "@trpc/server";
|
|
5
|
+
|
|
6
|
+
//#region src/adaptors/trpc.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Shape of `t.middleware` from `@trpc/server`. We accept this rather than the
|
|
10
|
+
* initialized `t` object so callers retain ownership of their tRPC instance
|
|
11
|
+
* (no double-initialization, no opinion on context/meta shape).
|
|
12
|
+
*/
|
|
13
|
+
type CreateMiddleware<TContext, TMeta> = <$ContextOverrides>(fn: TRPCMiddlewareFunction<TContext, TMeta, object, $ContextOverrides, unknown>) => TRPCMiddlewareBuilder<TContext, TMeta, $ContextOverrides, unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* Result of `createServicesMiddleware`: a function that accepts a service
|
|
16
|
+
* tuple and returns a tRPC middleware that merges resolved services onto the
|
|
17
|
+
* context.
|
|
18
|
+
*/
|
|
19
|
+
type ServicesMiddleware<TContext extends object, TMeta extends object> = <const T extends Service[]>(services: [...T]) => TRPCMiddlewareBuilder<TContext, TMeta, ServiceRecord<T>, unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Context shape required by `createServicesMiddleware` overload 2.
|
|
22
|
+
* Procedures that pull services via context-stored discovery must expose it
|
|
23
|
+
* under `serviceDiscovery`.
|
|
24
|
+
*/
|
|
25
|
+
interface ContextWithServiceDiscovery {
|
|
26
|
+
serviceDiscovery: ServiceDiscovery;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Minimum context required for request-context propagation. `logger` must be
|
|
30
|
+
* present so services can call `serviceContext.getLogger()`. `requestId` and
|
|
31
|
+
* `startTime` are auto-generated if missing.
|
|
32
|
+
*/
|
|
33
|
+
interface ContextWithLogger {
|
|
34
|
+
logger: Logger;
|
|
35
|
+
requestId?: string;
|
|
36
|
+
startTime?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a tRPC middleware that:
|
|
40
|
+
*
|
|
41
|
+
* 1. Resolves the requested services via `ServiceDiscovery`.
|
|
42
|
+
* 2. Wraps the downstream call in `runWithRequestContext` so any code reached
|
|
43
|
+
* by the procedure (including service method implementations) can read the
|
|
44
|
+
* current logger/request id via `serviceContext`.
|
|
45
|
+
* 3. Merges the resolved services onto the tRPC context so handlers can access
|
|
46
|
+
* them by service name (`ctx.database`, `ctx.cache`, ...).
|
|
47
|
+
*
|
|
48
|
+
* Two overloads:
|
|
49
|
+
* - Pass an `envParser` to create a per-request `ServiceDiscovery` instance.
|
|
50
|
+
* - Omit `envParser` to read `ctx.serviceDiscovery` from the tRPC context.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { initTRPC } from '@trpc/server';
|
|
55
|
+
* import { createServicesMiddleware } from '@geekmidas/constructs/trpc';
|
|
56
|
+
*
|
|
57
|
+
* const t = initTRPC.context<Context>().create();
|
|
58
|
+
* const withServices = createServicesMiddleware(t.middleware, envParser);
|
|
59
|
+
*
|
|
60
|
+
* export const authedProcedure = t.procedure.use(
|
|
61
|
+
* withServices([databaseService, cacheService]),
|
|
62
|
+
* );
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare function createServicesMiddleware<TContext extends ContextWithLogger & object, TMeta extends object>(mw: CreateMiddleware<TContext, TMeta>, envParser: EnvironmentParser<{}>): ServicesMiddleware<TContext, TMeta>;
|
|
66
|
+
declare function createServicesMiddleware<TContext extends ContextWithLogger & ContextWithServiceDiscovery & object, TMeta extends object>(mw: CreateMiddleware<TContext, TMeta>): ServicesMiddleware<TContext, TMeta>;
|
|
67
|
+
/**
|
|
68
|
+
* Create a tRPC middleware that establishes a request context for downstream
|
|
69
|
+
* code without resolving any services. Useful when services aren't needed on
|
|
70
|
+
* a procedure but the handler (or libraries it calls) still wants to read
|
|
71
|
+
* `serviceContext.getLogger()` / `getRequestId()` / `getRequestStartTime()`.
|
|
72
|
+
*
|
|
73
|
+
* `requestId` and `startTime` are pulled from the tRPC context when present,
|
|
74
|
+
* otherwise generated (`crypto.randomUUID()` and `Date.now()`).
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* const withRequestContext = createRequestContextMiddleware(t.middleware);
|
|
79
|
+
* export const baseProcedure = t.procedure.use(withRequestContext);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare function createRequestContextMiddleware<TContext extends ContextWithLogger & object, TMeta extends object>(mw: CreateMiddleware<TContext, TMeta>): TRPCMiddlewareBuilder<TContext, TMeta, object, unknown>;
|
|
83
|
+
//#endregion
|
|
84
|
+
export { ContextWithLogger, ContextWithServiceDiscovery, ServicesMiddleware, createRequestContextMiddleware, createServicesMiddleware };
|
|
85
|
+
//# sourceMappingURL=trpc.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trpc.d.cts","names":[],"sources":["../../src/adaptors/trpc.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAWsB;;;KAOjB,gBAGH,CAAA,QAAA,EAAA,KAAA,CAAA,GAAA,CAAA,iBAAA,CAAA,CAAA,EAAA,EAFG,sBAEH,CADA,QACA,EAAA,KAAA,EAAA,MAAA,EAEA,iBAFA,EAAA,OAAA,CAAA,EAAA,GAKG,qBALH,CAKyB,QALzB,EAKmC,KALnC,EAK0C,iBAL1C,EAAA,OAAA,CAAA;;;;;;AAKG,KAOO,kBAPP,CAAA,iBAAA,MAAA,EAAA,cAAA,MAAA,CAAA,GAAA,CAAA,gBAUgB,OAVhB,EAAA,CAAA,CAAA,QAAA,EAAA,CAAA,GAWU,CAXV,CAAA,EAAA,GAYA,qBAZA,CAYsB,QAZtB,EAYgC,KAZhC,EAYuC,aAZvC,CAYqD,CAZrD,CAAA,EAAA,OAAA,CAAA;AAAqB;AAO1B;;;;AAK2B,UAOV,2BAAA,CAPU;EAAQ,gBAAE,EAQlB,gBARkB;;;;AAAX;AAO1B;AASA;AAiCgB,UAjCC,iBAAA,CAiCuB;EAAA,MAAA,EAhC/B,MAgC+B;EAAA,SACtB,CAAA,EAAA,MAAA;EAAiB,SAGb,CAAA,EAAA,MAAA;;;;;;;AAED;AACrB;;;;;;;;;;AAG4D;AA+E5D;;;;;;;;;AAKwB;iBA9FR,0CACE,sDAGb,iBAAiB,UAAU,mBACpB,wBACT,mBAAmB,UAAU;iBAChB,0CACE,oBAAoB,gEAEhC,iBAAiB,UAAU,SAAS,mBAAmB,UAAU;;;;;;;;;;;;;;;;iBA+EvD,gDACE,sDAGb,iBAAiB,UAAU,SAC7B,sBAAsB,UAAU"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Service, ServiceDiscovery, ServiceRecord } from "@geekmidas/services";
|
|
2
|
+
import { EnvironmentParser } from "@geekmidas/envkit";
|
|
3
|
+
import { Logger } from "@geekmidas/logger";
|
|
4
|
+
import { TRPCMiddlewareBuilder, TRPCMiddlewareFunction } from "@trpc/server";
|
|
5
|
+
|
|
6
|
+
//#region src/adaptors/trpc.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Shape of `t.middleware` from `@trpc/server`. We accept this rather than the
|
|
10
|
+
* initialized `t` object so callers retain ownership of their tRPC instance
|
|
11
|
+
* (no double-initialization, no opinion on context/meta shape).
|
|
12
|
+
*/
|
|
13
|
+
type CreateMiddleware<TContext, TMeta> = <$ContextOverrides>(fn: TRPCMiddlewareFunction<TContext, TMeta, object, $ContextOverrides, unknown>) => TRPCMiddlewareBuilder<TContext, TMeta, $ContextOverrides, unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* Result of `createServicesMiddleware`: a function that accepts a service
|
|
16
|
+
* tuple and returns a tRPC middleware that merges resolved services onto the
|
|
17
|
+
* context.
|
|
18
|
+
*/
|
|
19
|
+
type ServicesMiddleware<TContext extends object, TMeta extends object> = <const T extends Service[]>(services: [...T]) => TRPCMiddlewareBuilder<TContext, TMeta, ServiceRecord<T>, unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Context shape required by `createServicesMiddleware` overload 2.
|
|
22
|
+
* Procedures that pull services via context-stored discovery must expose it
|
|
23
|
+
* under `serviceDiscovery`.
|
|
24
|
+
*/
|
|
25
|
+
interface ContextWithServiceDiscovery {
|
|
26
|
+
serviceDiscovery: ServiceDiscovery;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Minimum context required for request-context propagation. `logger` must be
|
|
30
|
+
* present so services can call `serviceContext.getLogger()`. `requestId` and
|
|
31
|
+
* `startTime` are auto-generated if missing.
|
|
32
|
+
*/
|
|
33
|
+
interface ContextWithLogger {
|
|
34
|
+
logger: Logger;
|
|
35
|
+
requestId?: string;
|
|
36
|
+
startTime?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a tRPC middleware that:
|
|
40
|
+
*
|
|
41
|
+
* 1. Resolves the requested services via `ServiceDiscovery`.
|
|
42
|
+
* 2. Wraps the downstream call in `runWithRequestContext` so any code reached
|
|
43
|
+
* by the procedure (including service method implementations) can read the
|
|
44
|
+
* current logger/request id via `serviceContext`.
|
|
45
|
+
* 3. Merges the resolved services onto the tRPC context so handlers can access
|
|
46
|
+
* them by service name (`ctx.database`, `ctx.cache`, ...).
|
|
47
|
+
*
|
|
48
|
+
* Two overloads:
|
|
49
|
+
* - Pass an `envParser` to create a per-request `ServiceDiscovery` instance.
|
|
50
|
+
* - Omit `envParser` to read `ctx.serviceDiscovery` from the tRPC context.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { initTRPC } from '@trpc/server';
|
|
55
|
+
* import { createServicesMiddleware } from '@geekmidas/constructs/trpc';
|
|
56
|
+
*
|
|
57
|
+
* const t = initTRPC.context<Context>().create();
|
|
58
|
+
* const withServices = createServicesMiddleware(t.middleware, envParser);
|
|
59
|
+
*
|
|
60
|
+
* export const authedProcedure = t.procedure.use(
|
|
61
|
+
* withServices([databaseService, cacheService]),
|
|
62
|
+
* );
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare function createServicesMiddleware<TContext extends ContextWithLogger & object, TMeta extends object>(mw: CreateMiddleware<TContext, TMeta>, envParser: EnvironmentParser<{}>): ServicesMiddleware<TContext, TMeta>;
|
|
66
|
+
declare function createServicesMiddleware<TContext extends ContextWithLogger & ContextWithServiceDiscovery & object, TMeta extends object>(mw: CreateMiddleware<TContext, TMeta>): ServicesMiddleware<TContext, TMeta>;
|
|
67
|
+
/**
|
|
68
|
+
* Create a tRPC middleware that establishes a request context for downstream
|
|
69
|
+
* code without resolving any services. Useful when services aren't needed on
|
|
70
|
+
* a procedure but the handler (or libraries it calls) still wants to read
|
|
71
|
+
* `serviceContext.getLogger()` / `getRequestId()` / `getRequestStartTime()`.
|
|
72
|
+
*
|
|
73
|
+
* `requestId` and `startTime` are pulled from the tRPC context when present,
|
|
74
|
+
* otherwise generated (`crypto.randomUUID()` and `Date.now()`).
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* const withRequestContext = createRequestContextMiddleware(t.middleware);
|
|
79
|
+
* export const baseProcedure = t.procedure.use(withRequestContext);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare function createRequestContextMiddleware<TContext extends ContextWithLogger & object, TMeta extends object>(mw: CreateMiddleware<TContext, TMeta>): TRPCMiddlewareBuilder<TContext, TMeta, object, unknown>;
|
|
83
|
+
//#endregion
|
|
84
|
+
export { ContextWithLogger, ContextWithServiceDiscovery, ServicesMiddleware, createRequestContextMiddleware, createServicesMiddleware };
|
|
85
|
+
//# sourceMappingURL=trpc.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trpc.d.mts","names":[],"sources":["../../src/adaptors/trpc.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAWsB;;;KAOjB,gBAGH,CAAA,QAAA,EAAA,KAAA,CAAA,GAAA,CAAA,iBAAA,CAAA,CAAA,EAAA,EAFG,sBAEH,CADA,QACA,EAAA,KAAA,EAAA,MAAA,EAEA,iBAFA,EAAA,OAAA,CAAA,EAAA,GAKG,qBALH,CAKyB,QALzB,EAKmC,KALnC,EAK0C,iBAL1C,EAAA,OAAA,CAAA;;;;;;AAKG,KAOO,kBAPP,CAAA,iBAAA,MAAA,EAAA,cAAA,MAAA,CAAA,GAAA,CAAA,gBAUgB,OAVhB,EAAA,CAAA,CAAA,QAAA,EAAA,CAAA,GAWU,CAXV,CAAA,EAAA,GAYA,qBAZA,CAYsB,QAZtB,EAYgC,KAZhC,EAYuC,aAZvC,CAYqD,CAZrD,CAAA,EAAA,OAAA,CAAA;AAAqB;AAO1B;;;;AAK2B,UAOV,2BAAA,CAPU;EAAQ,gBAAE,EAQlB,gBARkB;;;;AAAX;AAO1B;AASA;AAiCgB,UAjCC,iBAAA,CAiCuB;EAAA,MAAA,EAhC/B,MAgC+B;EAAA,SACtB,CAAA,EAAA,MAAA;EAAiB,SAGb,CAAA,EAAA,MAAA;;;;;;;AAED;AACrB;;;;;;;;;;AAG4D;AA+E5D;;;;;;;;;AAKwB;iBA9FR,0CACE,sDAGb,iBAAiB,UAAU,mBACpB,wBACT,mBAAmB,UAAU;iBAChB,0CACE,oBAAoB,gEAEhC,iBAAiB,UAAU,SAAS,mBAAmB,UAAU;;;;;;;;;;;;;;;;iBA+EvD,gDACE,sDAGb,iBAAiB,UAAU,SAC7B,sBAAsB,UAAU"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ServiceDiscovery, runWithRequestContext } from "@geekmidas/services";
|
|
2
|
+
|
|
3
|
+
//#region src/adaptors/trpc.ts
|
|
4
|
+
function createServicesMiddleware(mw, envParser) {
|
|
5
|
+
return (services) => {
|
|
6
|
+
const builder = mw(async (opts) => {
|
|
7
|
+
const ctx = opts.ctx;
|
|
8
|
+
const discovery = ctx.serviceDiscovery ?? ServiceDiscovery.getInstance(envParser ?? (() => {
|
|
9
|
+
throw new Error("createServicesMiddleware: no `envParser` provided and `ctx.serviceDiscovery` is missing. Pass an EnvironmentParser to createServicesMiddleware(), or attach a ServiceDiscovery instance to the tRPC context.");
|
|
10
|
+
})());
|
|
11
|
+
const requestId = ctx.requestId ?? crypto.randomUUID();
|
|
12
|
+
const startTime = ctx.startTime ?? Date.now();
|
|
13
|
+
return runWithRequestContext({
|
|
14
|
+
logger: ctx.logger,
|
|
15
|
+
requestId,
|
|
16
|
+
startTime
|
|
17
|
+
}, async () => {
|
|
18
|
+
const resolved = await discovery.register(services);
|
|
19
|
+
return opts.next({ ctx: {
|
|
20
|
+
...opts.ctx,
|
|
21
|
+
...resolved
|
|
22
|
+
} });
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
const middlewares = builder._middlewares;
|
|
26
|
+
if (middlewares?.length) {
|
|
27
|
+
const last = middlewares[middlewares.length - 1];
|
|
28
|
+
if (last) last._services = services;
|
|
29
|
+
}
|
|
30
|
+
return builder;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a tRPC middleware that establishes a request context for downstream
|
|
35
|
+
* code without resolving any services. Useful when services aren't needed on
|
|
36
|
+
* a procedure but the handler (or libraries it calls) still wants to read
|
|
37
|
+
* `serviceContext.getLogger()` / `getRequestId()` / `getRequestStartTime()`.
|
|
38
|
+
*
|
|
39
|
+
* `requestId` and `startTime` are pulled from the tRPC context when present,
|
|
40
|
+
* otherwise generated (`crypto.randomUUID()` and `Date.now()`).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const withRequestContext = createRequestContextMiddleware(t.middleware);
|
|
45
|
+
* export const baseProcedure = t.procedure.use(withRequestContext);
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
function createRequestContextMiddleware(mw) {
|
|
49
|
+
return mw(async (opts) => {
|
|
50
|
+
const ctx = opts.ctx;
|
|
51
|
+
const requestId = ctx.requestId ?? crypto.randomUUID();
|
|
52
|
+
const startTime = ctx.startTime ?? Date.now();
|
|
53
|
+
return runWithRequestContext({
|
|
54
|
+
logger: ctx.logger,
|
|
55
|
+
requestId,
|
|
56
|
+
startTime
|
|
57
|
+
}, () => opts.next());
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { createRequestContextMiddleware, createServicesMiddleware };
|
|
63
|
+
//# sourceMappingURL=trpc.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trpc.mjs","names":["mw: CreateMiddleware<TContext, TMeta>","envParser?: EnvironmentParser<{}>","services: [...T]"],"sources":["../../src/adaptors/trpc.ts"],"sourcesContent":["import type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport {\n\trunWithRequestContext,\n\ttype Service,\n\tServiceDiscovery,\n\ttype ServiceRecord,\n} from '@geekmidas/services';\nimport type {\n\tTRPCMiddlewareBuilder,\n\tTRPCMiddlewareFunction,\n} from '@trpc/server';\n\n/**\n * Shape of `t.middleware` from `@trpc/server`. We accept this rather than the\n * initialized `t` object so callers retain ownership of their tRPC instance\n * (no double-initialization, no opinion on context/meta shape).\n */\ntype CreateMiddleware<TContext, TMeta> = <$ContextOverrides>(\n\tfn: TRPCMiddlewareFunction<\n\t\tTContext,\n\t\tTMeta,\n\t\tobject,\n\t\t$ContextOverrides,\n\t\tunknown\n\t>,\n) => TRPCMiddlewareBuilder<TContext, TMeta, $ContextOverrides, unknown>;\n\n/**\n * Result of `createServicesMiddleware`: a function that accepts a service\n * tuple and returns a tRPC middleware that merges resolved services onto the\n * context.\n */\nexport type ServicesMiddleware<\n\tTContext extends object,\n\tTMeta extends object,\n> = <const T extends Service[]>(\n\tservices: [...T],\n) => TRPCMiddlewareBuilder<TContext, TMeta, ServiceRecord<T>, unknown>;\n\n/**\n * Context shape required by `createServicesMiddleware` overload 2.\n * Procedures that pull services via context-stored discovery must expose it\n * under `serviceDiscovery`.\n */\nexport interface ContextWithServiceDiscovery {\n\tserviceDiscovery: ServiceDiscovery;\n}\n\n/**\n * Minimum context required for request-context propagation. `logger` must be\n * present so services can call `serviceContext.getLogger()`. `requestId` and\n * `startTime` are auto-generated if missing.\n */\nexport interface ContextWithLogger {\n\tlogger: Logger;\n\trequestId?: string;\n\tstartTime?: number;\n}\n\n/**\n * Create a tRPC middleware that:\n *\n * 1. Resolves the requested services via `ServiceDiscovery`.\n * 2. Wraps the downstream call in `runWithRequestContext` so any code reached\n * by the procedure (including service method implementations) can read the\n * current logger/request id via `serviceContext`.\n * 3. Merges the resolved services onto the tRPC context so handlers can access\n * them by service name (`ctx.database`, `ctx.cache`, ...).\n *\n * Two overloads:\n * - Pass an `envParser` to create a per-request `ServiceDiscovery` instance.\n * - Omit `envParser` to read `ctx.serviceDiscovery` from the tRPC context.\n *\n * @example\n * ```ts\n * import { initTRPC } from '@trpc/server';\n * import { createServicesMiddleware } from '@geekmidas/constructs/trpc';\n *\n * const t = initTRPC.context<Context>().create();\n * const withServices = createServicesMiddleware(t.middleware, envParser);\n *\n * export const authedProcedure = t.procedure.use(\n * withServices([databaseService, cacheService]),\n * );\n * ```\n */\nexport function createServicesMiddleware<\n\tTContext extends ContextWithLogger & object,\n\tTMeta extends object,\n>(\n\tmw: CreateMiddleware<TContext, TMeta>,\n\tenvParser: EnvironmentParser<{}>,\n): ServicesMiddleware<TContext, TMeta>;\nexport function createServicesMiddleware<\n\tTContext extends ContextWithLogger & ContextWithServiceDiscovery & object,\n\tTMeta extends object,\n>(mw: CreateMiddleware<TContext, TMeta>): ServicesMiddleware<TContext, TMeta>;\nexport function createServicesMiddleware<\n\tTContext extends ContextWithLogger & object,\n\tTMeta extends object,\n>(\n\tmw: CreateMiddleware<TContext, TMeta>,\n\tenvParser?: EnvironmentParser<{}>,\n): ServicesMiddleware<TContext, TMeta> {\n\treturn (<const T extends Service[]>(services: [...T]) => {\n\t\tconst builder = mw(async (opts) => {\n\t\t\tconst ctx = opts.ctx as TContext & Partial<ContextWithServiceDiscovery>;\n\n\t\t\tconst discovery =\n\t\t\t\tctx.serviceDiscovery ??\n\t\t\t\tServiceDiscovery.getInstance(\n\t\t\t\t\tenvParser ??\n\t\t\t\t\t\t(() => {\n\t\t\t\t\t\t\t// Hit only if overload 2 was selected but ctx.serviceDiscovery is\n\t\t\t\t\t\t\t// missing at runtime — surface the mistake immediately rather\n\t\t\t\t\t\t\t// than letting an undefined env parser fail deep inside register.\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t'createServicesMiddleware: no `envParser` provided and ' +\n\t\t\t\t\t\t\t\t\t'`ctx.serviceDiscovery` is missing. Pass an EnvironmentParser ' +\n\t\t\t\t\t\t\t\t\t'to createServicesMiddleware(), or attach a ServiceDiscovery ' +\n\t\t\t\t\t\t\t\t\t'instance to the tRPC context.',\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t})(),\n\t\t\t\t);\n\n\t\t\tconst requestId = ctx.requestId ?? crypto.randomUUID();\n\t\t\tconst startTime = ctx.startTime ?? Date.now();\n\n\t\t\treturn runWithRequestContext(\n\t\t\t\t{ logger: ctx.logger, requestId, startTime },\n\t\t\t\tasync () => {\n\t\t\t\t\tconst resolved = await discovery.register(services);\n\t\t\t\t\treturn opts.next({\n\t\t\t\t\t\tctx: { ...opts.ctx, ...resolved } as typeof opts.ctx &\n\t\t\t\t\t\t\tServiceRecord<T>,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\n\t\t// Tag the inner middleware function with the requested services so external\n\t\t// tooling (e.g. detect-procedures route generators) can introspect a\n\t\t// procedure's service dependencies without re-executing middleware.\n\t\tconst middlewares = (\n\t\t\tbuilder as unknown as { _middlewares?: Array<{ _services?: Service[] }> }\n\t\t)._middlewares;\n\t\tif (middlewares?.length) {\n\t\t\tconst last = middlewares[middlewares.length - 1];\n\t\t\tif (last) last._services = services as unknown as Service[];\n\t\t}\n\n\t\treturn builder as TRPCMiddlewareBuilder<\n\t\t\tTContext,\n\t\t\tTMeta,\n\t\t\tServiceRecord<T>,\n\t\t\tunknown\n\t\t>;\n\t}) as ServicesMiddleware<TContext, TMeta>;\n}\n\n/**\n * Create a tRPC middleware that establishes a request context for downstream\n * code without resolving any services. Useful when services aren't needed on\n * a procedure but the handler (or libraries it calls) still wants to read\n * `serviceContext.getLogger()` / `getRequestId()` / `getRequestStartTime()`.\n *\n * `requestId` and `startTime` are pulled from the tRPC context when present,\n * otherwise generated (`crypto.randomUUID()` and `Date.now()`).\n *\n * @example\n * ```ts\n * const withRequestContext = createRequestContextMiddleware(t.middleware);\n * export const baseProcedure = t.procedure.use(withRequestContext);\n * ```\n */\nexport function createRequestContextMiddleware<\n\tTContext extends ContextWithLogger & object,\n\tTMeta extends object,\n>(\n\tmw: CreateMiddleware<TContext, TMeta>,\n): TRPCMiddlewareBuilder<TContext, TMeta, object, unknown> {\n\treturn mw(async (opts) => {\n\t\tconst ctx = opts.ctx as TContext;\n\t\tconst requestId = ctx.requestId ?? crypto.randomUUID();\n\t\tconst startTime = ctx.startTime ?? Date.now();\n\t\treturn runWithRequestContext(\n\t\t\t{ logger: ctx.logger, requestId, startTime },\n\t\t\t() => opts.next(),\n\t\t);\n\t});\n}\n"],"mappings":";;;AAkGA,SAAgB,yBAIfA,IACAC,WACsC;AACtC,QAAQ,CAA4BC,aAAqB;EACxD,MAAM,UAAU,GAAG,OAAO,SAAS;GAClC,MAAM,MAAM,KAAK;GAEjB,MAAM,YACL,IAAI,oBACJ,iBAAiB,YAChB,aACC,CAAC,MAAM;AAIN,UAAM,IAAI,MACT;GAKD,IAAG,CACL;GAEF,MAAM,YAAY,IAAI,aAAa,OAAO,YAAY;GACtD,MAAM,YAAY,IAAI,aAAa,KAAK,KAAK;AAE7C,UAAO,sBACN;IAAE,QAAQ,IAAI;IAAQ;IAAW;GAAW,GAC5C,YAAY;IACX,MAAM,WAAW,MAAM,UAAU,SAAS,SAAS;AACnD,WAAO,KAAK,KAAK,EAChB,KAAK;KAAE,GAAG,KAAK;KAAK,GAAG;IAAU,EAEjC,EAAC;GACF,EACD;EACD,EAAC;EAKF,MAAM,cACL,QACC;AACF,MAAI,aAAa,QAAQ;GACxB,MAAM,OAAO,YAAY,YAAY,SAAS;AAC9C,OAAI,KAAM,MAAK,YAAY;EAC3B;AAED,SAAO;CAMP;AACD;;;;;;;;;;;;;;;;AAiBD,SAAgB,+BAIfF,IAC0D;AAC1D,QAAO,GAAG,OAAO,SAAS;EACzB,MAAM,MAAM,KAAK;EACjB,MAAM,YAAY,IAAI,aAAa,OAAO,YAAY;EACtD,MAAM,YAAY,IAAI,aAAa,KAAK,KAAK;AAC7C,SAAO,sBACN;GAAE,QAAQ,IAAI;GAAQ;GAAW;EAAW,GAC5C,MAAM,KAAK,MAAM,CACjB;CACD,EAAC;AACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
|
+
key = keys[i];
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
22
|
+
value: mod,
|
|
23
|
+
enumerable: true
|
|
24
|
+
}) : target, mod));
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
|
|
28
|
+
Object.defineProperty(exports, '__commonJS', {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return __commonJS;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, '__toESM', {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () {
|
|
37
|
+
return __toESM;
|
|
38
|
+
}
|
|
39
|
+
});
|
package/dist/crons/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
1
|
+
const require_chunk = require('../chunk-DWy1uDak.cjs');
|
|
2
|
+
const require_Construct = require('../Construct-DXfLPGwg.cjs');
|
|
3
|
+
const require_functions = require('../functions-CX21wstW.cjs');
|
|
4
|
+
const __geekmidas_logger_console = require_chunk.__toESM(require("@geekmidas/logger/console"));
|
|
4
5
|
|
|
5
6
|
//#region src/crons/Cron.ts
|
|
6
7
|
var Cron = class extends require_functions.Function {
|
|
@@ -18,7 +19,7 @@ var Cron = class extends require_functions.Function {
|
|
|
18
19
|
|
|
19
20
|
//#endregion
|
|
20
21
|
//#region src/crons/CronBuilder.ts
|
|
21
|
-
var import_lodash =
|
|
22
|
+
var import_lodash = require_chunk.__toESM(require_functions.require_lodash(), 1);
|
|
22
23
|
const DEFAULT_LOGGER = new __geekmidas_logger_console.ConsoleLogger();
|
|
23
24
|
var CronBuilder = class extends require_functions.FunctionBuilder {
|
|
24
25
|
_schedule;
|