@classytic/arc 2.9.1 → 2.10.8
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 +20 -91
- package/dist/{BaseController-Vu2yc56T.mjs → BaseController-DVNKvoX4.mjs} +154 -170
- package/dist/{ResourceRegistry-Dq3_zBQP.mjs → ResourceRegistry-CcN2LVrc.mjs} +1 -1
- package/dist/actionPermissions-TUVR3uiZ.mjs +22 -0
- package/dist/adapters/index.d.mts +3 -3
- package/dist/adapters/index.mjs +2 -2
- package/dist/{adapters-BBqAVvPK.mjs → adapters-BXY4i-hw.mjs} +210 -41
- package/dist/audit/index.d.mts +38 -3
- package/dist/audit/index.mjs +54 -22
- package/dist/auth/index.d.mts +2 -2
- package/dist/auth/index.mjs +3 -3
- package/dist/cache/index.d.mts +17 -15
- package/dist/cache/index.mjs +16 -15
- package/dist/{caching-CjybdRwx.mjs → caching-3h93rkJM.mjs} +8 -3
- package/dist/cli/commands/describe.mjs +1 -1
- package/dist/cli/commands/docs.mjs +2 -2
- package/dist/cli/commands/init.mjs +1 -1
- package/dist/cli/commands/introspect.mjs +1 -1
- package/dist/context/index.d.mts +58 -0
- package/dist/context/index.mjs +2 -0
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +3 -4
- package/dist/{defineResource-C__jkwvs.mjs → core-3MWJosCH.mjs} +174 -94
- package/dist/{createActionRouter-DH1YFL9m.mjs → createActionRouter-C8UUB3Px.mjs} +1 -1
- package/dist/{createApp-CBJUJKGP.mjs → createApp-BwnEAO2h.mjs} +53 -19
- package/dist/docs/index.d.mts +1 -1
- package/dist/docs/index.mjs +2 -2
- package/dist/{elevation-DxQ6ACbt.mjs → elevation-Dci0AYLT.mjs} +2 -2
- package/dist/errorHandler-2ii4RIYr.d.mts +114 -0
- package/dist/{errorHandler-CZDW4EXS.mjs → errorHandler-CSxe7KIM.mjs} +1 -1
- package/dist/{eventPlugin-Dl7MoVWH.mjs → eventPlugin-ByU4Cv0e.mjs} +1 -1
- package/dist/{eventPlugin-BxvaCIZF.d.mts → eventPlugin-D1ThQ1Pp.d.mts} +1 -1
- package/dist/events/index.d.mts +8 -5
- package/dist/events/index.mjs +87 -52
- package/dist/events/transports/redis-stream-entry.d.mts +1 -1
- package/dist/events/transports/redis.d.mts +1 -1
- package/dist/factory/index.d.mts +1 -1
- package/dist/factory/index.mjs +1 -1
- package/dist/{types-DZi1aYhm.d.mts → fields-C8Y0XLAu.d.mts} +122 -2
- package/dist/hooks/index.d.mts +1 -1
- package/dist/idempotency/index.d.mts +5 -2
- package/dist/idempotency/index.mjs +46 -37
- package/dist/{interface-YrWsmKqE.d.mts → index-BGbpGVyM.d.mts} +2107 -2756
- package/dist/{index-CtGKT0lf.d.mts → index-BziRPS4H.d.mts} +81 -7
- package/dist/{index-C-xjcA6F.d.mts → index-C_Noptz-.d.mts} +284 -409
- package/dist/{index-Cibkchnx.d.mts → index-EqQN6p0W.d.mts} +3 -3
- package/dist/index.d.mts +6 -219
- package/dist/index.mjs +10 -131
- package/dist/integrations/event-gateway.d.mts +1 -1
- package/dist/integrations/event-gateway.mjs +1 -1
- package/dist/integrations/index.d.mts +1 -1
- package/dist/integrations/mcp/index.d.mts +2 -2
- package/dist/integrations/mcp/index.mjs +1 -1
- package/dist/integrations/mcp/testing.d.mts +1 -1
- package/dist/integrations/mcp/testing.mjs +1 -1
- package/dist/interface-yhyb_pLY.d.mts +77 -0
- package/dist/logger/index.d.mts +81 -0
- package/dist/{logger-CDjpjySd.mjs → logger/index.mjs} +1 -6
- package/dist/{memory-BFAYkf8H.mjs → memory-DqI-449b.mjs} +23 -8
- package/dist/middleware/index.d.mts +109 -0
- package/dist/middleware/index.mjs +70 -0
- package/dist/multipartBody-CUQGVlM_.mjs +123 -0
- package/dist/{openapi-CXuTG1M9.mjs → openapi-DpNpqBmo.mjs} +9 -7
- package/dist/org/index.d.mts +2 -2
- package/dist/permissions/index.d.mts +3 -4
- package/dist/permissions/index.mjs +5 -5
- package/dist/{permissions-oNZawnkR.mjs → permissions-wkqRwicB.mjs} +315 -397
- package/dist/pipe-CGJxqDGx.mjs +62 -0
- package/dist/pipeline/index.d.mts +62 -0
- package/dist/pipeline/index.mjs +53 -0
- package/dist/plugins/index.d.mts +23 -3
- package/dist/plugins/index.mjs +9 -11
- package/dist/plugins/response-cache.mjs +1 -1
- package/dist/plugins/tracing-entry.mjs +1 -1
- package/dist/presets/filesUpload.d.mts +3 -3
- package/dist/presets/filesUpload.mjs +255 -1
- package/dist/presets/index.d.mts +1 -1
- package/dist/presets/index.mjs +2 -2
- package/dist/presets/multiTenant.d.mts +1 -1
- package/dist/presets/multiTenant.mjs +43 -9
- package/dist/presets/search.d.mts +91 -4
- package/dist/presets/search.mjs +1 -1
- package/dist/{presets-hM4WhNWY.mjs → presets-CrwOvuXI.mjs} +1 -1
- package/dist/{queryCachePlugin-DbUVroUG.mjs → queryCachePlugin-ChLNZvFT.mjs} +9 -9
- package/dist/{queryCachePlugin-CnTZZTC5.d.mts → queryCachePlugin-Dumka73q.d.mts} +1 -1
- package/dist/{queryParser-Cs-6SHQK.mjs → queryParser-NR__Qiju.mjs} +69 -2
- package/dist/{redis-stream-Bz-4q96t.d.mts → redis-stream-bkO88VHx.d.mts} +1 -1
- package/dist/registry/index.d.mts +1 -1
- package/dist/registry/index.mjs +1 -1
- package/dist/{requestContext-DYtmNpm5.mjs → requestContext-C38GskNt.mjs} +1 -1
- package/dist/{resourceToTools-C3cWymnW.mjs → resourceToTools-BhF3JV5p.mjs} +8 -3
- package/dist/scope/index.d.mts +2 -2
- package/dist/scope/index.mjs +2 -2
- package/dist/{sse-CJpt7LGI.mjs → sse-D8UeDwis.mjs} +1 -1
- package/dist/{store-helpers-DFiZl5TL.mjs → store-helpers-DYYUQbQN.mjs} +4 -0
- package/dist/testing/index.d.mts +6 -5
- package/dist/testing/index.mjs +17 -10
- package/dist/types/index.d.mts +5 -5
- package/dist/types/index.mjs +1 -31
- package/dist/types-CDnTEpga.mjs +27 -0
- package/dist/{types-CoSzA-s-.d.mts → types-CVKBssX5.d.mts} +1 -1
- package/dist/{types-CunEX4UX.d.mts → types-CVdgPXBW.d.mts} +20 -7
- package/dist/utils/index.d.mts +277 -3
- package/dist/utils/index.mjs +4 -5
- package/dist/{utils-B7FuRr9w.mjs → utils-LMwVidKy.mjs} +303 -2
- package/dist/{versioning-Cm8qoFDg.mjs → versioning-B6mimogM.mjs} +3 -5
- package/dist/versioning-CeUXHfjw.d.mts +117 -0
- package/package.json +31 -18
- package/skills/arc/SKILL.md +8 -12
- package/skills/arc/references/production.md +0 -41
- package/dist/circuitBreaker-CvXkjfrW.d.mts +0 -206
- package/dist/circuitBreaker-l18oRgL5.mjs +0 -284
- package/dist/core-DNncu0xF.mjs +0 -34
- package/dist/dynamic/index.d.mts +0 -93
- package/dist/dynamic/index.mjs +0 -122
- package/dist/errorHandler-DixGcttC.d.mts +0 -218
- package/dist/fields-BC7zcmI9.d.mts +0 -121
- package/dist/filesUpload-q8oHt--L.mjs +0 -377
- package/dist/interface-DplgQO2e.d.mts +0 -54
- package/dist/policies/index.d.mts +0 -425
- package/dist/policies/index.mjs +0 -318
- package/dist/rpc/index.d.mts +0 -90
- package/dist/rpc/index.mjs +0 -248
- /package/dist/{EventTransport-CqZ8FyM_.d.mts → EventTransport-CfVEGaEl.d.mts} +0 -0
- /package/dist/{applyPermissionResult-bqGpo9ML.mjs → applyPermissionResult-QhV1Pa-g.mjs} +0 -0
- /package/dist/{constants-Cxde4rpC.mjs → constants-BhY1OHoH.mjs} +0 -0
- /package/dist/{elevation-B6S5csVA.d.mts → elevation-s5ykdNHr.d.mts} +0 -0
- /package/dist/{errors-CqWnSqM-.mjs → errors-BqdUDja_.mjs} +0 -0
- /package/dist/{fields-CU6FlaDV.mjs → fields-CTMWOUDt.mjs} +0 -0
- /package/dist/{keys-qcD-TVJl.mjs → keys-nWQGUTu1.mjs} +0 -0
- /package/dist/{types-ZUu_h0jp.mjs → types-D57iXYb8.mjs} +0 -0
- /package/dist/{types-BD85MlEK.d.mts → types-tgR4Pt8F.d.mts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { B as ResourceDefinition, C as RequestContext, F as FastifyWithDecorators, Mt as IControllerResponse, Nt as IRequestContext, T as CrudRouterOptions, Yt as AnyRecord, bt as ResourceConfig, ct as CrudController, jt as IController } from "./index-BGbpGVyM.mjs";
|
|
2
|
+
import { r as RequestScope } from "./types-tgR4Pt8F.mjs";
|
|
3
|
+
import { c as PermissionCheck } from "./fields-C8Y0XLAu.mjs";
|
|
4
4
|
import { FastifyReply, FastifyRequest, RouteHandlerMethod } from "fastify";
|
|
5
5
|
|
|
6
6
|
//#region src/constants.d.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -1,68 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as applyFieldWritePermissions, i as applyFieldReadPermissions, n as FieldPermissionMap, o as fields, t as FieldPermission } from "./fields-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { C as authenticated, D as publicRead, E as presets_d_exports, O as publicReadAdminWrite, S as adminOnly, T as ownerWithAdminBypass, _ as requireScopeContext, a as allOf, c as createDynamicPermissionMatrix, d as requireAuth, f as requireOrgInScope, g as requireRoles, h as requireOwnership, k as readOnly, l as createOrgPermissions, m as requireOrgRole, n as DynamicPermissionMatrix, o as allowPublic, p as requireOrgMembership, r as DynamicPermissionMatrixConfig, s as anyOf, u as denyAll, v as requireServiceScope, w as fullPublic, x as when, y as requireTeamMembership } from "./index-C-xjcA6F.mjs";
|
|
1
|
+
import { A as RequestIdOptions, B as ResourceDefinition, C as RequestContext, D as HealthCheck, Dt as RouteSchemaOptions, E as GracefulShutdownOptions, F as FastifyWithDecorators, L as RequestWithExtras, Mt as IControllerResponse, N as FastifyRequestExtras, Nt as IRequestContext, O as HealthOptions, P as FastifyWithAuth, Pt as RouteHandler, Qt as JWTPayload, T as CrudRouterOptions, V as defineResource, Wt as AuthPluginOptions, Xt as ApiResponse, Yt as AnyRecord, Zt as ArcRequest, _n as RepositoryLike, _t as PresetResult, a as InferAdapterDoc, an as BaseControllerOptions, bt as ResourceConfig, c as TypedController, ct as CrudController, d as PaginationResult, dt as EventDefinition, f as IntrospectionData, ft as FieldRule, g as ArcInternalMetadata, gn as RelationMetadata, h as ResourceMetadata, hn as FieldMetadata, ht as PresetFunction, i as ValidationResult$1, in as BaseController, jt as IController, k as IntrospectionPluginOptions, kt as ControllerLike, l as TypedRepository, lt as CrudRouteKey, m as RegistryStats, mn as DataAdapter, n as ConfigError, nn as envelope, o as InferDocType, p as RegistryEntry, pt as MiddlewareConfig, r as ValidateOptions, s as InferResourceDoc, t as RouteHandlerMethod, tn as UserOrganization, u as TypedResourceConfig, ut as CrudSchemas, vn as SchemaMetadata, vt as RateLimitConfig, w as ServiceContext, y as OwnershipCheck, yn as ValidationResult } from "./index-BGbpGVyM.mjs";
|
|
2
|
+
import { a as applyFieldWritePermissions, c as PermissionCheck, d as UserBase, i as applyFieldReadPermissions, l as PermissionContext, n as FieldPermissionMap, o as fields, t as FieldPermission, u as PermissionResult } from "./fields-C8Y0XLAu.mjs";
|
|
3
|
+
import { l as createMongooseAdapter, o as createPrismaAdapter, s as MongooseAdapter, t as PrismaAdapter } from "./index-BziRPS4H.mjs";
|
|
4
|
+
import { C as MAX_REGEX_LENGTH, D as RESERVED_QUERY_PARAMS, E as MutationOperation, O as SYSTEM_FIELDS, S as MAX_FILTER_DEPTH, T as MUTATION_OPERATIONS, _ as DEFAULT_UPDATE_METHOD, a as getControllerScope, b as HookOperation, d as CrudOperation, f as DEFAULT_ID_FIELD, g as DEFAULT_TENANT_FIELD, h as DEFAULT_SORT, m as DEFAULT_MAX_LIMIT, p as DEFAULT_LIMIT, s as defineResourceVariants, u as CRUD_OPERATIONS, v as HOOK_OPERATIONS, w as MAX_SEARCH_LENGTH, x as HookPhase, y as HOOK_PHASES } from "./index-EqQN6p0W.mjs";
|
|
5
|
+
import { A as requireRoles, C as allOf, E as denyAll, M as when, O as requireAuth, S as createOrgPermissions, T as anyOf, a as presets_d_exports, c as readOnly, d as requireOrgRole, f as requireScopeContext, i as ownerWithAdminBypass, k as requireOwnership, l as requireOrgInScope, m as requireTeamMembership, n as authenticated, o as publicRead, p as requireServiceScope, r as fullPublic, s as publicReadAdminWrite, t as adminOnly, u as requireOrgMembership, v as DynamicPermissionMatrix, w as allowPublic, x as createDynamicPermissionMatrix, y as DynamicPermissionMatrixConfig } from "./index-C_Noptz-.mjs";
|
|
7
6
|
import { a as NotFoundError, d as ValidationError, f as createDomainError, i as ForbiddenError, t as ArcError, u as UnauthorizedError } from "./errors-BI8kEKsO.mjs";
|
|
8
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
9
|
-
import { RouteHandlerMethod as RouteHandlerMethod$1 } from "fastify";
|
|
10
7
|
|
|
11
|
-
//#region src/context/requestContext.d.ts
|
|
12
|
-
/**
|
|
13
|
-
* Shape of the request-scoped context store.
|
|
14
|
-
* Populated by Arc's onRequest hook in arcCorePlugin.
|
|
15
|
-
*/
|
|
16
|
-
interface RequestStore {
|
|
17
|
-
/** Unique request identifier */
|
|
18
|
-
requestId?: string;
|
|
19
|
-
/** Authenticated user (if any) */
|
|
20
|
-
user?: {
|
|
21
|
-
id?: string;
|
|
22
|
-
_id?: string;
|
|
23
|
-
roles?: string[];
|
|
24
|
-
[key: string]: unknown;
|
|
25
|
-
} | null;
|
|
26
|
-
/** Active organization ID (multi-tenant) */
|
|
27
|
-
organizationId?: string;
|
|
28
|
-
/** Active team ID (team-scoped resources) */
|
|
29
|
-
teamId?: string;
|
|
30
|
-
/** Current resource name (set by arcDecorator in CRUD routes) */
|
|
31
|
-
resourceName?: string;
|
|
32
|
-
/** Request start time (for timing) */
|
|
33
|
-
startTime: number;
|
|
34
|
-
/** Additional context — extensible by app */
|
|
35
|
-
[key: string]: unknown;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Request context API.
|
|
39
|
-
*
|
|
40
|
-
* - `get()` — returns current store or undefined if outside request scope
|
|
41
|
-
* - `run(store, fn)` — run a function with a specific store (used by Arc internals)
|
|
42
|
-
* - `getStore()` — alias for get() (matches Node.js API naming)
|
|
43
|
-
*/
|
|
44
|
-
declare const requestContext: {
|
|
45
|
-
/**
|
|
46
|
-
* Get the current request context.
|
|
47
|
-
* Returns undefined if called outside a request lifecycle.
|
|
48
|
-
*/
|
|
49
|
-
get(): RequestStore | undefined;
|
|
50
|
-
/**
|
|
51
|
-
* Alias for get() — matches Node.js AsyncLocalStorage API naming.
|
|
52
|
-
*/
|
|
53
|
-
getStore(): RequestStore | undefined;
|
|
54
|
-
/**
|
|
55
|
-
* Run a function within a specific request context.
|
|
56
|
-
* Used internally by Arc's onRequest hook.
|
|
57
|
-
*/
|
|
58
|
-
run<T>(store: RequestStore, fn: () => T): T;
|
|
59
|
-
/**
|
|
60
|
-
* The underlying AsyncLocalStorage instance.
|
|
61
|
-
* Exposed for advanced use cases (testing, custom integrations).
|
|
62
|
-
*/
|
|
63
|
-
storage: AsyncLocalStorage<RequestStore>;
|
|
64
|
-
};
|
|
65
|
-
//#endregion
|
|
66
8
|
//#region src/core/validateResourceConfig.d.ts
|
|
67
9
|
interface ConfigError$1 {
|
|
68
10
|
field: string;
|
|
@@ -95,162 +37,7 @@ declare function formatValidationErrors(resourceName: string, result: Validation
|
|
|
95
37
|
*/
|
|
96
38
|
declare function assertValidConfig(config: ResourceConfig, options?: ValidateOptions$1): void;
|
|
97
39
|
//#endregion
|
|
98
|
-
//#region src/middleware/middleware.d.ts
|
|
99
|
-
interface NamedMiddleware {
|
|
100
|
-
/** Unique name for debugging/introspection */
|
|
101
|
-
readonly name: string;
|
|
102
|
-
/** Operations this middleware applies to (default: all) */
|
|
103
|
-
readonly operations?: Array<"list" | "get" | "create" | "update" | "delete" | string>;
|
|
104
|
-
/** Priority — lower numbers run first (default: 10) */
|
|
105
|
-
readonly priority: number;
|
|
106
|
-
/** Conditional execution — return true to run, false to skip */
|
|
107
|
-
readonly when?: (request: RequestWithExtras) => boolean | Promise<boolean>;
|
|
108
|
-
/** The middleware handler */
|
|
109
|
-
readonly handler: MiddlewareHandler;
|
|
110
|
-
}
|
|
111
|
-
interface MiddlewareOptions {
|
|
112
|
-
operations?: NamedMiddleware["operations"];
|
|
113
|
-
priority?: number;
|
|
114
|
-
when?: NamedMiddleware["when"];
|
|
115
|
-
handler: MiddlewareHandler;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Create a named middleware with priority and conditions.
|
|
119
|
-
*/
|
|
120
|
-
declare function middleware(name: string, options: MiddlewareOptions): NamedMiddleware;
|
|
121
|
-
/**
|
|
122
|
-
* Sort named middlewares by priority (ascending — lower runs first).
|
|
123
|
-
* Returns a MiddlewareConfig map keyed by operation, ready to pass to `defineResource()`.
|
|
124
|
-
*/
|
|
125
|
-
declare function sortMiddlewares(middlewares: NamedMiddleware[]): MiddlewareConfig;
|
|
126
|
-
//#endregion
|
|
127
|
-
//#region src/pipeline/guard.d.ts
|
|
128
|
-
interface GuardOptions {
|
|
129
|
-
operations?: OperationFilter;
|
|
130
|
-
handler: (ctx: PipelineContext) => boolean | Promise<boolean>;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Create a named guard.
|
|
134
|
-
*
|
|
135
|
-
* @param name - Guard name (for debugging/introspection)
|
|
136
|
-
* @param handlerOrOptions - Handler function or options object
|
|
137
|
-
*/
|
|
138
|
-
declare function guard(name: string, handlerOrOptions: ((ctx: PipelineContext) => boolean | Promise<boolean>) | GuardOptions): Guard;
|
|
139
|
-
//#endregion
|
|
140
|
-
//#region src/pipeline/intercept.d.ts
|
|
141
|
-
interface InterceptOptions {
|
|
142
|
-
operations?: OperationFilter;
|
|
143
|
-
handler: (ctx: PipelineContext, next: NextFunction) => Promise<IControllerResponse<unknown>>;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Create a named interceptor.
|
|
147
|
-
*
|
|
148
|
-
* @param name - Interceptor name (for debugging/introspection)
|
|
149
|
-
* @param handlerOrOptions - Handler function or options object
|
|
150
|
-
*/
|
|
151
|
-
declare function intercept(name: string, handlerOrOptions: ((ctx: PipelineContext, next: NextFunction) => Promise<IControllerResponse<unknown>>) | InterceptOptions): Interceptor;
|
|
152
|
-
//#endregion
|
|
153
|
-
//#region src/pipeline/pipe.d.ts
|
|
154
|
-
/**
|
|
155
|
-
* Compose pipeline steps into an ordered array.
|
|
156
|
-
* Accepts guards, transforms, and interceptors in any order.
|
|
157
|
-
*/
|
|
158
|
-
declare function pipe(...steps: PipelineStep[]): PipelineStep[];
|
|
159
|
-
//#endregion
|
|
160
|
-
//#region src/pipeline/transform.d.ts
|
|
161
|
-
interface TransformOptions {
|
|
162
|
-
operations?: OperationFilter;
|
|
163
|
-
handler: (ctx: PipelineContext) => PipelineContext | undefined | Promise<PipelineContext | undefined>;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Create a named transform.
|
|
167
|
-
*
|
|
168
|
-
* @param name - Transform name (for debugging/introspection)
|
|
169
|
-
* @param handlerOrOptions - Handler function or options object
|
|
170
|
-
*/
|
|
171
|
-
declare function transform(name: string, handlerOrOptions: ((ctx: PipelineContext) => PipelineContext | undefined | Promise<PipelineContext | undefined>) | TransformOptions): Transform;
|
|
172
|
-
//#endregion
|
|
173
|
-
//#region src/logger/index.d.ts
|
|
174
|
-
/**
|
|
175
|
-
* Arc Logger — Centralized debug & warning system
|
|
176
|
-
*
|
|
177
|
-
* Lightweight, zero-dependency logger for Arc framework internals.
|
|
178
|
-
* Inspired by the `debug` npm package — disabled by default, opt-in via
|
|
179
|
-
* environment variable or `createApp({ debug })` option.
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* ```typescript
|
|
183
|
-
* // Enable via env var
|
|
184
|
-
* ARC_DEBUG=1 node server.js // all modules
|
|
185
|
-
* ARC_DEBUG=scope,elevation node server.js // specific modules
|
|
186
|
-
*
|
|
187
|
-
* // Enable via createApp
|
|
188
|
-
* const app = await createApp({ debug: true });
|
|
189
|
-
* const app = await createApp({ debug: 'scope,elevation' });
|
|
190
|
-
*
|
|
191
|
-
* // Suppress warnings (not recommended)
|
|
192
|
-
* ARC_SUPPRESS_WARNINGS=1 node server.js
|
|
193
|
-
*
|
|
194
|
-
* // Framework internals use:
|
|
195
|
-
* import { arcLog } from '../logger/index.js';
|
|
196
|
-
* const log = arcLog('elevation');
|
|
197
|
-
* log.debug('Elevation applied', { userId });
|
|
198
|
-
* log.warn('Something unexpected');
|
|
199
|
-
* ```
|
|
200
|
-
*/
|
|
201
|
-
interface ArcLoggerOptions {
|
|
202
|
-
/**
|
|
203
|
-
* Enable debug output.
|
|
204
|
-
* - `true` or `'*'` — all modules
|
|
205
|
-
* - `string` — comma-separated module names (e.g., `'scope,elevation'`)
|
|
206
|
-
* - `false` — disabled (default)
|
|
207
|
-
*/
|
|
208
|
-
debug?: boolean | string;
|
|
209
|
-
/**
|
|
210
|
-
* Custom log writer. Defaults to `console`.
|
|
211
|
-
* Useful for routing Arc logs into Fastify's pino logger or test fixtures.
|
|
212
|
-
*/
|
|
213
|
-
writer?: ArcLogWriter;
|
|
214
|
-
}
|
|
215
|
-
interface ArcLogWriter {
|
|
216
|
-
debug: (...args: unknown[]) => void;
|
|
217
|
-
info: (...args: unknown[]) => void;
|
|
218
|
-
warn: (...args: unknown[]) => void;
|
|
219
|
-
error: (...args: unknown[]) => void;
|
|
220
|
-
}
|
|
221
|
-
interface ArcLogger {
|
|
222
|
-
debug: (...args: unknown[]) => void;
|
|
223
|
-
info: (...args: unknown[]) => void;
|
|
224
|
-
warn: (...args: unknown[]) => void;
|
|
225
|
-
error: (...args: unknown[]) => void;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Configure the Arc logger globally.
|
|
229
|
-
*
|
|
230
|
-
* Called automatically by `createApp({ debug })`, but can also be
|
|
231
|
-
* called manually for standalone usage outside of `createApp`.
|
|
232
|
-
*/
|
|
233
|
-
declare function configureArcLogger(options: ArcLoggerOptions): void;
|
|
234
|
-
/**
|
|
235
|
-
* Create a module-scoped logger.
|
|
236
|
-
*
|
|
237
|
-
* Debug and info messages are gated by the `ARC_DEBUG` env var or
|
|
238
|
-
* `createApp({ debug })` option. Warnings always show (unless
|
|
239
|
-
* `ARC_SUPPRESS_WARNINGS=1`). Errors always show.
|
|
240
|
-
*
|
|
241
|
-
* @param module - Module name (e.g., 'scope', 'elevation', 'sse', 'preset')
|
|
242
|
-
* @returns Logger instance for that module
|
|
243
|
-
*
|
|
244
|
-
* @example
|
|
245
|
-
* ```typescript
|
|
246
|
-
* const log = arcLog('elevation');
|
|
247
|
-
* log.debug('Checking elevation header');
|
|
248
|
-
* log.warn('No authenticate decorator found');
|
|
249
|
-
* ```
|
|
250
|
-
*/
|
|
251
|
-
declare function arcLog(module: string): ArcLogger;
|
|
252
|
-
//#endregion
|
|
253
40
|
//#region src/index.d.ts
|
|
254
41
|
declare const version: string;
|
|
255
42
|
//#endregion
|
|
256
|
-
export { type ValidationResult as AdapterValidationResult, type AnyRecord, type ApiResponse, ArcError, type ArcInternalMetadata, type
|
|
43
|
+
export { type ValidationResult as AdapterValidationResult, type AnyRecord, type ApiResponse, ArcError, type ArcInternalMetadata, type ArcRequest, type AuthPluginOptions, BaseController, type BaseControllerOptions, CRUD_OPERATIONS, type ConfigError, type ControllerLike, type CrudController, CrudOperation, type CrudRouteKey, type CrudRouterOptions, type CrudSchemas, DEFAULT_ID_FIELD, DEFAULT_LIMIT, DEFAULT_MAX_LIMIT, DEFAULT_SORT, DEFAULT_TENANT_FIELD, DEFAULT_UPDATE_METHOD, type DataAdapter, type DynamicPermissionMatrix, type DynamicPermissionMatrixConfig, type EventDefinition, type FastifyRequestExtras, type FastifyWithAuth, type FastifyWithDecorators, type FieldMetadata, type FieldPermission, type FieldPermissionMap, type FieldRule, ForbiddenError, type GracefulShutdownOptions, HOOK_OPERATIONS, HOOK_PHASES, type HealthCheck, type HealthOptions, HookOperation, HookPhase, type IController, type IControllerResponse, type IRequestContext, type InferAdapterDoc, type InferDocType, type InferResourceDoc, type IntrospectionData, type IntrospectionPluginOptions, type JWTPayload, MAX_FILTER_DEPTH, MAX_REGEX_LENGTH, MAX_SEARCH_LENGTH, MUTATION_OPERATIONS, type MiddlewareConfig, MongooseAdapter, MutationOperation, NotFoundError, type OwnershipCheck, type PaginationResult, type PermissionCheck, type PermissionContext, type PermissionResult, type PresetFunction, type PresetResult, PrismaAdapter, RESERVED_QUERY_PARAMS, type RateLimitConfig, type RegistryEntry, type RegistryStats, type RelationMetadata, type RepositoryLike, type RequestContext, type RequestIdOptions, type RequestWithExtras, type ResourceConfig, ResourceDefinition, type ResourceMetadata, type RouteHandler, type RouteHandlerMethod, type RouteSchemaOptions, SYSTEM_FIELDS, type SchemaMetadata, type ServiceContext, type TypedController, type TypedRepository, type TypedResourceConfig, UnauthorizedError, type UserBase, type UserOrganization, type ValidateOptions, ValidationError, type ValidationResult$1 as ValidationResult, adminOnly, allOf, allowPublic, anyOf, applyFieldReadPermissions, applyFieldWritePermissions, assertValidConfig, authenticated, createDomainError, createDynamicPermissionMatrix, createMongooseAdapter, createOrgPermissions, createPrismaAdapter, defineResource, defineResourceVariants, denyAll, envelope, fields, formatValidationErrors, fullPublic, getControllerScope, ownerWithAdminBypass, presets_d_exports as permissions, publicRead, publicReadAdminWrite, readOnly, requireAuth, requireOrgInScope, requireOrgMembership, requireOrgRole, requireOwnership, requireRoles, requireScopeContext, requireServiceScope, requireTeamMembership, validateResourceConfig, version, when };
|
package/dist/index.mjs
CHANGED
|
@@ -1,133 +1,12 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as
|
|
3
|
-
import { t as BaseController } from "./BaseController-
|
|
4
|
-
import { envelope } from "./types
|
|
5
|
-
import { n as applyFieldWritePermissions, r as fields, t as applyFieldReadPermissions } from "./fields-
|
|
6
|
-
import { d as createDomainError, i as NotFoundError, l as UnauthorizedError, r as ForbiddenError, t as ArcError, u as ValidationError } from "./errors-
|
|
7
|
-
import { t as
|
|
8
|
-
import { a as
|
|
9
|
-
import { C as publicRead, S as presets_exports, T as readOnly, _ as when, a as createOrgPermissions, b as fullPublic, c as requireOrgInScope, d as requireOwnership, f as requireRoles, h as requireTeamMembership, i as createDynamicPermissionMatrix, l as requireOrgMembership, m as requireServiceScope, n as allowPublic, o as denyAll, p as requireScopeContext, r as anyOf, s as requireAuth, t as allOf, u as requireOrgRole, v as adminOnly, w as publicReadAdminWrite, x as ownerWithAdminBypass, y as authenticated } from "./permissions-oNZawnkR.mjs";
|
|
10
|
-
import { t as defineResourceVariants } from "./core-DNncu0xF.mjs";
|
|
11
|
-
import { n as configureArcLogger, t as arcLog } from "./logger-CDjpjySd.mjs";
|
|
12
|
-
//#region src/middleware/middleware.ts
|
|
13
|
-
/**
|
|
14
|
-
* Named Middleware — Priority-based, conditional middleware execution.
|
|
15
|
-
*
|
|
16
|
-
* Named middleware replaces flat arrays with structured, inspectable middleware
|
|
17
|
-
* that runs in priority order and supports conditional execution.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { middleware } from '@classytic/arc';
|
|
22
|
-
*
|
|
23
|
-
* const verifyEmail = middleware('verifyEmail', {
|
|
24
|
-
* operations: ['create', 'update'],
|
|
25
|
-
* priority: 5,
|
|
26
|
-
* when: (req) => !req.user?.emailVerified,
|
|
27
|
-
* handler: async (req, reply) => {
|
|
28
|
-
* reply.code(403).send({ error: 'Email verification required' });
|
|
29
|
-
* },
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* const rateLimit = middleware('rateLimit', {
|
|
33
|
-
* priority: 1,
|
|
34
|
-
* handler: async (req, reply) => {
|
|
35
|
-
* // rate limit logic
|
|
36
|
-
* },
|
|
37
|
-
* });
|
|
38
|
-
*
|
|
39
|
-
* const productResource = defineResource({
|
|
40
|
-
* name: 'product',
|
|
41
|
-
* adapter,
|
|
42
|
-
* middlewares: sortMiddlewares([verifyEmail, rateLimit]),
|
|
43
|
-
* });
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
/**
|
|
47
|
-
* Create a named middleware with priority and conditions.
|
|
48
|
-
*/
|
|
49
|
-
function middleware(name, options) {
|
|
50
|
-
return {
|
|
51
|
-
name,
|
|
52
|
-
operations: options.operations,
|
|
53
|
-
priority: options.priority ?? 10,
|
|
54
|
-
when: options.when,
|
|
55
|
-
handler: options.handler
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Sort named middlewares by priority (ascending — lower runs first).
|
|
60
|
-
* Returns a MiddlewareConfig map keyed by operation, ready to pass to `defineResource()`.
|
|
61
|
-
*/
|
|
62
|
-
function sortMiddlewares(middlewares) {
|
|
63
|
-
const sorted = [...middlewares].sort((a, b) => a.priority - b.priority);
|
|
64
|
-
const operations = CRUD_OPERATIONS;
|
|
65
|
-
const result = {};
|
|
66
|
-
for (const op of operations) {
|
|
67
|
-
const applicable = sorted.filter((m) => !m.operations || m.operations.length === 0 || m.operations.includes(op));
|
|
68
|
-
if (applicable.length > 0) result[op] = applicable.map((m) => {
|
|
69
|
-
if (!m.when) return m.handler;
|
|
70
|
-
const wrapped = async (request, reply) => {
|
|
71
|
-
if (await m.when?.(request)) return m.handler(request, reply);
|
|
72
|
-
};
|
|
73
|
-
return wrapped;
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/pipeline/guard.ts
|
|
80
|
-
/**
|
|
81
|
-
* Create a named guard.
|
|
82
|
-
*
|
|
83
|
-
* @param name - Guard name (for debugging/introspection)
|
|
84
|
-
* @param handlerOrOptions - Handler function or options object
|
|
85
|
-
*/
|
|
86
|
-
function guard(name, handlerOrOptions) {
|
|
87
|
-
const opts = typeof handlerOrOptions === "function" ? { handler: handlerOrOptions } : handlerOrOptions;
|
|
88
|
-
return {
|
|
89
|
-
_type: "guard",
|
|
90
|
-
name,
|
|
91
|
-
operations: opts.operations,
|
|
92
|
-
handler: opts.handler
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
//#endregion
|
|
96
|
-
//#region src/pipeline/intercept.ts
|
|
97
|
-
/**
|
|
98
|
-
* Create a named interceptor.
|
|
99
|
-
*
|
|
100
|
-
* @param name - Interceptor name (for debugging/introspection)
|
|
101
|
-
* @param handlerOrOptions - Handler function or options object
|
|
102
|
-
*/
|
|
103
|
-
function intercept(name, handlerOrOptions) {
|
|
104
|
-
const opts = typeof handlerOrOptions === "function" ? { handler: handlerOrOptions } : handlerOrOptions;
|
|
105
|
-
return {
|
|
106
|
-
_type: "interceptor",
|
|
107
|
-
name,
|
|
108
|
-
operations: opts.operations,
|
|
109
|
-
handler: opts.handler
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region src/pipeline/transform.ts
|
|
114
|
-
/**
|
|
115
|
-
* Create a named transform.
|
|
116
|
-
*
|
|
117
|
-
* @param name - Transform name (for debugging/introspection)
|
|
118
|
-
* @param handlerOrOptions - Handler function or options object
|
|
119
|
-
*/
|
|
120
|
-
function transform(name, handlerOrOptions) {
|
|
121
|
-
const opts = typeof handlerOrOptions === "function" ? { handler: handlerOrOptions } : handlerOrOptions;
|
|
122
|
-
return {
|
|
123
|
-
_type: "transform",
|
|
124
|
-
name,
|
|
125
|
-
operations: opts.operations,
|
|
126
|
-
handler: opts.handler
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
//#endregion
|
|
1
|
+
import { a as createMongooseAdapter, i as MongooseAdapter, r as createPrismaAdapter, t as PrismaAdapter } from "./adapters-BXY4i-hw.mjs";
|
|
2
|
+
import { a as DEFAULT_SORT, c as HOOK_OPERATIONS, d as MAX_REGEX_LENGTH, f as MAX_SEARCH_LENGTH, h as SYSTEM_FIELDS, i as DEFAULT_MAX_LIMIT, l as HOOK_PHASES, m as RESERVED_QUERY_PARAMS, n as DEFAULT_ID_FIELD, o as DEFAULT_TENANT_FIELD, p as MUTATION_OPERATIONS, r as DEFAULT_LIMIT, s as DEFAULT_UPDATE_METHOD, t as CRUD_OPERATIONS, u as MAX_FILTER_DEPTH } from "./constants-BhY1OHoH.mjs";
|
|
3
|
+
import { t as BaseController } from "./BaseController-DVNKvoX4.mjs";
|
|
4
|
+
import { t as envelope } from "./types-CDnTEpga.mjs";
|
|
5
|
+
import { n as applyFieldWritePermissions, r as fields, t as applyFieldReadPermissions } from "./fields-CTMWOUDt.mjs";
|
|
6
|
+
import { d as createDomainError, i as NotFoundError, l as UnauthorizedError, r as ForbiddenError, t as ArcError, u as ValidationError } from "./errors-BqdUDja_.mjs";
|
|
7
|
+
import { a as formatValidationErrors, i as assertValidConfig, n as ResourceDefinition, o as validateResourceConfig, p as getControllerScope, r as defineResource, t as defineResourceVariants } from "./core-3MWJosCH.mjs";
|
|
8
|
+
import { C as requireAuth, D as when, T as requireRoles, _ as requireTeamMembership, a as presets_exports, b as anyOf, c as readOnly, d as createOrgPermissions, f as requireOrgInScope, g as requireServiceScope, h as requireScopeContext, i as ownerWithAdminBypass, m as requireOrgRole, n as authenticated, o as publicRead, p as requireOrgMembership, r as fullPublic, s as publicReadAdminWrite, t as adminOnly, u as createDynamicPermissionMatrix, v as allOf, w as requireOwnership, x as denyAll, y as allowPublic } from "./permissions-wkqRwicB.mjs";
|
|
130
9
|
//#region src/index.ts
|
|
131
|
-
const version = "2.
|
|
10
|
+
const version = "2.10.8";
|
|
132
11
|
//#endregion
|
|
133
|
-
export { ArcError, BaseController, CRUD_OPERATIONS, DEFAULT_ID_FIELD, DEFAULT_LIMIT, DEFAULT_MAX_LIMIT, DEFAULT_SORT, DEFAULT_TENANT_FIELD, DEFAULT_UPDATE_METHOD, ForbiddenError, HOOK_OPERATIONS, HOOK_PHASES, MAX_FILTER_DEPTH, MAX_REGEX_LENGTH, MAX_SEARCH_LENGTH, MUTATION_OPERATIONS, MongooseAdapter, NotFoundError, PrismaAdapter, RESERVED_QUERY_PARAMS, ResourceDefinition, SYSTEM_FIELDS, UnauthorizedError, ValidationError, adminOnly, allOf, allowPublic, anyOf, applyFieldReadPermissions, applyFieldWritePermissions,
|
|
12
|
+
export { ArcError, BaseController, CRUD_OPERATIONS, DEFAULT_ID_FIELD, DEFAULT_LIMIT, DEFAULT_MAX_LIMIT, DEFAULT_SORT, DEFAULT_TENANT_FIELD, DEFAULT_UPDATE_METHOD, ForbiddenError, HOOK_OPERATIONS, HOOK_PHASES, MAX_FILTER_DEPTH, MAX_REGEX_LENGTH, MAX_SEARCH_LENGTH, MUTATION_OPERATIONS, MongooseAdapter, NotFoundError, PrismaAdapter, RESERVED_QUERY_PARAMS, ResourceDefinition, SYSTEM_FIELDS, UnauthorizedError, ValidationError, adminOnly, allOf, allowPublic, anyOf, applyFieldReadPermissions, applyFieldWritePermissions, assertValidConfig, authenticated, createDomainError, createDynamicPermissionMatrix, createMongooseAdapter, createOrgPermissions, createPrismaAdapter, defineResource, defineResourceVariants, denyAll, envelope, fields, formatValidationErrors, fullPublic, getControllerScope, ownerWithAdminBypass, presets_exports as permissions, publicRead, publicReadAdminWrite, readOnly, requireAuth, requireOrgInScope, requireOrgMembership, requireOrgRole, requireOwnership, requireRoles, requireScopeContext, requireServiceScope, requireTeamMembership, validateResourceConfig, version, when };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as DomainEvent } from "../EventTransport-
|
|
1
|
+
import { n as DomainEvent } from "../EventTransport-CfVEGaEl.mjs";
|
|
2
2
|
import { WebSocketClient, WebSocketMessage } from "./websocket.mjs";
|
|
3
3
|
import { FastifyPluginAsync, FastifyRequest } from "fastify";
|
|
4
4
|
|
|
@@ -4,7 +4,7 @@ const eventGatewayPluginImpl = async (fastify, opts = {}) => {
|
|
|
4
4
|
const { auth = true, orgScoped = false, roomPolicy, maxMessageBytes, maxSubscriptionsPerClient, authenticate } = opts;
|
|
5
5
|
if (auth && !authenticate && !fastify.hasDecorator("authenticate")) throw new Error("[arc-event-gateway] auth is true but fastify.authenticate is not registered. Register an auth plugin first, provide a custom authenticate function, or set auth: false.");
|
|
6
6
|
if (opts.sse !== false) {
|
|
7
|
-
const { default: ssePlugin } = await import("../sse-
|
|
7
|
+
const { default: ssePlugin } = await import("../sse-D8UeDwis.mjs").then((n) => n.r);
|
|
8
8
|
await fastify.register(ssePlugin, {
|
|
9
9
|
path: opts.sse?.path ?? "/events/stream",
|
|
10
10
|
requireAuth: auth,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WebSocketClient, WebSocketMessage, WebSocketPluginOptions } from "./websocket.mjs";
|
|
2
2
|
import { EventGatewayOptions } from "./event-gateway.mjs";
|
|
3
3
|
import { JobDefinition, JobDispatchOptions, JobDispatcher, JobMeta, JobsPluginOptions, QueueStats } from "./jobs.mjs";
|
|
4
|
-
import { c as McpResourceConfig, f as ToolAnnotations, i as CrudOperation, l as PromptDefinition, m as ToolDefinition, n as CallToolResult, o as McpAuthResult, p as ToolContext, r as CreateMcpServerConfig, s as McpPluginOptions, t as BetterAuthHandler } from "../types-
|
|
4
|
+
import { c as McpResourceConfig, f as ToolAnnotations, i as CrudOperation, l as PromptDefinition, m as ToolDefinition, n as CallToolResult, o as McpAuthResult, p as ToolContext, r as CreateMcpServerConfig, s as McpPluginOptions, t as BetterAuthHandler } from "../types-CVKBssX5.mjs";
|
|
5
5
|
import { StreamlinePluginOptions, WorkflowLike, WorkflowRunLike } from "./streamline.mjs";
|
|
6
6
|
import { WebhookDeliveryRecord, WebhookManager, WebhookPluginOptions, WebhookStore, WebhookSubscription } from "./webhooks.mjs";
|
|
7
7
|
export { type BetterAuthHandler, type CallToolResult, type CreateMcpServerConfig, type CrudOperation, type EventGatewayOptions, type JobDefinition, type JobDispatchOptions, type JobDispatcher, type JobMeta, type JobsPluginOptions, type McpAuthResult, type McpPluginOptions, type McpResourceConfig, type PromptDefinition, type QueueStats, type StreamlinePluginOptions, type ToolAnnotations, type ToolContext, type ToolDefinition, type WebSocketClient, type WebSocketMessage, type WebSocketPluginOptions, type WebhookDeliveryRecord, type WebhookManager, type WebhookPluginOptions, type WebhookStore, type WebhookSubscription, type WorkflowLike, type WorkflowRunLike };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as McpAuthResolver, c as McpResourceConfig, d as SessionEntry, f as ToolAnnotations, i as CrudOperation, l as PromptDefinition, m as ToolDefinition, n as CallToolResult, o as McpAuthResult, p as ToolContext, r as CreateMcpServerConfig, s as McpPluginOptions, t as BetterAuthHandler, u as PromptResult } from "../../types-
|
|
1
|
+
import { B as ResourceDefinition } from "../../index-BGbpGVyM.mjs";
|
|
2
|
+
import { a as McpAuthResolver, c as McpResourceConfig, d as SessionEntry, f as ToolAnnotations, i as CrudOperation, l as PromptDefinition, m as ToolDefinition, n as CallToolResult, o as McpAuthResult, p as ToolContext, r as CreateMcpServerConfig, s as McpPluginOptions, t as BetterAuthHandler, u as PromptResult } from "../../types-CVKBssX5.mjs";
|
|
3
3
|
import { FastifyPluginAsync } from "fastify";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as fieldRulesToZod, r as createMcpServer, t as resourceToTools } from "../../resourceToTools-
|
|
1
|
+
import { n as fieldRulesToZod, r as createMcpServer, t as resourceToTools } from "../../resourceToTools-BhF3JV5p.mjs";
|
|
2
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
3
|
import fp from "fastify-plugin";
|
|
4
4
|
//#region src/integrations/mcp/defineTool.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as createMcpServer, t as resourceToTools } from "../../resourceToTools-
|
|
1
|
+
import { r as createMcpServer, t as resourceToTools } from "../../resourceToTools-BhF3JV5p.mjs";
|
|
2
2
|
//#region src/integrations/mcp/testing.ts
|
|
3
3
|
/**
|
|
4
4
|
* @classytic/arc/mcp/testing — MCP Test Utilities
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region src/cache/interface.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Cache Store Interface — aligned with `@classytic/repo-core/cache.CacheAdapter`.
|
|
4
|
+
*
|
|
5
|
+
* Arc's cache layer speaks the same `get / set(ttlSeconds?) / del / clear(pattern?)`
|
|
6
|
+
* transport-level contract published by `@classytic/repo-core`. One Redis
|
|
7
|
+
* implementation drops into Arc's `QueryCache`, mongokit's cache plugin,
|
|
8
|
+
* sqlitekit's cache plugin, and every future kit without wrapper shims.
|
|
9
|
+
*
|
|
10
|
+
* Arc extends the bare adapter with two optional observability fields —
|
|
11
|
+
* `name` (for diagnostics) and `stats()` (for the response-cache plugin) —
|
|
12
|
+
* that are opt-in: consumers implementing only `CacheAdapter` still
|
|
13
|
+
* structurally satisfy `CacheStore`, so a raw repo-core adapter plugs
|
|
14
|
+
* directly into Arc.
|
|
15
|
+
*
|
|
16
|
+
* ## TTL unit
|
|
17
|
+
*
|
|
18
|
+
* `ttlSeconds`, not milliseconds. Matches Redis (`SET … EX seconds`) which
|
|
19
|
+
* is the dominant backend. `0` or `undefined` means no expiry; implementations
|
|
20
|
+
* may apply their own default.
|
|
21
|
+
*
|
|
22
|
+
* ## Not-found semantics
|
|
23
|
+
*
|
|
24
|
+
* `get()` returns `undefined` on miss / expired. Matches repo-core.
|
|
25
|
+
*
|
|
26
|
+
* ## Sync-or-async
|
|
27
|
+
*
|
|
28
|
+
* Method returns are `Promise<T> | T` — in-memory `Map` adapters can be
|
|
29
|
+
* synchronous; Redis adapters are async. Consumers always `await`, so
|
|
30
|
+
* sync values just short-circuit the microtask.
|
|
31
|
+
*/
|
|
32
|
+
interface CacheLogger {
|
|
33
|
+
warn(message: string, ...args: unknown[]): void;
|
|
34
|
+
error(message: string, ...args: unknown[]): void;
|
|
35
|
+
}
|
|
36
|
+
interface CacheStats {
|
|
37
|
+
/** Number of entries currently stored */
|
|
38
|
+
entries: number;
|
|
39
|
+
/** Estimated memory usage in bytes (-1 if unavailable) */
|
|
40
|
+
memoryBytes: number;
|
|
41
|
+
/** Cache hit count since creation */
|
|
42
|
+
hits: number;
|
|
43
|
+
/** Cache miss count since creation */
|
|
44
|
+
misses: number;
|
|
45
|
+
/** Number of entries evicted since creation */
|
|
46
|
+
evictions: number;
|
|
47
|
+
}
|
|
48
|
+
interface CacheStore<TValue = unknown> {
|
|
49
|
+
/** Store name for logs/diagnostics. Optional to match repo-core's bare `CacheAdapter`. */
|
|
50
|
+
readonly name?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Get a value by key. Returns `undefined` when not found or expired.
|
|
53
|
+
*/
|
|
54
|
+
get(key: string): Promise<TValue | undefined> | TValue | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Store a value with optional TTL (seconds). `0` or `undefined` means
|
|
57
|
+
* no expiry; implementations may apply a default.
|
|
58
|
+
*/
|
|
59
|
+
set(key: string, value: TValue, ttlSeconds?: number): Promise<void> | void;
|
|
60
|
+
/**
|
|
61
|
+
* Delete a single key. No-op when the key doesn't exist.
|
|
62
|
+
*/
|
|
63
|
+
delete(key: string): Promise<void> | void;
|
|
64
|
+
/**
|
|
65
|
+
* Invalidate keys matching a glob pattern (typically `prefix:*`), or
|
|
66
|
+
* every key when `pattern` is omitted.
|
|
67
|
+
*
|
|
68
|
+
* Optional — simpler adapters that can't enumerate keys (some KV stores)
|
|
69
|
+
* may omit this and rely on TTL for eventual consistency. Consumers that
|
|
70
|
+
* need strict invalidation must check for its presence: `store.clear?.(pattern)`.
|
|
71
|
+
*/
|
|
72
|
+
clear?(pattern?: string): Promise<void> | void;
|
|
73
|
+
/** Cache statistics for observability. Optional. */
|
|
74
|
+
stats?(): CacheStats;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { CacheStats as n, CacheStore as r, CacheLogger as t };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
//#region src/logger/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Arc Logger — Centralized debug & warning system
|
|
4
|
+
*
|
|
5
|
+
* Lightweight, zero-dependency logger for Arc framework internals.
|
|
6
|
+
* Inspired by the `debug` npm package — disabled by default, opt-in via
|
|
7
|
+
* environment variable or `createApp({ debug })` option.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Enable via env var
|
|
12
|
+
* ARC_DEBUG=1 node server.js // all modules
|
|
13
|
+
* ARC_DEBUG=scope,elevation node server.js // specific modules
|
|
14
|
+
*
|
|
15
|
+
* // Enable via createApp
|
|
16
|
+
* const app = await createApp({ debug: true });
|
|
17
|
+
* const app = await createApp({ debug: 'scope,elevation' });
|
|
18
|
+
*
|
|
19
|
+
* // Suppress warnings (not recommended)
|
|
20
|
+
* ARC_SUPPRESS_WARNINGS=1 node server.js
|
|
21
|
+
*
|
|
22
|
+
* // Framework internals use:
|
|
23
|
+
* import { arcLog } from '../logger/index.js';
|
|
24
|
+
* const log = arcLog('elevation');
|
|
25
|
+
* log.debug('Elevation applied', { userId });
|
|
26
|
+
* log.warn('Something unexpected');
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
interface ArcLoggerOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Enable debug output.
|
|
32
|
+
* - `true` or `'*'` — all modules
|
|
33
|
+
* - `string` — comma-separated module names (e.g., `'scope,elevation'`)
|
|
34
|
+
* - `false` — disabled (default)
|
|
35
|
+
*/
|
|
36
|
+
debug?: boolean | string;
|
|
37
|
+
/**
|
|
38
|
+
* Custom log writer. Defaults to `console`.
|
|
39
|
+
* Useful for routing Arc logs into Fastify's pino logger or test fixtures.
|
|
40
|
+
*/
|
|
41
|
+
writer?: ArcLogWriter;
|
|
42
|
+
}
|
|
43
|
+
interface ArcLogWriter {
|
|
44
|
+
debug: (...args: unknown[]) => void;
|
|
45
|
+
info: (...args: unknown[]) => void;
|
|
46
|
+
warn: (...args: unknown[]) => void;
|
|
47
|
+
error: (...args: unknown[]) => void;
|
|
48
|
+
}
|
|
49
|
+
interface ArcLogger {
|
|
50
|
+
debug: (...args: unknown[]) => void;
|
|
51
|
+
info: (...args: unknown[]) => void;
|
|
52
|
+
warn: (...args: unknown[]) => void;
|
|
53
|
+
error: (...args: unknown[]) => void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Configure the Arc logger globally.
|
|
57
|
+
*
|
|
58
|
+
* Called automatically by `createApp({ debug })`, but can also be
|
|
59
|
+
* called manually for standalone usage outside of `createApp`.
|
|
60
|
+
*/
|
|
61
|
+
declare function configureArcLogger(options: ArcLoggerOptions): void;
|
|
62
|
+
/**
|
|
63
|
+
* Create a module-scoped logger.
|
|
64
|
+
*
|
|
65
|
+
* Debug and info messages are gated by the `ARC_DEBUG` env var or
|
|
66
|
+
* `createApp({ debug })` option. Warnings always show (unless
|
|
67
|
+
* `ARC_SUPPRESS_WARNINGS=1`). Errors always show.
|
|
68
|
+
*
|
|
69
|
+
* @param module - Module name (e.g., 'scope', 'elevation', 'sse', 'preset')
|
|
70
|
+
* @returns Logger instance for that module
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const log = arcLog('elevation');
|
|
75
|
+
* log.debug('Checking elevation header');
|
|
76
|
+
* log.warn('No authenticate decorator found');
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function arcLog(module: string): ArcLogger;
|
|
80
|
+
//#endregion
|
|
81
|
+
export { ArcLogWriter, ArcLogger, ArcLoggerOptions, arcLog, configureArcLogger };
|