@classytic/arc 1.1.0 → 2.1.2
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/README.md +247 -794
- package/bin/arc.js +91 -52
- package/dist/EventTransport-BD2U0BTc.d.mts +100 -0
- package/dist/EventTransport-BD2U0BTc.d.mts.map +1 -0
- package/dist/HookSystem-BsGV-j2l.mjs +405 -0
- package/dist/HookSystem-BsGV-j2l.mjs.map +1 -0
- package/dist/ResourceRegistry-DsN4KJjV.mjs +250 -0
- package/dist/ResourceRegistry-DsN4KJjV.mjs.map +1 -0
- package/dist/adapters/index.d.mts +5 -0
- package/dist/adapters/index.mjs +3 -0
- package/dist/audit/index.d.mts +82 -0
- package/dist/audit/index.d.mts.map +1 -0
- package/dist/audit/index.mjs +276 -0
- package/dist/audit/index.mjs.map +1 -0
- package/dist/audit/mongodb.d.mts +5 -0
- package/dist/audit/mongodb.mjs +3 -0
- package/dist/audited-C3T5DTUx.mjs +141 -0
- package/dist/audited-C3T5DTUx.mjs.map +1 -0
- package/dist/auth/index.d.mts +189 -0
- package/dist/auth/index.d.mts.map +1 -0
- package/dist/auth/index.mjs +1102 -0
- package/dist/auth/index.mjs.map +1 -0
- package/dist/auth/redis-session.d.mts +44 -0
- package/dist/auth/redis-session.d.mts.map +1 -0
- package/dist/auth/redis-session.mjs +76 -0
- package/dist/auth/redis-session.mjs.map +1 -0
- package/dist/betterAuthOpenApi-BrHKeSAx.mjs +250 -0
- package/dist/betterAuthOpenApi-BrHKeSAx.mjs.map +1 -0
- package/dist/cache/index.d.mts +146 -0
- package/dist/cache/index.d.mts.map +1 -0
- package/dist/cache/index.mjs +92 -0
- package/dist/cache/index.mjs.map +1 -0
- package/dist/caching-Bl28lYsR.mjs +94 -0
- package/dist/caching-Bl28lYsR.mjs.map +1 -0
- package/dist/chunk-C7Uep-_p.mjs +20 -0
- package/dist/circuitBreaker-DeY4FCjs.mjs +1097 -0
- package/dist/circuitBreaker-DeY4FCjs.mjs.map +1 -0
- package/dist/cli/commands/describe.d.mts +19 -0
- package/dist/cli/commands/describe.d.mts.map +1 -0
- package/dist/cli/commands/describe.mjs +239 -0
- package/dist/cli/commands/describe.mjs.map +1 -0
- package/dist/cli/commands/docs.d.mts +14 -0
- package/dist/cli/commands/docs.d.mts.map +1 -0
- package/dist/cli/commands/docs.mjs +53 -0
- package/dist/cli/commands/docs.mjs.map +1 -0
- package/dist/cli/commands/{generate.d.ts → generate.d.mts} +3 -1
- package/dist/cli/commands/generate.d.mts.map +1 -0
- package/dist/cli/commands/generate.mjs +358 -0
- package/dist/cli/commands/generate.mjs.map +1 -0
- package/dist/cli/commands/{init.d.ts → init.d.mts} +12 -8
- package/dist/cli/commands/init.d.mts.map +1 -0
- package/dist/cli/commands/{init.js → init.mjs} +807 -616
- package/dist/cli/commands/init.mjs.map +1 -0
- package/dist/cli/commands/introspect.d.mts +11 -0
- package/dist/cli/commands/introspect.d.mts.map +1 -0
- package/dist/cli/commands/introspect.mjs +76 -0
- package/dist/cli/commands/introspect.mjs.map +1 -0
- package/dist/cli/index.d.mts +17 -0
- package/dist/cli/index.d.mts.map +1 -0
- package/dist/cli/index.mjs +157 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/constants-DdXFXQtN.mjs +85 -0
- package/dist/constants-DdXFXQtN.mjs.map +1 -0
- package/dist/core/index.d.mts +5 -0
- package/dist/core/index.mjs +4 -0
- package/dist/createApp-CUgNqegw.mjs +560 -0
- package/dist/createApp-CUgNqegw.mjs.map +1 -0
- package/dist/defineResource-k0_BDn8v.mjs +2197 -0
- package/dist/defineResource-k0_BDn8v.mjs.map +1 -0
- package/dist/discovery/index.d.mts +47 -0
- package/dist/discovery/index.d.mts.map +1 -0
- package/dist/discovery/index.mjs +110 -0
- package/dist/discovery/index.mjs.map +1 -0
- package/dist/docs/index.d.mts +163 -0
- package/dist/docs/index.d.mts.map +1 -0
- package/dist/docs/index.mjs +73 -0
- package/dist/docs/index.mjs.map +1 -0
- package/dist/elevation-BRy3yFWT.mjs +113 -0
- package/dist/elevation-BRy3yFWT.mjs.map +1 -0
- package/dist/elevation-B_2dRLVP.d.mts +88 -0
- package/dist/elevation-B_2dRLVP.d.mts.map +1 -0
- package/dist/errorHandler-BbcgBmIH.d.mts +73 -0
- package/dist/errorHandler-BbcgBmIH.d.mts.map +1 -0
- package/dist/errorHandler-C1okiriz.mjs +109 -0
- package/dist/errorHandler-C1okiriz.mjs.map +1 -0
- package/dist/errors-B9bZok84.mjs +212 -0
- package/dist/errors-B9bZok84.mjs.map +1 -0
- package/dist/errors-ChKiFz62.d.mts +125 -0
- package/dist/errors-ChKiFz62.d.mts.map +1 -0
- package/dist/eventPlugin-CTrLH3mt.d.mts +125 -0
- package/dist/eventPlugin-CTrLH3mt.d.mts.map +1 -0
- package/dist/eventPlugin-DGR_B2on.mjs +230 -0
- package/dist/eventPlugin-DGR_B2on.mjs.map +1 -0
- package/dist/events/index.d.mts +54 -0
- package/dist/events/index.d.mts.map +1 -0
- package/dist/events/index.mjs +52 -0
- package/dist/events/index.mjs.map +1 -0
- package/dist/events/transports/redis-stream-entry.d.mts +2 -0
- package/dist/events/transports/redis-stream-entry.mjs +178 -0
- package/dist/events/transports/redis-stream-entry.mjs.map +1 -0
- package/dist/events/transports/redis.d.mts +77 -0
- package/dist/events/transports/redis.d.mts.map +1 -0
- package/dist/events/transports/redis.mjs +125 -0
- package/dist/events/transports/redis.mjs.map +1 -0
- package/dist/externalPaths-DlINfKbP.d.mts +51 -0
- package/dist/externalPaths-DlINfKbP.d.mts.map +1 -0
- package/dist/factory/index.d.mts +64 -0
- package/dist/factory/index.d.mts.map +1 -0
- package/dist/factory/index.mjs +3 -0
- package/dist/fastifyAdapter-BkrGrlFi.d.mts +217 -0
- package/dist/fastifyAdapter-BkrGrlFi.d.mts.map +1 -0
- package/dist/fields-DyaDVX4J.d.mts +110 -0
- package/dist/fields-DyaDVX4J.d.mts.map +1 -0
- package/dist/fields-iagOozy0.mjs +115 -0
- package/dist/fields-iagOozy0.mjs.map +1 -0
- package/dist/hooks/index.d.mts +4 -0
- package/dist/hooks/index.mjs +3 -0
- package/dist/idempotency/index.d.mts +97 -0
- package/dist/idempotency/index.d.mts.map +1 -0
- package/dist/idempotency/index.mjs +320 -0
- package/dist/idempotency/index.mjs.map +1 -0
- package/dist/idempotency/mongodb.d.mts +2 -0
- package/dist/idempotency/mongodb.mjs +115 -0
- package/dist/idempotency/mongodb.mjs.map +1 -0
- package/dist/idempotency/redis.d.mts +2 -0
- package/dist/idempotency/redis.mjs +104 -0
- package/dist/idempotency/redis.mjs.map +1 -0
- package/dist/index.d.mts +261 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +105 -0
- package/dist/index.mjs.map +1 -0
- package/dist/integrations/event-gateway.d.mts +47 -0
- package/dist/integrations/event-gateway.d.mts.map +1 -0
- package/dist/integrations/event-gateway.mjs +44 -0
- package/dist/integrations/event-gateway.mjs.map +1 -0
- package/dist/integrations/index.d.mts +5 -0
- package/dist/integrations/index.mjs +1 -0
- package/dist/integrations/jobs.d.mts +104 -0
- package/dist/integrations/jobs.d.mts.map +1 -0
- package/dist/integrations/jobs.mjs +124 -0
- package/dist/integrations/jobs.mjs.map +1 -0
- package/dist/integrations/streamline.d.mts +61 -0
- package/dist/integrations/streamline.d.mts.map +1 -0
- package/dist/integrations/streamline.mjs +126 -0
- package/dist/integrations/streamline.mjs.map +1 -0
- package/dist/integrations/websocket.d.mts +83 -0
- package/dist/integrations/websocket.d.mts.map +1 -0
- package/dist/integrations/websocket.mjs +289 -0
- package/dist/integrations/websocket.mjs.map +1 -0
- package/dist/interface-B01JvPVc.d.mts +78 -0
- package/dist/interface-B01JvPVc.d.mts.map +1 -0
- package/dist/interface-CZe8IkMf.d.mts +55 -0
- package/dist/interface-CZe8IkMf.d.mts.map +1 -0
- package/dist/interface-Ch8HU9uM.d.mts +1098 -0
- package/dist/interface-Ch8HU9uM.d.mts.map +1 -0
- package/dist/introspectionPlugin-rFdO8ZUa.mjs +54 -0
- package/dist/introspectionPlugin-rFdO8ZUa.mjs.map +1 -0
- package/dist/keys-BqNejWup.mjs +43 -0
- package/dist/keys-BqNejWup.mjs.map +1 -0
- package/dist/logger-Df2O2WsW.mjs +79 -0
- package/dist/logger-Df2O2WsW.mjs.map +1 -0
- package/dist/memory-cQgelFOj.mjs +144 -0
- package/dist/memory-cQgelFOj.mjs.map +1 -0
- package/dist/migrations/index.d.mts +157 -0
- package/dist/migrations/index.d.mts.map +1 -0
- package/dist/migrations/index.mjs +261 -0
- package/dist/migrations/index.mjs.map +1 -0
- package/dist/mongodb-BfJVlUJH.mjs +94 -0
- package/dist/mongodb-BfJVlUJH.mjs.map +1 -0
- package/dist/mongodb-CGzRbfAK.d.mts +119 -0
- package/dist/mongodb-CGzRbfAK.d.mts.map +1 -0
- package/dist/mongodb-JN-9JA7K.d.mts +72 -0
- package/dist/mongodb-JN-9JA7K.d.mts.map +1 -0
- package/dist/openapi-G3Cw7XuM.mjs +524 -0
- package/dist/openapi-G3Cw7XuM.mjs.map +1 -0
- package/dist/org/index.d.mts +69 -0
- package/dist/org/index.d.mts.map +1 -0
- package/dist/org/index.mjs +514 -0
- package/dist/org/index.mjs.map +1 -0
- package/dist/org/types.d.mts +83 -0
- package/dist/org/types.d.mts.map +1 -0
- package/dist/org/types.mjs +1 -0
- package/dist/permissions/index.d.mts +279 -0
- package/dist/permissions/index.d.mts.map +1 -0
- package/dist/permissions/index.mjs +579 -0
- package/dist/permissions/index.mjs.map +1 -0
- package/dist/plugins/index.d.mts +173 -0
- package/dist/plugins/index.d.mts.map +1 -0
- package/dist/plugins/index.mjs +523 -0
- package/dist/plugins/index.mjs.map +1 -0
- package/dist/plugins/response-cache.d.mts +88 -0
- package/dist/plugins/response-cache.d.mts.map +1 -0
- package/dist/plugins/response-cache.mjs +284 -0
- package/dist/plugins/response-cache.mjs.map +1 -0
- package/dist/plugins/tracing-entry.d.mts +2 -0
- package/dist/plugins/tracing-entry.mjs +186 -0
- package/dist/plugins/tracing-entry.mjs.map +1 -0
- package/dist/pluralize-CEweyOEm.mjs +87 -0
- package/dist/pluralize-CEweyOEm.mjs.map +1 -0
- package/dist/policies/{index.d.ts → index.d.mts} +204 -169
- package/dist/policies/index.d.mts.map +1 -0
- package/dist/policies/index.mjs +322 -0
- package/dist/policies/index.mjs.map +1 -0
- package/dist/presets/{index.d.ts → index.d.mts} +63 -131
- package/dist/presets/index.d.mts.map +1 -0
- package/dist/presets/index.mjs +144 -0
- package/dist/presets/index.mjs.map +1 -0
- package/dist/presets/multiTenant.d.mts +25 -0
- package/dist/presets/multiTenant.d.mts.map +1 -0
- package/dist/presets/multiTenant.mjs +114 -0
- package/dist/presets/multiTenant.mjs.map +1 -0
- package/dist/presets-BITljm96.mjs +120 -0
- package/dist/presets-BITljm96.mjs.map +1 -0
- package/dist/presets-DzSMwlKj.d.mts +58 -0
- package/dist/presets-DzSMwlKj.d.mts.map +1 -0
- package/dist/prisma-DJbMt3yf.mjs +628 -0
- package/dist/prisma-DJbMt3yf.mjs.map +1 -0
- package/dist/prisma-Dg9GoVdj.d.mts +275 -0
- package/dist/prisma-Dg9GoVdj.d.mts.map +1 -0
- package/dist/queryCachePlugin-7THaI5mt.d.mts +72 -0
- package/dist/queryCachePlugin-7THaI5mt.d.mts.map +1 -0
- package/dist/queryCachePlugin-DMBnp2Q0.mjs +139 -0
- package/dist/queryCachePlugin-DMBnp2Q0.mjs.map +1 -0
- package/dist/redis-D-JAeLtm.d.mts +50 -0
- package/dist/redis-D-JAeLtm.d.mts.map +1 -0
- package/dist/redis-stream-Bdh_vUU8.d.mts +104 -0
- package/dist/redis-stream-Bdh_vUU8.d.mts.map +1 -0
- package/dist/registry/index.d.mts +12 -0
- package/dist/registry/index.d.mts.map +1 -0
- package/dist/registry/index.mjs +4 -0
- package/dist/requestContext-QQD6ROJc.mjs +56 -0
- package/dist/requestContext-QQD6ROJc.mjs.map +1 -0
- package/dist/schemaConverter-BwrmWroW.mjs +99 -0
- package/dist/schemaConverter-BwrmWroW.mjs.map +1 -0
- package/dist/schemas/index.d.mts +64 -0
- package/dist/schemas/index.d.mts.map +1 -0
- package/dist/schemas/index.mjs +83 -0
- package/dist/schemas/index.mjs.map +1 -0
- package/dist/scope/index.d.mts +22 -0
- package/dist/scope/index.d.mts.map +1 -0
- package/dist/scope/index.mjs +66 -0
- package/dist/scope/index.mjs.map +1 -0
- package/dist/sessionManager-jPKLbHE0.d.mts +187 -0
- package/dist/sessionManager-jPKLbHE0.d.mts.map +1 -0
- package/dist/sse-B3c3_yZp.mjs +124 -0
- package/dist/sse-B3c3_yZp.mjs.map +1 -0
- package/dist/testing/index.d.mts +908 -0
- package/dist/testing/index.d.mts.map +1 -0
- package/dist/testing/index.mjs +1977 -0
- package/dist/testing/index.mjs.map +1 -0
- package/dist/tracing-Cc7vVQPp.d.mts +71 -0
- package/dist/tracing-Cc7vVQPp.d.mts.map +1 -0
- package/dist/typeGuards-DhMNLuvU.mjs +10 -0
- package/dist/typeGuards-DhMNLuvU.mjs.map +1 -0
- package/dist/types/index.d.mts +947 -0
- package/dist/types/index.d.mts.map +1 -0
- package/dist/types/index.mjs +15 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types-Beqn1Un7.mjs +39 -0
- package/dist/types-Beqn1Un7.mjs.map +1 -0
- package/dist/types-CIgB7UUl.d.mts +446 -0
- package/dist/types-CIgB7UUl.d.mts.map +1 -0
- package/dist/types-aYB4V7uN.d.mts +87 -0
- package/dist/types-aYB4V7uN.d.mts.map +1 -0
- package/dist/utils/index.d.mts +748 -0
- package/dist/utils/index.d.mts.map +1 -0
- package/dist/utils/index.mjs +6 -0
- package/package.json +194 -68
- package/dist/BaseController-DVAiHxEQ.d.ts +0 -233
- package/dist/adapters/index.d.ts +0 -237
- package/dist/adapters/index.js +0 -668
- package/dist/arcCorePlugin-CsShQdyP.d.ts +0 -273
- package/dist/audit/index.d.ts +0 -195
- package/dist/audit/index.js +0 -319
- package/dist/auth/index.d.ts +0 -47
- package/dist/auth/index.js +0 -174
- package/dist/cli/commands/docs.d.ts +0 -11
- package/dist/cli/commands/docs.js +0 -474
- package/dist/cli/commands/generate.js +0 -334
- package/dist/cli/commands/introspect.d.ts +0 -8
- package/dist/cli/commands/introspect.js +0 -338
- package/dist/cli/index.d.ts +0 -4
- package/dist/cli/index.js +0 -3269
- package/dist/core/index.d.ts +0 -220
- package/dist/core/index.js +0 -2786
- package/dist/createApp-Ce9wl8W9.d.ts +0 -77
- package/dist/docs/index.d.ts +0 -166
- package/dist/docs/index.js +0 -658
- package/dist/errors-8WIxGS_6.d.ts +0 -122
- package/dist/events/index.d.ts +0 -117
- package/dist/events/index.js +0 -89
- package/dist/factory/index.d.ts +0 -38
- package/dist/factory/index.js +0 -1652
- package/dist/hooks/index.d.ts +0 -4
- package/dist/hooks/index.js +0 -199
- package/dist/idempotency/index.d.ts +0 -323
- package/dist/idempotency/index.js +0 -500
- package/dist/index-B4t03KQ0.d.ts +0 -1366
- package/dist/index.d.ts +0 -135
- package/dist/index.js +0 -4756
- package/dist/migrations/index.d.ts +0 -185
- package/dist/migrations/index.js +0 -274
- package/dist/org/index.d.ts +0 -129
- package/dist/org/index.js +0 -220
- package/dist/permissions/index.d.ts +0 -144
- package/dist/permissions/index.js +0 -103
- package/dist/plugins/index.d.ts +0 -46
- package/dist/plugins/index.js +0 -1069
- package/dist/policies/index.js +0 -196
- package/dist/presets/index.js +0 -384
- package/dist/presets/multiTenant.d.ts +0 -39
- package/dist/presets/multiTenant.js +0 -112
- package/dist/registry/index.d.ts +0 -16
- package/dist/registry/index.js +0 -253
- package/dist/testing/index.d.ts +0 -618
- package/dist/testing/index.js +0 -48020
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.js +0 -8
- package/dist/types-B99TBmFV.d.ts +0 -76
- package/dist/types-BvckRbs2.d.ts +0 -143
- package/dist/utils/index.d.ts +0 -679
- package/dist/utils/index.js +0 -931
package/dist/core/index.d.ts
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
export { B as BaseController, a as BaseControllerOptions } from '../BaseController-DVAiHxEQ.js';
|
|
2
|
-
import { RouteHandlerMethod, FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
|
|
3
|
-
import { w as FastifyWithDecorators, B as CrudController, _ as CrudRouterOptions, d as RequestWithExtras, a as IRequestContext, c as IControllerResponse, I as IController } from '../index-B4t03KQ0.js';
|
|
4
|
-
export { q as ResourceDefinition, p as defineResource } from '../index-B4t03KQ0.js';
|
|
5
|
-
import { P as PermissionCheck } from '../types-B99TBmFV.js';
|
|
6
|
-
import 'mongoose';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* CRUD Router Factory
|
|
10
|
-
*
|
|
11
|
-
* Creates standard REST routes with permission-based access control.
|
|
12
|
-
* Full TypeScript support with proper Fastify types.
|
|
13
|
-
*
|
|
14
|
-
* Features:
|
|
15
|
-
* - Permission-based access control via PermissionCheck functions
|
|
16
|
-
* - Organization scoping for multi-tenant routes
|
|
17
|
-
* - Consistent route patterns
|
|
18
|
-
* - Framework-agnostic controllers via adapter pattern
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Create CRUD routes for a controller
|
|
23
|
-
*
|
|
24
|
-
* @param fastify - Fastify instance with Arc decorators
|
|
25
|
-
* @param controller - CRUD controller with handler methods
|
|
26
|
-
* @param options - Router configuration
|
|
27
|
-
*/
|
|
28
|
-
declare function createCrudRouter<TDoc = unknown>(fastify: FastifyWithDecorators, controller: CrudController<TDoc> | undefined, options?: CrudRouterOptions): void;
|
|
29
|
-
/**
|
|
30
|
-
* Helper to create org scoped middleware
|
|
31
|
-
*/
|
|
32
|
-
declare function createOrgScopedMiddleware(instance: FastifyWithDecorators): RouteHandlerMethod[];
|
|
33
|
-
/**
|
|
34
|
-
* Create permission middleware from PermissionCheck
|
|
35
|
-
* Useful for custom route registration
|
|
36
|
-
*/
|
|
37
|
-
declare function createPermissionMiddleware(permission: PermissionCheck, resourceName: string, action: string): RouteHandlerMethod | null;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Action Router Factory (Stripe Pattern)
|
|
41
|
-
*
|
|
42
|
-
* Consolidates multiple state-transition endpoints into a single unified action endpoint.
|
|
43
|
-
* Instead of separate endpoints for each action (approve, dispatch, receive, cancel),
|
|
44
|
-
* this creates one endpoint: POST /:id/action
|
|
45
|
-
*
|
|
46
|
-
* Benefits:
|
|
47
|
-
* - 40% fewer endpoints
|
|
48
|
-
* - Consistent permission checking
|
|
49
|
-
* - Self-documenting via action enum
|
|
50
|
-
* - Type-safe action validation
|
|
51
|
-
* - Single audit point for all state transitions
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* import { createActionRouter } from '@classytic/arc';
|
|
55
|
-
* import { requireRoles } from '@classytic/arc/permissions';
|
|
56
|
-
*
|
|
57
|
-
* createActionRouter(fastify, {
|
|
58
|
-
* tag: 'Inventory - Transfers',
|
|
59
|
-
* actions: {
|
|
60
|
-
* approve: async (id, data, req) => transferService.approve(id, req.user),
|
|
61
|
-
* dispatch: async (id, data, req) => transferService.dispatch(id, data.transport, req.user),
|
|
62
|
-
* receive: async (id, data, req) => transferService.receive(id, data, req.user),
|
|
63
|
-
* cancel: async (id, data, req) => transferService.cancel(id, data.reason, req.user),
|
|
64
|
-
* },
|
|
65
|
-
* actionPermissions: {
|
|
66
|
-
* approve: requireRoles(['admin', 'warehouse-manager']),
|
|
67
|
-
* dispatch: requireRoles(['admin', 'warehouse-staff']),
|
|
68
|
-
* receive: requireRoles(['admin', 'store-manager']),
|
|
69
|
-
* cancel: requireRoles(['admin']),
|
|
70
|
-
* },
|
|
71
|
-
* actionSchemas: {
|
|
72
|
-
* dispatch: {
|
|
73
|
-
* transport: { type: 'object', properties: { driver: { type: 'string' } } }
|
|
74
|
-
* },
|
|
75
|
-
* cancel: {
|
|
76
|
-
* reason: { type: 'string', minLength: 10 }
|
|
77
|
-
* },
|
|
78
|
-
* }
|
|
79
|
-
* });
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Action handler function
|
|
84
|
-
* @param id - Resource ID
|
|
85
|
-
* @param data - Action-specific data from request body
|
|
86
|
-
* @param req - Full Fastify request object
|
|
87
|
-
* @returns Action result (will be wrapped in success response)
|
|
88
|
-
*/
|
|
89
|
-
type ActionHandler<TData = any, TResult = any> = (id: string, data: TData, req: RequestWithExtras) => Promise<TResult>;
|
|
90
|
-
/**
|
|
91
|
-
* Action router configuration
|
|
92
|
-
*/
|
|
93
|
-
interface ActionRouterConfig {
|
|
94
|
-
/**
|
|
95
|
-
* OpenAPI tag for grouping routes
|
|
96
|
-
*/
|
|
97
|
-
tag?: string;
|
|
98
|
-
/**
|
|
99
|
-
* Action handlers map
|
|
100
|
-
* @example { approve: (id, data, req) => service.approve(id), ... }
|
|
101
|
-
*/
|
|
102
|
-
actions: Record<string, ActionHandler>;
|
|
103
|
-
/**
|
|
104
|
-
* Per-action permission checks (PermissionCheck functions)
|
|
105
|
-
* @example { approve: requireRoles(['admin', 'manager']), cancel: requireRoles(['admin']) }
|
|
106
|
-
*/
|
|
107
|
-
actionPermissions?: Record<string, PermissionCheck>;
|
|
108
|
-
/**
|
|
109
|
-
* Per-action JSON schema for body validation
|
|
110
|
-
* @example { dispatch: { transport: { type: 'object' } } }
|
|
111
|
-
*/
|
|
112
|
-
actionSchemas?: Record<string, Record<string, any>>;
|
|
113
|
-
/**
|
|
114
|
-
* Global permission check applied to all actions (if action-specific not defined)
|
|
115
|
-
*/
|
|
116
|
-
globalAuth?: PermissionCheck;
|
|
117
|
-
/**
|
|
118
|
-
* Optional idempotency service
|
|
119
|
-
* If provided, will handle idempotency-key header
|
|
120
|
-
*/
|
|
121
|
-
idempotencyService?: IdempotencyService;
|
|
122
|
-
/**
|
|
123
|
-
* Custom error handler for action execution failures
|
|
124
|
-
* @param error - The error thrown by action handler
|
|
125
|
-
* @param action - The action that failed
|
|
126
|
-
* @param id - The resource ID
|
|
127
|
-
* @returns Status code and error response
|
|
128
|
-
*/
|
|
129
|
-
onError?: (error: Error, action: string, id: string) => {
|
|
130
|
-
statusCode: number;
|
|
131
|
-
error: string;
|
|
132
|
-
code?: string;
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Idempotency service interface
|
|
137
|
-
* Apps can provide their own implementation
|
|
138
|
-
*/
|
|
139
|
-
interface IdempotencyService {
|
|
140
|
-
check(key: string, payload: any): Promise<{
|
|
141
|
-
isNew: boolean;
|
|
142
|
-
existingResult?: any;
|
|
143
|
-
}>;
|
|
144
|
-
complete(key: string | undefined, result: any): Promise<void>;
|
|
145
|
-
fail(key: string | undefined, error: Error): Promise<void>;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Create action-based state transition endpoint
|
|
149
|
-
*
|
|
150
|
-
* Registers: POST /:id/action
|
|
151
|
-
* Body: { action: string, ...actionData }
|
|
152
|
-
*
|
|
153
|
-
* @param fastify - Fastify instance
|
|
154
|
-
* @param config - Action router configuration
|
|
155
|
-
*/
|
|
156
|
-
declare function createActionRouter(fastify: FastifyInstance, config: ActionRouterConfig): void;
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Fastify Adapter for IController
|
|
160
|
-
*
|
|
161
|
-
* Converts between Fastify's request/reply and framework-agnostic IRequestContext/IControllerResponse.
|
|
162
|
-
* This allows controllers implementing IController to work seamlessly with Fastify.
|
|
163
|
-
*/
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Create IRequestContext from Fastify request
|
|
167
|
-
*
|
|
168
|
-
* Extracts framework-agnostic context from Fastify-specific request object
|
|
169
|
-
*/
|
|
170
|
-
declare function createRequestContext(req: FastifyRequest): IRequestContext;
|
|
171
|
-
/**
|
|
172
|
-
* Send IControllerResponse via Fastify reply
|
|
173
|
-
*
|
|
174
|
-
* Converts framework-agnostic response to Fastify response
|
|
175
|
-
* Applies field masking if specified in request
|
|
176
|
-
*/
|
|
177
|
-
declare function sendControllerResponse<T>(reply: FastifyReply, response: IControllerResponse<T>, request?: FastifyRequest): void;
|
|
178
|
-
/**
|
|
179
|
-
* Create Fastify route handler from IController method
|
|
180
|
-
*
|
|
181
|
-
* Wraps framework-agnostic controller method in Fastify-specific handler
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```typescript
|
|
185
|
-
* const controller = new BaseController(repository);
|
|
186
|
-
*
|
|
187
|
-
* // Create Fastify handler
|
|
188
|
-
* const listHandler = createFastifyHandler(controller.list.bind(controller));
|
|
189
|
-
*
|
|
190
|
-
* // Register route
|
|
191
|
-
* fastify.get('/products', listHandler);
|
|
192
|
-
* ```
|
|
193
|
-
*/
|
|
194
|
-
declare function createFastifyHandler<T>(controllerMethod: (req: IRequestContext) => Promise<IControllerResponse<T>>): (req: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
195
|
-
/**
|
|
196
|
-
* Create Fastify adapters for all CRUD methods of an IController
|
|
197
|
-
*
|
|
198
|
-
* Returns Fastify-compatible handlers for each CRUD operation
|
|
199
|
-
*
|
|
200
|
-
* @example
|
|
201
|
-
* ```typescript
|
|
202
|
-
* const controller = new BaseController(repository);
|
|
203
|
-
* const handlers = createCrudHandlers(controller);
|
|
204
|
-
*
|
|
205
|
-
* fastify.get('/', handlers.list);
|
|
206
|
-
* fastify.get('/:id', handlers.get);
|
|
207
|
-
* fastify.post('/', handlers.create);
|
|
208
|
-
* fastify.patch('/:id', handlers.update);
|
|
209
|
-
* fastify.delete('/:id', handlers.delete);
|
|
210
|
-
* ```
|
|
211
|
-
*/
|
|
212
|
-
declare function createCrudHandlers<TDoc>(controller: IController<TDoc>): {
|
|
213
|
-
list: (req: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
214
|
-
get: (req: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
215
|
-
create: (req: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
216
|
-
update: (req: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
217
|
-
delete: (req: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
export { type ActionHandler, type ActionRouterConfig, type IdempotencyService, createActionRouter, createCrudHandlers, createCrudRouter, createFastifyHandler, createOrgScopedMiddleware, createPermissionMiddleware, createRequestContext, sendControllerResponse };
|