@classytic/arc 2.8.3 → 2.8.5

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.
Files changed (125) hide show
  1. package/README.md +50 -1
  2. package/dist/adapters/index.d.mts +2 -2
  3. package/dist/audit/index.d.mts +1 -1
  4. package/dist/audit/index.mjs +1 -1
  5. package/dist/audit/mongodb.d.mts +1 -1
  6. package/dist/audit/mongodb.mjs +1 -1
  7. package/dist/auth/index.d.mts +4 -4
  8. package/dist/auth/index.mjs +2 -2
  9. package/dist/auth/redis-session.d.mts +1 -1
  10. package/dist/{betterAuthOpenApi-C5lDyRH2.mjs → betterAuthOpenApi-BuUcUEJq.mjs} +1 -1
  11. package/dist/cache/index.d.mts +73 -3
  12. package/dist/cache/index.mjs +95 -2
  13. package/dist/cli/commands/docs.mjs +2 -2
  14. package/dist/cli/commands/generate.mjs +1 -1
  15. package/dist/cli/commands/introspect.mjs +1 -1
  16. package/dist/core/index.d.mts +2 -2
  17. package/dist/core/index.mjs +3 -3
  18. package/dist/{core-DKSwNSXf.mjs → core-F0QoWBt2.mjs} +1 -1
  19. package/dist/{createActionRouter-Df1BuawX.mjs → createActionRouter-BORM8f17.mjs} +1 -1
  20. package/dist/{createApp-BOYjBgdI.mjs → createApp-B1EY8zxa.mjs} +11 -11
  21. package/dist/{defineResource-Bb_Bdhtw.mjs → defineResource-tcgySDo1.mjs} +2 -2
  22. package/dist/docs/index.d.mts +2 -2
  23. package/dist/docs/index.mjs +1 -1
  24. package/dist/dynamic/index.d.mts +2 -2
  25. package/dist/dynamic/index.mjs +1 -1
  26. package/dist/{elevation-BBGFjzIP.mjs → elevation-DtFxrG0s.mjs} +1 -1
  27. package/dist/{errorHandler-CdZDavNH.d.mts → errorHandler-Bah5JhBd.d.mts} +1 -1
  28. package/dist/{eventPlugin-CVxlE6De.d.mts → eventPlugin-D9DKB2zM.d.mts} +1 -1
  29. package/dist/events/index.d.mts +3 -3
  30. package/dist/events/index.mjs +1 -1
  31. package/dist/events/transports/redis-stream-entry.d.mts +1 -1
  32. package/dist/events/transports/redis.d.mts +1 -1
  33. package/dist/factory/index.d.mts +1 -1
  34. package/dist/factory/index.mjs +2 -2
  35. package/dist/filesUpload-C7r7HIeA.mjs +319 -0
  36. package/dist/hooks/index.d.mts +1 -1
  37. package/dist/hooks/index.mjs +1 -1
  38. package/dist/idempotency/index.d.mts +3 -3
  39. package/dist/idempotency/mongodb.d.mts +1 -1
  40. package/dist/idempotency/redis.d.mts +2 -2
  41. package/dist/idempotency/redis.mjs +134 -13
  42. package/dist/{index-CSkeivBx.d.mts → index-BLXBmWud.d.mts} +3 -3
  43. package/dist/{index-BgmMdpm8.d.mts → index-C1meYuDn.d.mts} +1 -1
  44. package/dist/{index-CpTSDqmD.d.mts → index-DtDzOBn8.d.mts} +3 -3
  45. package/dist/index.d.mts +7 -7
  46. package/dist/index.mjs +4 -4
  47. package/dist/integrations/event-gateway.d.mts +1 -1
  48. package/dist/integrations/event-gateway.mjs +1 -1
  49. package/dist/integrations/index.d.mts +1 -1
  50. package/dist/integrations/jobs.d.mts +25 -3
  51. package/dist/integrations/jobs.mjs +63 -4
  52. package/dist/integrations/mcp/index.d.mts +51 -3
  53. package/dist/integrations/mcp/index.mjs +78 -19
  54. package/dist/integrations/mcp/testing.d.mts +1 -1
  55. package/dist/integrations/mcp/testing.mjs +1 -1
  56. package/dist/{interface-BVuMfeVv.d.mts → interface-CMRutPfe.d.mts} +38 -16
  57. package/dist/{mongodb-B8U2xaLj.d.mts → mongodb-BsP-WbhN.d.mts} +1 -1
  58. package/dist/{mongodb-X7LbEjTN.d.mts → mongodb-CTcp0hQZ.d.mts} +1 -1
  59. package/dist/{openapi-CYCuekCn.mjs → openapi-CbKUJY_m.mjs} +3 -3
  60. package/dist/org/index.d.mts +2 -2
  61. package/dist/permissions/index.d.mts +3 -3
  62. package/dist/plugins/index.d.mts +4 -4
  63. package/dist/plugins/index.mjs +8 -8
  64. package/dist/plugins/tracing-entry.d.mts +1 -1
  65. package/dist/plugins/tracing-entry.mjs +1 -1
  66. package/dist/policies/index.d.mts +1 -1
  67. package/dist/presets/filesUpload.d.mts +49 -0
  68. package/dist/presets/filesUpload.mjs +2 -0
  69. package/dist/presets/index.d.mts +3 -2
  70. package/dist/presets/index.mjs +2 -1
  71. package/dist/presets/multiTenant.d.mts +1 -1
  72. package/dist/{queryCachePlugin-CnTZZTC5.d.mts → queryCachePlugin-BJJGBTlu.d.mts} +1 -1
  73. package/dist/redis-BM00zaPB.d.mts +115 -0
  74. package/dist/{redis-stream-D54N5oXs.d.mts → redis-stream-CrsfUmPt.d.mts} +1 -1
  75. package/dist/registry/index.d.mts +1 -1
  76. package/dist/registry/index.mjs +2 -2
  77. package/dist/{resourceToTools-O_HwWXFa.mjs → resourceToTools-8s-EsCCe.mjs} +1 -1
  78. package/dist/rpc/index.d.mts +1 -1
  79. package/dist/{schemaConverter-OxfCshus.mjs → schemaConverter-Y7nCYaLJ.mjs} +24 -8
  80. package/dist/scope/index.d.mts +2 -2
  81. package/dist/scope/index.mjs +1 -1
  82. package/dist/{sse-CJpt7LGI.mjs → sse-Ad7ypl9e.mjs} +1 -1
  83. package/dist/storage-Dfzt4VTl.d.mts +146 -0
  84. package/dist/testing/index.d.mts +4 -3
  85. package/dist/testing/index.mjs +3 -2
  86. package/dist/testing/storageContract.d.mts +26 -0
  87. package/dist/testing/storageContract.mjs +216 -0
  88. package/dist/types/index.d.mts +4 -4
  89. package/dist/types/storage.d.mts +2 -0
  90. package/dist/types/storage.mjs +1 -0
  91. package/dist/{types-CcG4avic.d.mts → types-BsbNMEDR.d.mts} +1 -1
  92. package/dist/{types-Bg2X42_m.d.mts → types-Ch9pTQbf.d.mts} +9 -9
  93. package/dist/{types-CVC4HOKi.d.mts → types-DZi1aYhm.d.mts} +1 -1
  94. package/dist/utils/index.d.mts +26 -8
  95. package/dist/utils/index.mjs +1 -1
  96. package/package.json +16 -1
  97. package/skills/arc/SKILL.md +22 -0
  98. package/skills/arc/references/events.md +29 -0
  99. package/skills/arc/references/mcp.md +37 -0
  100. package/dist/redis-z3sFr1UP.d.mts +0 -49
  101. /package/dist/{EventTransport-CinyO7zQ.d.mts → EventTransport-BXja8NOc.d.mts} +0 -0
  102. /package/dist/{HookSystem-BjFu7zf1.mjs → HookSystem-HprTmvVY.mjs} +0 -0
  103. /package/dist/{ResourceRegistry-Dq3_zBQP.mjs → ResourceRegistry-C6uXlWe3.mjs} +0 -0
  104. /package/dist/{caching-CjybdRwx.mjs → caching-IMuYVjTL.mjs} +0 -0
  105. /package/dist/{circuitBreaker-CvXkjfrW.d.mts → circuitBreaker-dTtG-UyS.d.mts} +0 -0
  106. /package/dist/{elevation-s5ykdNHr.d.mts → elevation-B6S5csVA.d.mts} +0 -0
  107. /package/dist/{errorHandler-mzqk4cGl.mjs → errorHandler-f869_8PQ.mjs} +0 -0
  108. /package/dist/{errors-Bmn3eZT6.d.mts → errors-Ck2h67pm.d.mts} +0 -0
  109. /package/dist/{eventPlugin-D91S2YF4.mjs → eventPlugin-CDjVTM82.mjs} +0 -0
  110. /package/dist/{externalPaths-Bapitwvd.d.mts → externalPaths-BnkYrNzp.d.mts} +0 -0
  111. /package/dist/{fields-DC4So2M2.d.mts → fields-DpZQa_Q3.d.mts} +0 -0
  112. /package/dist/{interface-DplgQO2e.d.mts → interface-4y979v99.d.mts} +0 -0
  113. /package/dist/{interface-B-pe8fhj.d.mts → interface-DfLGcus7.d.mts} +0 -0
  114. /package/dist/{loadResources-Bksk8ydA.mjs → loadResources-PWd0OCpV.mjs} +0 -0
  115. /package/dist/{logger-CDjpjySd.mjs → logger-D1YrIImS.mjs} +0 -0
  116. /package/dist/{metrics-TuOmguhi.mjs → metrics-B-PU4-Yu.mjs} +0 -0
  117. /package/dist/{mongodb-B5O6xaW1.mjs → mongodb-Utc5k_-0.mjs} +0 -0
  118. /package/dist/{pluralize-A0tWEl1K.mjs → pluralize-CWP6MB39.mjs} +0 -0
  119. /package/dist/{queryCachePlugin-D0iIVhW_.mjs → queryCachePlugin-BH-fidlv.mjs} +0 -0
  120. /package/dist/{registry-B0Wl7uVV.mjs → registry-BiTKT1Dg.mjs} +0 -0
  121. /package/dist/{replyHelpers-BLojtuvR.mjs → replyHelpers-CxkYGT81.mjs} +0 -0
  122. /package/dist/{sessionManager-D-oNWHz3.d.mts → sessionManager-DDCmiNIo.d.mts} +0 -0
  123. /package/dist/{tracing-DxjKk7eW.d.mts → tracing-DdN2-wHJ.d.mts} +0 -0
  124. /package/dist/{types-C72d3NDn.d.mts → types-BD85MlEK.d.mts} +0 -0
  125. /package/dist/{versioning-Cm8qoFDg.mjs → versioning-CDugduqI.mjs} +0 -0
@@ -1,4 +1,5 @@
1
- import { Ht as IControllerResponse, Ut as IRequestContext, m as AnyRecord, on as PaginationResult, tt as PresetResult, ut as ResourceConfig } from "../interface-BVuMfeVv.mjs";
1
+ import { Ht as IControllerResponse, Ut as IRequestContext, m as AnyRecord, on as PaginationResult, tt as PresetResult, ut as ResourceConfig } from "../interface-CMRutPfe.mjs";
2
+ import { FilesUploadPresetOptions, FilesUploadPresetPermissions, FilesUploadPresetRoutes, filesUploadPreset } from "./filesUpload.mjs";
2
3
  import { MultiTenantOptions, TenantFieldSpec, multiTenantPreset } from "./multiTenant.mjs";
3
4
 
4
5
  //#region src/presets/ownedByUser.d.ts
@@ -271,4 +272,4 @@ type PresetInput = string | PresetResult | {
271
272
  */
272
273
  declare function applyPresets<TDoc = AnyRecord>(config: ResourceConfig<TDoc>, presets?: PresetInput[]): ResourceConfig<TDoc>;
273
274
  //#endregion
274
- export { type AuditedPresetOptions, type BulkOperation, type BulkPresetOptions, type IAuditedPreset, type IMultiTenantPreset, type IOwnedByUserPreset, type IPresetController, type ISlugLookupController, type ISoftDeleteController, type ITreeController, type MultiTenantOptions, type OwnedByUserOptions, type SlugLookupOptions, type TenantFieldSpec, type TreeOptions, applyPresets, auditedPreset, bulkPreset, flexibleMultiTenantPreset, getAvailablePresets, getPreset, multiTenantPreset, ownedByUserPreset, registerPreset, slugLookupPreset, softDeletePreset, treePreset };
275
+ export { type AuditedPresetOptions, type BulkOperation, type BulkPresetOptions, type FilesUploadPresetOptions, type FilesUploadPresetPermissions, type FilesUploadPresetRoutes, type IAuditedPreset, type IMultiTenantPreset, type IOwnedByUserPreset, type IPresetController, type ISlugLookupController, type ISoftDeleteController, type ITreeController, type MultiTenantOptions, type OwnedByUserOptions, type SlugLookupOptions, type TenantFieldSpec, type TreeOptions, applyPresets, auditedPreset, bulkPreset, filesUploadPreset, flexibleMultiTenantPreset, getAvailablePresets, getPreset, multiTenantPreset, ownedByUserPreset, registerPreset, slugLookupPreset, softDeletePreset, treePreset };
@@ -1,3 +1,4 @@
1
1
  import { multiTenantPreset } from "./multiTenant.mjs";
2
2
  import { a as registerPreset, c as auditedPreset, d as ownedByUserPreset, i as getPreset, l as softDeletePreset, n as flexibleMultiTenantPreset, o as treePreset, r as getAvailablePresets, s as bulkPreset, t as applyPresets, u as slugLookupPreset } from "../presets-C2xgzW6x.mjs";
3
- export { applyPresets, auditedPreset, bulkPreset, flexibleMultiTenantPreset, getAvailablePresets, getPreset, multiTenantPreset, ownedByUserPreset, registerPreset, slugLookupPreset, softDeletePreset, treePreset };
3
+ import { t as filesUploadPreset } from "../filesUpload-C7r7HIeA.mjs";
4
+ export { applyPresets, auditedPreset, bulkPreset, filesUploadPreset, flexibleMultiTenantPreset, getAvailablePresets, getPreset, multiTenantPreset, ownedByUserPreset, registerPreset, slugLookupPreset, softDeletePreset, treePreset };
@@ -1,4 +1,4 @@
1
- import { E as CrudRouteKey, tt as PresetResult } from "../interface-BVuMfeVv.mjs";
1
+ import { E as CrudRouteKey, tt as PresetResult } from "../interface-CMRutPfe.mjs";
2
2
 
3
3
  //#region src/presets/multiTenant.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { i as CacheStore } from "./interface-DplgQO2e.mjs";
1
+ import { i as CacheStore } from "./interface-4y979v99.mjs";
2
2
  import { FastifyPluginAsync } from "fastify";
3
3
 
4
4
  //#region src/cache/QueryCache.d.ts
@@ -0,0 +1,115 @@
1
+ import { n as IdempotencyResult, r as IdempotencyStore } from "./interface-DfLGcus7.mjs";
2
+
3
+ //#region src/idempotency/stores/redis.d.ts
4
+ interface RedisClient {
5
+ get(key: string): Promise<string | null>;
6
+ set(key: string, value: string, options?: {
7
+ EX?: number;
8
+ NX?: boolean;
9
+ }): Promise<string | null>;
10
+ del(key: string | string[]): Promise<number>;
11
+ exists(key: string | string[]): Promise<number>;
12
+ /** SCAN command — compatible with node-redis and ioredis varargs signatures. */
13
+ scan?(cursor: string | number, ...args: (string | number)[]): Promise<[string | number, string[]]>;
14
+ quit?(): Promise<string>;
15
+ disconnect?(): Promise<void>;
16
+ }
17
+ interface RedisIdempotencyStoreOptions {
18
+ /** Redis client instance */
19
+ client: RedisClient;
20
+ /** Key prefix (default: 'idem:') */
21
+ prefix?: string;
22
+ /** Lock key prefix (default: 'idem:lock:') */
23
+ lockPrefix?: string;
24
+ /** Default TTL in ms (default: 86400000 = 24 hours) */
25
+ ttlMs?: number;
26
+ }
27
+ declare class RedisIdempotencyStore implements IdempotencyStore {
28
+ readonly name = "redis";
29
+ private client;
30
+ private prefix;
31
+ private lockPrefix;
32
+ private ttlMs;
33
+ constructor(options: RedisIdempotencyStoreOptions);
34
+ private resultKey;
35
+ private lockKey;
36
+ get(key: string): Promise<IdempotencyResult | undefined>;
37
+ set(key: string, result: Omit<IdempotencyResult, "key">): Promise<void>;
38
+ tryLock(key: string, requestId: string, ttlMs: number): Promise<boolean>;
39
+ unlock(key: string, requestId: string): Promise<void>;
40
+ isLocked(key: string): Promise<boolean>;
41
+ delete(key: string): Promise<void>;
42
+ deleteByPrefix(prefix: string): Promise<number>;
43
+ findByPrefix(prefix: string): Promise<IdempotencyResult | undefined>;
44
+ /** Scan Redis keys matching a prefix pattern. Falls back to empty if SCAN unavailable. */
45
+ private scanByPrefix;
46
+ close(): Promise<void>;
47
+ }
48
+ /** Minimal ioredis shape we depend on — keeps this file peer-dep-free. */
49
+ interface IoredisLike {
50
+ get(key: string): Promise<string | null>;
51
+ set(...args: unknown[]): Promise<string | null>;
52
+ del(...keys: string[]): Promise<number>;
53
+ exists(...keys: string[]): Promise<number>;
54
+ scan(cursor: string | number, ...args: (string | number)[]): Promise<[string, string[]]>;
55
+ eval?(script: string, numKeys: number, ...args: (string | number)[]): Promise<unknown>;
56
+ quit?(): Promise<string>;
57
+ disconnect?(): void;
58
+ }
59
+ /**
60
+ * Wrap an ioredis instance as the arc idempotency `RedisClient`.
61
+ *
62
+ * Arc's idempotency store expects node-redis-v4 style option objects
63
+ * (`{ EX, NX }`). ioredis uses positional flags. This adapter lets users
64
+ * plug an ioredis instance in without writing the bridge themselves.
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * import Redis from 'ioredis';
69
+ * import { RedisIdempotencyStore, ioredisAsIdempotencyClient }
70
+ * from '@classytic/arc/idempotency/redis';
71
+ *
72
+ * const redis = new Redis(process.env.REDIS_URL);
73
+ * const store = new RedisIdempotencyStore({
74
+ * client: ioredisAsIdempotencyClient(redis),
75
+ * });
76
+ * ```
77
+ */
78
+ declare function ioredisAsIdempotencyClient(client: IoredisLike): RedisClient & {
79
+ eval?: (script: string, numkeys: number, ...args: (string | number)[]) => Promise<unknown>;
80
+ };
81
+ /** Minimal `@upstash/redis` shape we depend on (REST client, edge-safe). */
82
+ interface UpstashRedisLike {
83
+ get(key: string): Promise<string | null | unknown>;
84
+ set(key: string, value: unknown, opts?: Record<string, unknown>): Promise<unknown>;
85
+ del(...keys: string[]): Promise<number>;
86
+ exists(...keys: string[]): Promise<number>;
87
+ scan(cursor: number | string, opts?: {
88
+ match?: string;
89
+ count?: number;
90
+ }): Promise<[number, string[]] | [string, string[]]>;
91
+ eval?(script: string, keys: string[], args: (string | number)[]): Promise<unknown>;
92
+ }
93
+ /**
94
+ * Wrap an `@upstash/redis` REST client as an idempotency `RedisClient`.
95
+ *
96
+ * Enables running arc's idempotency store on Cloudflare Workers, Vercel Edge
97
+ * and Deno Deploy — runtimes that don't support raw TCP (ioredis).
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * import { Redis } from '@upstash/redis';
102
+ * import { RedisIdempotencyStore, upstashAsIdempotencyClient }
103
+ * from '@classytic/arc/idempotency/redis';
104
+ *
105
+ * const redis = Redis.fromEnv();
106
+ * const store = new RedisIdempotencyStore({
107
+ * client: upstashAsIdempotencyClient(redis),
108
+ * });
109
+ * ```
110
+ */
111
+ declare function upstashAsIdempotencyClient(client: UpstashRedisLike): RedisClient & {
112
+ eval?: (script: string, numkeys: number, ...args: (string | number)[]) => Promise<unknown>;
113
+ };
114
+ //#endregion
115
+ export { UpstashRedisLike as a, RedisIdempotencyStoreOptions as i, RedisClient as n, ioredisAsIdempotencyClient as o, RedisIdempotencyStore as r, upstashAsIdempotencyClient as s, IoredisLike as t };
@@ -1,4 +1,4 @@
1
- import { i as EventTransport, n as EventHandler, r as EventLogger, t as DomainEvent } from "./EventTransport-CinyO7zQ.mjs";
1
+ import { i as EventTransport, n as EventHandler, r as EventLogger, t as DomainEvent } from "./EventTransport-BXja8NOc.mjs";
2
2
 
3
3
  //#region src/events/transports/redis-stream.d.ts
4
4
  interface RedisStreamLike {
@@ -1,4 +1,4 @@
1
- import { Gt as RegisterOptions, H as IntrospectionPluginOptions, Kt as ResourceRegistry } from "../interface-BVuMfeVv.mjs";
1
+ import { Gt as RegisterOptions, H as IntrospectionPluginOptions, Kt as ResourceRegistry } from "../interface-CMRutPfe.mjs";
2
2
  import { FastifyPluginAsync } from "fastify";
3
3
 
4
4
  //#region src/registry/introspectionPlugin.d.ts
@@ -1,3 +1,3 @@
1
- import { n as introspectionPlugin_default, t as introspectionPlugin } from "../registry-B0Wl7uVV.mjs";
2
- import { t as ResourceRegistry } from "../ResourceRegistry-Dq3_zBQP.mjs";
1
+ import { n as introspectionPlugin_default, t as introspectionPlugin } from "../registry-BiTKT1Dg.mjs";
2
+ import { t as ResourceRegistry } from "../ResourceRegistry-C6uXlWe3.mjs";
3
3
  export { ResourceRegistry, introspectionPlugin_default as introspectionPlugin, introspectionPlugin as introspectionPluginFn };
@@ -1,6 +1,6 @@
1
1
  import { t as BaseController } from "./BaseController-DAGGc5Xn.mjs";
2
2
  import { n as normalizePermissionResult } from "./applyPermissionResult-D6GPMsvh.mjs";
3
- import { t as pluralize } from "./pluralize-A0tWEl1K.mjs";
3
+ import { t as pluralize } from "./pluralize-CWP6MB39.mjs";
4
4
  import { z } from "zod";
5
5
  //#region src/integrations/mcp/createMcpServer.ts
6
6
  /**
@@ -1,4 +1,4 @@
1
- import { r as CircuitBreakerOptions } from "../circuitBreaker-CvXkjfrW.mjs";
1
+ import { r as CircuitBreakerOptions } from "../circuitBreaker-dTtG-UyS.mjs";
2
2
 
3
3
  //#region src/rpc/serviceClient.d.ts
4
4
  interface RetryConfig {
@@ -1,4 +1,8 @@
1
1
  //#region src/utils/schemaConverter.ts
2
+ /** Default target for Fastify-consumed schemas (matches Fastify v5's default AJV draft). */
3
+ const DEFAULT_FASTIFY_TARGET = "draft-7";
4
+ /** Default target for OpenAPI document generation (matches arc's emitted OpenAPI version). */
5
+ const DEFAULT_OPENAPI_TARGET = "openapi-3.0";
2
6
  let _toJSONSchema = null;
3
7
  import("zod").then(({ z }) => {
4
8
  if (typeof z?.toJSONSchema === "function") _toJSONSchema = (schema, opts) => z.toJSONSchema(schema, opts);
@@ -26,17 +30,23 @@ function isZodSchema(input) {
26
30
  * Detection order:
27
31
  * 1. `null`/`undefined` → `undefined`
28
32
  * 2. Already JSON Schema → pass through as-is (zero overhead)
29
- * 3. Zod v4 schema → `z.toJSONSchema(schema, { target: 'openapi-3.0' })`
33
+ * 3. Zod v4 schema → `z.toJSONSchema(schema, { target })`
30
34
  * 4. Unrecognized object → return as-is (treat as opaque schema)
35
+ *
36
+ * @param input Schema (Zod, plain JSON Schema, or opaque object)
37
+ * @param target Output target — defaults to `draft-7` for Fastify compatibility.
38
+ * Pass `openapi-3.0`/`openapi-3.1` for OpenAPI document generation.
31
39
  */
32
- function toJsonSchema(input) {
40
+ function toJsonSchema(input, target = DEFAULT_FASTIFY_TARGET) {
33
41
  if (input == null) return void 0;
34
42
  if (typeof input !== "object") return void 0;
35
43
  if (isJsonSchema(input)) return input;
36
44
  if (isZodSchema(input)) {
37
45
  if (!_toJSONSchema) return input;
38
46
  try {
39
- return _toJSONSchema(input, { target: "openapi-3.0" });
47
+ const converted = _toJSONSchema(input, { target });
48
+ if ("$schema" in converted) delete converted.$schema;
49
+ return converted;
40
50
  } catch {
41
51
  return { type: "object" };
42
52
  }
@@ -46,8 +56,11 @@ function toJsonSchema(input) {
46
56
  /**
47
57
  * Convert all schema fields in an OpenApiSchemas object.
48
58
  * JSON Schema values pass through unchanged. Only Zod schemas are converted.
59
+ *
60
+ * Defaults to the `openapi-3.0` target since this function feeds OpenAPI doc
61
+ * generation, not Fastify route validation.
49
62
  */
50
- function convertOpenApiSchemas(schemas) {
63
+ function convertOpenApiSchemas(schemas, target = DEFAULT_OPENAPI_TARGET) {
51
64
  const result = {};
52
65
  const schemaFields = [
53
66
  "entity",
@@ -59,7 +72,7 @@ function convertOpenApiSchemas(schemas) {
59
72
  ];
60
73
  for (const field of schemaFields) {
61
74
  const value = schemas[field];
62
- if (value !== void 0) result[field] = toJsonSchema(value) ?? value;
75
+ if (value !== void 0) result[field] = toJsonSchema(value, target) ?? value;
63
76
  }
64
77
  for (const [key, value] of Object.entries(schemas)) if (!schemaFields.includes(key)) result[key] = value;
65
78
  return result;
@@ -73,19 +86,22 @@ function convertOpenApiSchemas(schemas) {
73
86
  * JSON Schema values pass through unchanged. Only Zod schemas are converted.
74
87
  *
75
88
  * Used for both additionalRoutes and customSchemas (CRUD overrides).
89
+ *
90
+ * Defaults to `draft-7` so Fastify v5's bundled AJV 8 accepts the output.
91
+ * Pass `openapi-3.0` (or `openapi-3.1`) when generating OpenAPI documents.
76
92
  */
77
- function convertRouteSchema(schema) {
93
+ function convertRouteSchema(schema, target = DEFAULT_FASTIFY_TARGET) {
78
94
  const result = { ...schema };
79
95
  for (const field of [
80
96
  "body",
81
97
  "querystring",
82
98
  "params",
83
99
  "headers"
84
- ]) if (result[field] !== void 0) result[field] = toJsonSchema(result[field]) ?? result[field];
100
+ ]) if (result[field] !== void 0) result[field] = toJsonSchema(result[field], target) ?? result[field];
85
101
  if (result.response !== void 0 && typeof result.response === "object" && result.response !== null) {
86
102
  const responseObj = result.response;
87
103
  const convertedResponse = {};
88
- for (const [statusCode, responseSchema] of Object.entries(responseObj)) convertedResponse[statusCode] = toJsonSchema(responseSchema) ?? responseSchema;
104
+ for (const [statusCode, responseSchema] of Object.entries(responseObj)) convertedResponse[statusCode] = toJsonSchema(responseSchema, target) ?? responseSchema;
89
105
  result.response = convertedResponse;
90
106
  }
91
107
  return result;
@@ -1,5 +1,5 @@
1
- import { _ as isAuthenticated, a as getClientId, b as isOrgInScope, c as getOrgRoles, d as getScopeContextMap, f as getServiceScopes, g as hasOrgAccess, h as getUserRoles, i as getAncestorOrgIds, l as getRequestScope, m as getUserId, n as PUBLIC_SCOPE, o as getOrgContext, p as getTeamId, r as RequestScope, s as getOrgId, t as AUTHENTICATED_SCOPE, u as getScopeContext, v as isElevated, x as isService, y as isMember } from "../types-C72d3NDn.mjs";
2
- import { i as elevationPlugin, n as ElevationOptions, r as _default, t as ElevationEvent } from "../elevation-s5ykdNHr.mjs";
1
+ import { _ as isAuthenticated, a as getClientId, b as isOrgInScope, c as getOrgRoles, d as getScopeContextMap, f as getServiceScopes, g as hasOrgAccess, h as getUserRoles, i as getAncestorOrgIds, l as getRequestScope, m as getUserId, n as PUBLIC_SCOPE, o as getOrgContext, p as getTeamId, r as RequestScope, s as getOrgId, t as AUTHENTICATED_SCOPE, u as getScopeContext, v as isElevated, x as isService, y as isMember } from "../types-BD85MlEK.mjs";
2
+ import { i as elevationPlugin, n as ElevationOptions, r as _default, t as ElevationEvent } from "../elevation-B6S5csVA.mjs";
3
3
  import { FastifyReply, FastifyRequest } from "fastify";
4
4
 
5
5
  //#region src/scope/rateLimitKey.d.ts
@@ -1,6 +1,6 @@
1
1
  import { _ as isElevated, a as getOrgContext, b as isService, c as getRequestScope, d as getServiceScopes, f as getTeamId, g as isAuthenticated, h as hasOrgAccess, i as getClientId, l as getScopeContext, m as getUserRoles, n as PUBLIC_SCOPE, o as getOrgId, p as getUserId, r as getAncestorOrgIds, s as getOrgRoles, t as AUTHENTICATED_SCOPE, u as getScopeContextMap, v as isMember, y as isOrgInScope } from "../types-AOD8fxIw.mjs";
2
2
  import { n as normalizeRoles } from "../types-ZUu_h0jp.mjs";
3
- import { n as elevation_default, t as elevationPlugin } from "../elevation-BBGFjzIP.mjs";
3
+ import { n as elevation_default, t as elevationPlugin } from "../elevation-DtFxrG0s.mjs";
4
4
  //#region src/scope/rateLimitKey.ts
5
5
  function createTenantKeyGenerator(opts) {
6
6
  if (opts?.strategy) return opts.strategy;
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./chunk-BpYLSNr0.mjs";
2
2
  import { n as PUBLIC_SCOPE, o as getOrgId } from "./types-AOD8fxIw.mjs";
3
- import { t as arcLog } from "./logger-CDjpjySd.mjs";
3
+ import { t as arcLog } from "./logger-D1YrIImS.mjs";
4
4
  import fp from "fastify-plugin";
5
5
  //#region src/plugins/sse.ts
6
6
  var sse_exports = /* @__PURE__ */ __exportAll({
@@ -0,0 +1,146 @@
1
+ //#region src/types/storage.d.ts
2
+ /**
3
+ * Arc's minimal backend-agnostic storage contract.
4
+ *
5
+ * Implementations live OUTSIDE arc core. This interface is deliberately
6
+ * small — no variants, no hashing, no CDN transforms, no multi-tenancy
7
+ * policy. Those are adapter concerns.
8
+ *
9
+ * Adapter authors should verify their implementation with
10
+ * `runStorageContract()` from `@classytic/arc/testing/storage` —
11
+ * passing the contract guarantees compatibility with every arc preset
12
+ * that consumes `Storage`.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import type { Storage } from '@classytic/arc/types/storage';
17
+ *
18
+ * export function memoryStorage(): Storage {
19
+ * const rows = new Map<string, { buffer: Buffer; contentType: string }>();
20
+ * return {
21
+ * async upload(input) {
22
+ * const id = crypto.randomUUID();
23
+ * rows.set(id, { buffer: input.buffer, contentType: input.mimeType });
24
+ * return { id, url: `memory://${id}`, pathname: id, contentType: input.mimeType, bytes: input.size };
25
+ * },
26
+ * async read(id) {
27
+ * const row = rows.get(id);
28
+ * if (!row) throw new Error('Not found');
29
+ * return { kind: 'buffer', buffer: row.buffer, contentType: row.contentType };
30
+ * },
31
+ * async delete(id) { return rows.delete(id); },
32
+ * };
33
+ * }
34
+ * ```
35
+ */
36
+ /**
37
+ * Input passed to `Storage.upload()`.
38
+ * The preset populates this from the parsed multipart file.
39
+ */
40
+ interface StorageUploadInput {
41
+ /** File bytes. */
42
+ buffer: Buffer;
43
+ /** Original filename from the client. */
44
+ filename: string;
45
+ /** IANA media type — preset validates via `multipartBody`. */
46
+ mimeType: string;
47
+ /** Size in bytes. Equals `buffer.length`. */
48
+ size: number;
49
+ }
50
+ /**
51
+ * Context threaded through every storage call.
52
+ * Adapters decide which keys they care about.
53
+ */
54
+ interface StorageContext {
55
+ /**
56
+ * App-defined scope. Arc populates this from `RequestScope` via the preset's
57
+ * `contextFrom` option so adapters can isolate per-tenant / per-user / per-project.
58
+ */
59
+ scope?: Record<string, unknown>;
60
+ /** Optional request correlation id for logging. */
61
+ requestId?: string;
62
+ }
63
+ /**
64
+ * Handle returned by `Storage.upload()`.
65
+ * The adapter owns the id namespace and URL format.
66
+ */
67
+ interface StorageFile {
68
+ /** Stable ID — the adapter owns the namespace. Used as the route param for GET/DELETE. */
69
+ id: string;
70
+ /** Public or signed URL — what the frontend stores in an `<img src>`. */
71
+ url: string;
72
+ /** Storage-side path / key. Opaque to arc; useful for admin tooling. */
73
+ pathname: string;
74
+ /** IANA media type — usually echoed from `input.mimeType`. */
75
+ contentType: string;
76
+ /** Size in bytes. */
77
+ bytes: number;
78
+ /** Adapter-defined metadata passed through to the response body. */
79
+ metadata?: Record<string, unknown>;
80
+ }
81
+ /**
82
+ * Optional byte range for partial reads.
83
+ * End-inclusive, matching HTTP `Range: bytes=start-end` semantics and
84
+ * media-kit's `StorageDriver.read()` contract.
85
+ */
86
+ interface StorageReadRange {
87
+ /** First byte offset (inclusive). */
88
+ start: number;
89
+ /** Last byte offset (inclusive). */
90
+ end: number;
91
+ }
92
+ /**
93
+ * Result of `Storage.read()`.
94
+ * Adapters pick whichever shape is natural; the preset handler branches on `kind`.
95
+ * Large/remote backends should return a stream; small/in-memory backends can
96
+ * return a buffer without wrapping it in a `PassThrough` for no reason.
97
+ */
98
+ type StorageReadResult = {
99
+ kind: "stream";
100
+ stream: NodeJS.ReadableStream;
101
+ contentType: string; /** Total size of the full object (NOT the ranged slice). Required for `Content-Range`. */
102
+ bytes?: number; /** Actual byte range returned when the caller passed `range`. */
103
+ range?: StorageReadRange;
104
+ } | {
105
+ kind: "buffer";
106
+ buffer: Buffer;
107
+ contentType: string; /** Total size of the full object. Used for `Content-Range` on partial reads. */
108
+ totalBytes?: number; /** Actual byte range returned when the caller passed `range`. */
109
+ range?: StorageReadRange;
110
+ };
111
+ /**
112
+ * Minimal storage contract consumed by `filesUploadPreset`.
113
+ *
114
+ * Adapters are ~50–100 LOC wrappers around S3, GCS, local FS, GridFS,
115
+ * media-kit, or a provider Files API. Ship zero reference adapters in
116
+ * arc core — the one you'd pick is always the wrong default.
117
+ */
118
+ interface Storage {
119
+ /** Write bytes, return a stable handle. */
120
+ upload(input: StorageUploadInput, ctx: StorageContext): Promise<StorageFile>;
121
+ /**
122
+ * Read bytes by id. Streaming preferred; Buffer fine for small files.
123
+ *
124
+ * If `range` is provided, implementations SHOULD return only the requested
125
+ * slice and set `range` on the result. Implementations that cannot range
126
+ * (e.g. trivial in-memory adapters) MAY return the full object and let the
127
+ * preset slice it — the preset handles both cases.
128
+ */
129
+ read(id: string, ctx: StorageContext, range?: StorageReadRange): Promise<StorageReadResult>;
130
+ /**
131
+ * Remove bytes by id. MAY be a soft delete — the interface doesn't
132
+ * dictate lifecycle. Return `false` when the id was already absent.
133
+ */
134
+ delete(id: string, ctx: StorageContext): Promise<boolean>;
135
+ /** Optional — fast existence check without a full read. */
136
+ exists?(id: string, ctx: StorageContext): Promise<boolean>;
137
+ /**
138
+ * Optional — return a fresh URL for an existing id. Called by the preset
139
+ * when the stored `url` may have expired (signed URLs, rotated buckets).
140
+ * Default behavior when omitted: the preset falls back to the url stored
141
+ * on the original `upload()` result.
142
+ */
143
+ resolveUrl?(id: string, ctx: StorageContext): Promise<string>;
144
+ }
145
+ //#endregion
146
+ export { StorageReadResult as a, StorageReadRange as i, StorageContext as n, StorageUploadInput as o, StorageFile as r, Storage as t };
@@ -1,5 +1,6 @@
1
- import { Zt as CrudRepository, m as AnyRecord, qt as ResourceDefinition } from "../interface-BVuMfeVv.mjs";
2
- import { d as ResourceLike, r as CreateAppOptions } from "../types-Bg2X42_m.mjs";
1
+ import { Zt as CrudRepository, m as AnyRecord, qt as ResourceDefinition } from "../interface-CMRutPfe.mjs";
2
+ import { d as ResourceLike, r as CreateAppOptions } from "../types-Ch9pTQbf.mjs";
3
+ import { StorageContractSetup, StorageContractSetupResult, runStorageContract } from "./storageContract.mjs";
3
4
  import Fastify, { FastifyInstance, FastifyServerOptions } from "fastify";
4
5
  import { Connection } from "mongoose";
5
6
  import { Mock } from "vitest";
@@ -921,4 +922,4 @@ declare class TestDataLoader {
921
922
  cleanup(): Promise<void>;
922
923
  }
923
924
  //#endregion
924
- export { type AuthProvider, type AuthResponse, type BetterAuthTestHelpers, type BetterAuthTestHelpersOptions, type CreateTestAppOptions, DatabaseSnapshot, TestFixtures as DbTestFixtures, type GenerateTestFileOptions, HttpTestHarness, type HttpTestHarnessOptions, InMemoryDatabase, type OrgResponse, type SetupBetterAuthOrgOptions, type SetupUserConfig, type TestAppResult, TestDataLoader, TestDatabase, type TestFixtures$1 as TestFixtures, TestHarness, type TestHarnessOptions, type TestOrgContext, TestRequestBuilder, TestSeeder, TestTransaction, type TestUserContext, createBetterAuthProvider, createBetterAuthTestHelpers, createConfigTestSuite, createDataFactory, createHttpTestHarness, createJwtAuthProvider, createMinimalTestApp, createMockController, createMockReply, createMockRepository, createMockRequest, createMockUser, createSnapshotMatcher, createSpy, createTestApp, createTestAuth, createTestHarness, createTestTimer, generateTestFile, preloadResources, preloadResourcesAsync, request, safeParseBody, setupBetterAuthOrg, waitFor, withTestDb };
925
+ export { type AuthProvider, type AuthResponse, type BetterAuthTestHelpers, type BetterAuthTestHelpersOptions, type CreateTestAppOptions, DatabaseSnapshot, TestFixtures as DbTestFixtures, type GenerateTestFileOptions, HttpTestHarness, type HttpTestHarnessOptions, InMemoryDatabase, type OrgResponse, type SetupBetterAuthOrgOptions, type SetupUserConfig, type StorageContractSetup, type StorageContractSetupResult, type TestAppResult, TestDataLoader, TestDatabase, type TestFixtures$1 as TestFixtures, TestHarness, type TestHarnessOptions, type TestOrgContext, TestRequestBuilder, TestSeeder, TestTransaction, type TestUserContext, createBetterAuthProvider, createBetterAuthTestHelpers, createConfigTestSuite, createDataFactory, createHttpTestHarness, createJwtAuthProvider, createMinimalTestApp, createMockController, createMockReply, createMockRepository, createMockRequest, createMockUser, createSnapshotMatcher, createSpy, createTestApp, createTestAuth, createTestHarness, createTestTimer, generateTestFile, preloadResources, preloadResourcesAsync, request, runStorageContract, safeParseBody, setupBetterAuthOrg, waitFor, withTestDb };
@@ -1,5 +1,6 @@
1
1
  import { t as CRUD_OPERATIONS } from "../constants-Cxde4rpC.mjs";
2
2
  import { n as applyFieldWritePermissions, t as applyFieldReadPermissions } from "../fields-ipsbIRPK.mjs";
3
+ import { runStorageContract } from "./storageContract.mjs";
3
4
  import Fastify from "fastify";
4
5
  import mongoose from "mongoose";
5
6
  import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
@@ -1796,7 +1797,7 @@ function runEventTests(resourceName, displayName, events) {
1796
1797
  * ```
1797
1798
  */
1798
1799
  async function createTestApp(options = {}) {
1799
- const { createApp } = await import("../createApp-BOYjBgdI.mjs").then((n) => n.r);
1800
+ const { createApp } = await import("../createApp-B1EY8zxa.mjs").then((n) => n.r);
1800
1801
  const { useInMemoryDb = true, mongoUri: providedMongoUri, ...appOptions } = options;
1801
1802
  const defaultAuth = {
1802
1803
  type: "jwt",
@@ -1994,4 +1995,4 @@ var TestDataLoader = class {
1994
1995
  }
1995
1996
  };
1996
1997
  //#endregion
1997
- export { DatabaseSnapshot, TestFixtures as DbTestFixtures, HttpTestHarness, InMemoryDatabase, TestDataLoader, TestDatabase, TestHarness, TestRequestBuilder, TestSeeder, TestTransaction, createBetterAuthProvider, createBetterAuthTestHelpers, createConfigTestSuite, createDataFactory, createHttpTestHarness, createJwtAuthProvider, createMinimalTestApp, createMockController, createMockReply, createMockRepository, createMockRequest, createMockUser, createSnapshotMatcher, createSpy, createTestApp, createTestAuth, createTestHarness, createTestTimer, generateTestFile, preloadResources, preloadResourcesAsync, request, safeParseBody, setupBetterAuthOrg, waitFor, withTestDb };
1998
+ export { DatabaseSnapshot, TestFixtures as DbTestFixtures, HttpTestHarness, InMemoryDatabase, TestDataLoader, TestDatabase, TestHarness, TestRequestBuilder, TestSeeder, TestTransaction, createBetterAuthProvider, createBetterAuthTestHelpers, createConfigTestSuite, createDataFactory, createHttpTestHarness, createJwtAuthProvider, createMinimalTestApp, createMockController, createMockReply, createMockRepository, createMockRequest, createMockUser, createSnapshotMatcher, createSpy, createTestApp, createTestAuth, createTestHarness, createTestTimer, generateTestFile, preloadResources, preloadResourcesAsync, request, runStorageContract, safeParseBody, setupBetterAuthOrg, waitFor, withTestDb };
@@ -0,0 +1,26 @@
1
+ import { t as Storage } from "../storage-Dfzt4VTl.mjs";
2
+
3
+ //#region src/testing/storageContract.d.ts
4
+ interface StorageContractSetupResult {
5
+ storage: Storage;
6
+ teardown: () => Promise<void>;
7
+ }
8
+ type StorageContractSetup = () => Promise<StorageContractSetupResult>;
9
+ /**
10
+ * Register the storage contract suite under the caller's name.
11
+ *
12
+ * Assertions covered:
13
+ * 1. upload() returns a StorageFile with every required field populated
14
+ * 2. read(upload.id) round-trips the exact bytes
15
+ * 3. delete() returns true on first call
16
+ * 4. delete() returns false (or throws) on a missing id
17
+ * 5. exists() (if implemented) agrees with upload/delete state
18
+ * 6. resolveUrl() (if implemented) returns a non-empty URL for an existing id
19
+ * 7. Two isolated scopes don't collide (scope threading)
20
+ * 8. Full lifecycle: upload → read → delete → read rejects
21
+ * 9. Both `kind: "stream"` and `kind: "buffer"` read results deliver correct bytes
22
+ * 10. Ranged reads (if adapter supports them) slice correctly
23
+ */
24
+ declare function runStorageContract(name: string, setup: StorageContractSetup): void;
25
+ //#endregion
26
+ export { StorageContractSetup, StorageContractSetupResult, runStorageContract };