@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.
Files changed (132) hide show
  1. package/README.md +20 -91
  2. package/dist/{BaseController-Vu2yc56T.mjs → BaseController-DVNKvoX4.mjs} +154 -170
  3. package/dist/{ResourceRegistry-Dq3_zBQP.mjs → ResourceRegistry-CcN2LVrc.mjs} +1 -1
  4. package/dist/actionPermissions-TUVR3uiZ.mjs +22 -0
  5. package/dist/adapters/index.d.mts +3 -3
  6. package/dist/adapters/index.mjs +2 -2
  7. package/dist/{adapters-BBqAVvPK.mjs → adapters-BXY4i-hw.mjs} +210 -41
  8. package/dist/audit/index.d.mts +38 -3
  9. package/dist/audit/index.mjs +54 -22
  10. package/dist/auth/index.d.mts +2 -2
  11. package/dist/auth/index.mjs +3 -3
  12. package/dist/cache/index.d.mts +17 -15
  13. package/dist/cache/index.mjs +16 -15
  14. package/dist/{caching-CjybdRwx.mjs → caching-3h93rkJM.mjs} +8 -3
  15. package/dist/cli/commands/describe.mjs +1 -1
  16. package/dist/cli/commands/docs.mjs +2 -2
  17. package/dist/cli/commands/init.mjs +1 -1
  18. package/dist/cli/commands/introspect.mjs +1 -1
  19. package/dist/context/index.d.mts +58 -0
  20. package/dist/context/index.mjs +2 -0
  21. package/dist/core/index.d.mts +2 -2
  22. package/dist/core/index.mjs +3 -4
  23. package/dist/{defineResource-C__jkwvs.mjs → core-3MWJosCH.mjs} +174 -94
  24. package/dist/{createActionRouter-DH1YFL9m.mjs → createActionRouter-C8UUB3Px.mjs} +1 -1
  25. package/dist/{createApp-CBJUJKGP.mjs → createApp-BwnEAO2h.mjs} +53 -19
  26. package/dist/docs/index.d.mts +1 -1
  27. package/dist/docs/index.mjs +2 -2
  28. package/dist/{elevation-DxQ6ACbt.mjs → elevation-Dci0AYLT.mjs} +2 -2
  29. package/dist/errorHandler-2ii4RIYr.d.mts +114 -0
  30. package/dist/{errorHandler-CZDW4EXS.mjs → errorHandler-CSxe7KIM.mjs} +1 -1
  31. package/dist/{eventPlugin-Dl7MoVWH.mjs → eventPlugin-ByU4Cv0e.mjs} +1 -1
  32. package/dist/{eventPlugin-BxvaCIZF.d.mts → eventPlugin-D1ThQ1Pp.d.mts} +1 -1
  33. package/dist/events/index.d.mts +8 -5
  34. package/dist/events/index.mjs +87 -52
  35. package/dist/events/transports/redis-stream-entry.d.mts +1 -1
  36. package/dist/events/transports/redis.d.mts +1 -1
  37. package/dist/factory/index.d.mts +1 -1
  38. package/dist/factory/index.mjs +1 -1
  39. package/dist/{types-DZi1aYhm.d.mts → fields-C8Y0XLAu.d.mts} +122 -2
  40. package/dist/hooks/index.d.mts +1 -1
  41. package/dist/idempotency/index.d.mts +5 -2
  42. package/dist/idempotency/index.mjs +46 -37
  43. package/dist/{interface-YrWsmKqE.d.mts → index-BGbpGVyM.d.mts} +2107 -2756
  44. package/dist/{index-CtGKT0lf.d.mts → index-BziRPS4H.d.mts} +81 -7
  45. package/dist/{index-C-xjcA6F.d.mts → index-C_Noptz-.d.mts} +284 -409
  46. package/dist/{index-Cibkchnx.d.mts → index-EqQN6p0W.d.mts} +3 -3
  47. package/dist/index.d.mts +6 -219
  48. package/dist/index.mjs +10 -131
  49. package/dist/integrations/event-gateway.d.mts +1 -1
  50. package/dist/integrations/event-gateway.mjs +1 -1
  51. package/dist/integrations/index.d.mts +1 -1
  52. package/dist/integrations/mcp/index.d.mts +2 -2
  53. package/dist/integrations/mcp/index.mjs +1 -1
  54. package/dist/integrations/mcp/testing.d.mts +1 -1
  55. package/dist/integrations/mcp/testing.mjs +1 -1
  56. package/dist/interface-yhyb_pLY.d.mts +77 -0
  57. package/dist/logger/index.d.mts +81 -0
  58. package/dist/{logger-CDjpjySd.mjs → logger/index.mjs} +1 -6
  59. package/dist/{memory-BFAYkf8H.mjs → memory-DqI-449b.mjs} +23 -8
  60. package/dist/middleware/index.d.mts +109 -0
  61. package/dist/middleware/index.mjs +70 -0
  62. package/dist/multipartBody-CUQGVlM_.mjs +123 -0
  63. package/dist/{openapi-CXuTG1M9.mjs → openapi-DpNpqBmo.mjs} +9 -7
  64. package/dist/org/index.d.mts +2 -2
  65. package/dist/permissions/index.d.mts +3 -4
  66. package/dist/permissions/index.mjs +5 -5
  67. package/dist/{permissions-oNZawnkR.mjs → permissions-wkqRwicB.mjs} +315 -397
  68. package/dist/pipe-CGJxqDGx.mjs +62 -0
  69. package/dist/pipeline/index.d.mts +62 -0
  70. package/dist/pipeline/index.mjs +53 -0
  71. package/dist/plugins/index.d.mts +23 -3
  72. package/dist/plugins/index.mjs +9 -11
  73. package/dist/plugins/response-cache.mjs +1 -1
  74. package/dist/plugins/tracing-entry.mjs +1 -1
  75. package/dist/presets/filesUpload.d.mts +3 -3
  76. package/dist/presets/filesUpload.mjs +255 -1
  77. package/dist/presets/index.d.mts +1 -1
  78. package/dist/presets/index.mjs +2 -2
  79. package/dist/presets/multiTenant.d.mts +1 -1
  80. package/dist/presets/multiTenant.mjs +43 -9
  81. package/dist/presets/search.d.mts +91 -4
  82. package/dist/presets/search.mjs +1 -1
  83. package/dist/{presets-hM4WhNWY.mjs → presets-CrwOvuXI.mjs} +1 -1
  84. package/dist/{queryCachePlugin-DbUVroUG.mjs → queryCachePlugin-ChLNZvFT.mjs} +9 -9
  85. package/dist/{queryCachePlugin-CnTZZTC5.d.mts → queryCachePlugin-Dumka73q.d.mts} +1 -1
  86. package/dist/{queryParser-Cs-6SHQK.mjs → queryParser-NR__Qiju.mjs} +69 -2
  87. package/dist/{redis-stream-Bz-4q96t.d.mts → redis-stream-bkO88VHx.d.mts} +1 -1
  88. package/dist/registry/index.d.mts +1 -1
  89. package/dist/registry/index.mjs +1 -1
  90. package/dist/{requestContext-DYtmNpm5.mjs → requestContext-C38GskNt.mjs} +1 -1
  91. package/dist/{resourceToTools-C3cWymnW.mjs → resourceToTools-BhF3JV5p.mjs} +8 -3
  92. package/dist/scope/index.d.mts +2 -2
  93. package/dist/scope/index.mjs +2 -2
  94. package/dist/{sse-CJpt7LGI.mjs → sse-D8UeDwis.mjs} +1 -1
  95. package/dist/{store-helpers-DFiZl5TL.mjs → store-helpers-DYYUQbQN.mjs} +4 -0
  96. package/dist/testing/index.d.mts +6 -5
  97. package/dist/testing/index.mjs +17 -10
  98. package/dist/types/index.d.mts +5 -5
  99. package/dist/types/index.mjs +1 -31
  100. package/dist/types-CDnTEpga.mjs +27 -0
  101. package/dist/{types-CoSzA-s-.d.mts → types-CVKBssX5.d.mts} +1 -1
  102. package/dist/{types-CunEX4UX.d.mts → types-CVdgPXBW.d.mts} +20 -7
  103. package/dist/utils/index.d.mts +277 -3
  104. package/dist/utils/index.mjs +4 -5
  105. package/dist/{utils-B7FuRr9w.mjs → utils-LMwVidKy.mjs} +303 -2
  106. package/dist/{versioning-Cm8qoFDg.mjs → versioning-B6mimogM.mjs} +3 -5
  107. package/dist/versioning-CeUXHfjw.d.mts +117 -0
  108. package/package.json +31 -18
  109. package/skills/arc/SKILL.md +8 -12
  110. package/skills/arc/references/production.md +0 -41
  111. package/dist/circuitBreaker-CvXkjfrW.d.mts +0 -206
  112. package/dist/circuitBreaker-l18oRgL5.mjs +0 -284
  113. package/dist/core-DNncu0xF.mjs +0 -34
  114. package/dist/dynamic/index.d.mts +0 -93
  115. package/dist/dynamic/index.mjs +0 -122
  116. package/dist/errorHandler-DixGcttC.d.mts +0 -218
  117. package/dist/fields-BC7zcmI9.d.mts +0 -121
  118. package/dist/filesUpload-q8oHt--L.mjs +0 -377
  119. package/dist/interface-DplgQO2e.d.mts +0 -54
  120. package/dist/policies/index.d.mts +0 -425
  121. package/dist/policies/index.mjs +0 -318
  122. package/dist/rpc/index.d.mts +0 -90
  123. package/dist/rpc/index.mjs +0 -248
  124. /package/dist/{EventTransport-CqZ8FyM_.d.mts → EventTransport-CfVEGaEl.d.mts} +0 -0
  125. /package/dist/{applyPermissionResult-bqGpo9ML.mjs → applyPermissionResult-QhV1Pa-g.mjs} +0 -0
  126. /package/dist/{constants-Cxde4rpC.mjs → constants-BhY1OHoH.mjs} +0 -0
  127. /package/dist/{elevation-B6S5csVA.d.mts → elevation-s5ykdNHr.d.mts} +0 -0
  128. /package/dist/{errors-CqWnSqM-.mjs → errors-BqdUDja_.mjs} +0 -0
  129. /package/dist/{fields-CU6FlaDV.mjs → fields-CTMWOUDt.mjs} +0 -0
  130. /package/dist/{keys-qcD-TVJl.mjs → keys-nWQGUTu1.mjs} +0 -0
  131. /package/dist/{types-ZUu_h0jp.mjs → types-D57iXYb8.mjs} +0 -0
  132. /package/dist/{types-BD85MlEK.d.mts → types-tgR4Pt8F.d.mts} +0 -0
@@ -1,377 +0,0 @@
1
- import { o as getOrgId, p as getUserId } from "./types-AOD8fxIw.mjs";
2
- import { i as NotFoundError, u as ValidationError } from "./errors-CqWnSqM-.mjs";
3
- import { n as allowPublic, s as requireAuth } from "./permissions-oNZawnkR.mjs";
4
- //#region src/middleware/multipartBody.ts
5
- const DEFAULT_MAX_FILE_SIZE$1 = 10 * 1024 * 1024;
6
- const DEFAULT_MAX_FILES = 5;
7
- const DEFAULT_FILES_KEY = "_files";
8
- /**
9
- * Build a matcher for MIME allow-lists that supports exact (e.g. `image/png`),
10
- * subtype wildcards (e.g. `image/\*`), and total wildcards (`\*` or `\*\/\*`).
11
- *
12
- * Returns `undefined` when no filter is needed — either because the option
13
- * was omitted or because a total wildcard was present.
14
- */
15
- function buildMimeMatcher(allowed) {
16
- if (!allowed || allowed.length === 0) return void 0;
17
- const exact = /* @__PURE__ */ new Set();
18
- const prefixes = [];
19
- for (const entry of allowed) {
20
- const value = entry.trim().toLowerCase();
21
- if (!value) continue;
22
- if (value === "*" || value === "*/*") return void 0;
23
- if (value.endsWith("/*")) prefixes.push(value.slice(0, -1));
24
- else exact.add(value);
25
- }
26
- if (exact.size === 0 && prefixes.length === 0) return void 0;
27
- return {
28
- matches(mime) {
29
- const m = mime.toLowerCase();
30
- if (exact.has(m)) return true;
31
- for (const p of prefixes) if (m.startsWith(p)) return true;
32
- return false;
33
- },
34
- describe() {
35
- return [...exact, ...prefixes.map((p) => `${p}*`)].join(", ");
36
- }
37
- };
38
- }
39
- /**
40
- * Create a multipart body parsing middleware.
41
- *
42
- * When a request has `content-type: multipart/form-data`, this middleware:
43
- * 1. Reads all parts (fields + files)
44
- * 2. Sets text fields on `req.body` as a plain object
45
- * 3. Attaches file buffers to `req.body[filesKey]` (default: `req.body._files`)
46
- *
47
- * For non-multipart requests (regular JSON), this is a no-op — the request
48
- * passes through unchanged. This makes it safe to add to create/update
49
- * middlewares without breaking JSON clients.
50
- */
51
- function multipartBody(options = {}) {
52
- const maxFileSize = options.maxFileSize ?? DEFAULT_MAX_FILE_SIZE$1;
53
- const maxFiles = options.maxFiles ?? DEFAULT_MAX_FILES;
54
- const mimeMatcher = buildMimeMatcher(options.allowedMimeTypes);
55
- const filesKey = options.filesKey ?? DEFAULT_FILES_KEY;
56
- const requiredFields = options.requiredFields && options.requiredFields.length > 0 ? options.requiredFields : void 0;
57
- return async function parseMultipartBody(request, reply) {
58
- if (!(request.headers["content-type"] ?? "").includes("multipart/form-data")) return;
59
- if (typeof request.parts !== "function") {
60
- request.log.warn("multipartBody middleware: @fastify/multipart not registered. Ensure createApp() has multipart enabled (default) or install @fastify/multipart.");
61
- return;
62
- }
63
- const body = {};
64
- const files = {};
65
- let fileCount = 0;
66
- try {
67
- const parts = request.parts();
68
- for await (const part of parts) if (part.type === "file") {
69
- if (fileCount >= maxFiles) continue;
70
- if (mimeMatcher && !mimeMatcher.matches(part.mimetype)) return reply.code(415).send({
71
- success: false,
72
- error: `File type '${part.mimetype}' not allowed. Accepted: ${mimeMatcher.describe()}`
73
- });
74
- const buffer = await part.toBuffer();
75
- if (buffer.length > maxFileSize) return reply.code(413).send({
76
- success: false,
77
- error: `File '${part.filename}' exceeds maximum size of ${Math.round(maxFileSize / 1024 / 1024)}MB`
78
- });
79
- files[part.fieldname] = {
80
- filename: part.filename,
81
- mimetype: part.mimetype,
82
- buffer,
83
- size: buffer.length,
84
- fieldname: part.fieldname
85
- };
86
- fileCount++;
87
- } else body[part.fieldname] = tryParseValue(part.value);
88
- } catch (err) {
89
- request.log.error({ err }, "multipartBody: failed to parse multipart form");
90
- return reply.code(400).send({
91
- success: false,
92
- error: "Failed to parse multipart form data"
93
- });
94
- }
95
- if (requiredFields) {
96
- const missing = requiredFields.filter((name) => !(name in files));
97
- if (missing.length > 0) return reply.code(400).send({
98
- success: false,
99
- error: `Missing required file field${missing.length > 1 ? "s" : ""}: ${missing.join(", ")}`,
100
- code: "MISSING_FILE_FIELDS",
101
- details: { missing }
102
- });
103
- }
104
- if (fileCount > 0) body[filesKey] = files;
105
- request.body = body;
106
- };
107
- }
108
- /**
109
- * Try to parse a form field value as JSON, number, or boolean.
110
- * Falls back to the raw string if parsing fails.
111
- */
112
- function tryParseValue(value) {
113
- if (value === "true") return true;
114
- if (value === "false") return false;
115
- if (value === "null") return null;
116
- if (/^-?\d+(\.\d+)?$/.test(value) && value.length < 16) {
117
- const num = Number(value);
118
- if (Number.isFinite(num)) return num;
119
- }
120
- if (value.startsWith("{") && value.endsWith("}") || value.startsWith("[") && value.endsWith("]")) try {
121
- return JSON.parse(value);
122
- } catch {}
123
- return value;
124
- }
125
- //#endregion
126
- //#region src/presets/filesUpload.ts
127
- const DEFAULT_FIELD_NAME = "file";
128
- const DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024;
129
- function defaultContextFrom(scope) {
130
- if (!scope) return {};
131
- const userId = getUserId(scope);
132
- const organizationId = getOrgId(scope);
133
- const ctx = {};
134
- if (userId !== void 0) ctx.userId = userId;
135
- if (organizationId !== void 0) ctx.organizationId = organizationId;
136
- return ctx;
137
- }
138
- function buildStorageContext(request, contextFrom) {
139
- const scope = request.scope;
140
- return {
141
- scope: contextFrom(scope),
142
- requestId: request.id
143
- };
144
- }
145
- /**
146
- * Parse a single-range `Range: bytes=start-end` header.
147
- *
148
- * Returns `undefined` when the header is missing or unparseable. Only
149
- * satisfiable single ranges are supported — multi-range requests fall through
150
- * to the full-object response (per RFC 7233 §4.1 a server MAY ignore ranges).
151
- */
152
- function parseRangeHeader(header, totalSize) {
153
- if (!header || !header.startsWith("bytes=")) return void 0;
154
- const spec = header.slice(6).split(",")[0]?.trim();
155
- if (!spec) return void 0;
156
- const dashIndex = spec.indexOf("-");
157
- if (dashIndex === -1) return void 0;
158
- const startRaw = spec.slice(0, dashIndex);
159
- const endRaw = spec.slice(dashIndex + 1);
160
- if (startRaw === "") {
161
- if (totalSize === void 0) return void 0;
162
- const suffix = Number(endRaw);
163
- if (!Number.isFinite(suffix) || suffix <= 0) return void 0;
164
- return {
165
- start: Math.max(0, totalSize - suffix),
166
- end: totalSize - 1
167
- };
168
- }
169
- const start = Number(startRaw);
170
- if (!Number.isFinite(start) || start < 0) return void 0;
171
- if (endRaw === "") {
172
- if (totalSize === void 0) return void 0;
173
- return {
174
- start,
175
- end: totalSize - 1
176
- };
177
- }
178
- const end = Number(endRaw);
179
- if (!Number.isFinite(end) || end < start) return void 0;
180
- if (totalSize !== void 0 && end >= totalSize) return {
181
- start,
182
- end: totalSize - 1
183
- };
184
- return {
185
- start,
186
- end
187
- };
188
- }
189
- /**
190
- * Strict policy — rejects filenames that could escape a storage root or
191
- * confuse a filesystem. Safe default for disk/S3 adapters that compose
192
- * `${prefix}/${filename}` or `path.join(root, filename)`.
193
- */
194
- function strictFilenamePolicy(filename) {
195
- if (filename.length === 0) throw new ValidationError("Upload filename is empty");
196
- if (filename.length > 255) throw new ValidationError("Upload filename exceeds 255 characters");
197
- if (filename.includes("\0")) throw new ValidationError("Upload filename contains a NUL byte");
198
- if (filename.includes("/") || filename.includes("\\")) throw new ValidationError("Upload filename contains a path separator");
199
- if (filename === "." || filename === "..") throw new ValidationError("Upload filename is a path traversal component");
200
- return filename;
201
- }
202
- /** Resolve the user-supplied policy option into a concrete validator. */
203
- function resolveFilenamePolicy(policy) {
204
- if (policy === void 0 || policy === true) return strictFilenamePolicy;
205
- if (policy === false || policy === "*") return (f) => f;
206
- if (typeof policy === "function") return (filename) => {
207
- const result = policy(filename);
208
- if (result === false) throw new ValidationError(`Upload filename rejected: ${filename}`);
209
- if (typeof result === "string") return result;
210
- return filename;
211
- };
212
- return strictFilenamePolicy;
213
- }
214
- function makeUploadHandler(deps) {
215
- return async function uploadHandler(request, reply) {
216
- const file = (request.body?._files)?.[deps.fieldName];
217
- if (!file) throw new ValidationError(`Missing file field '${deps.fieldName}' in multipart body`);
218
- const filename = deps.applyFilenamePolicy(file.filename);
219
- const ctx = buildStorageContext(request, deps.contextFrom);
220
- const result = await deps.storage.upload({
221
- buffer: file.buffer,
222
- filename,
223
- mimeType: file.mimetype,
224
- size: file.size
225
- }, ctx);
226
- return reply.code(201).send({
227
- success: true,
228
- data: toResponseFile(result)
229
- });
230
- };
231
- }
232
- function toResponseFile(file) {
233
- const payload = {
234
- id: file.id,
235
- url: file.url,
236
- pathname: file.pathname,
237
- contentType: file.contentType,
238
- bytes: file.bytes
239
- };
240
- if (file.metadata !== void 0) payload.metadata = file.metadata;
241
- return payload;
242
- }
243
- function makeReadHandler(deps) {
244
- return async function readHandler(request, reply) {
245
- const { id } = request.params;
246
- const ctx = buildStorageContext(request, deps.contextFrom);
247
- reply.header("Accept-Ranges", "bytes");
248
- const rangeHeader = request.headers.range;
249
- let result;
250
- try {
251
- const parsed = rangeHeader ? parseRangeHeader(rangeHeader, void 0) : void 0;
252
- result = await deps.storage.read(id, ctx, parsed);
253
- } catch (err) {
254
- throw toNotFound(err, "File", id);
255
- }
256
- if (result.kind === "buffer") return sendBuffer(reply, result, rangeHeader);
257
- return sendStream(reply, result, rangeHeader);
258
- };
259
- }
260
- function sendBuffer(reply, result, rangeHeader) {
261
- reply.type(result.contentType);
262
- const total = result.totalBytes ?? result.buffer.length;
263
- if (result.range) {
264
- const { start, end } = result.range;
265
- reply.code(206);
266
- reply.header("Content-Range", `bytes ${start}-${end}/${total}`);
267
- reply.header("Content-Length", String(result.buffer.length));
268
- return reply.send(result.buffer);
269
- }
270
- if (rangeHeader) {
271
- const parsed = parseRangeHeader(rangeHeader, total);
272
- if (parsed) {
273
- const slice = result.buffer.subarray(parsed.start, parsed.end + 1);
274
- reply.code(206);
275
- reply.header("Content-Range", `bytes ${parsed.start}-${parsed.end}/${total}`);
276
- reply.header("Content-Length", String(slice.length));
277
- return reply.send(slice);
278
- }
279
- }
280
- reply.header("Content-Length", String(result.buffer.length));
281
- return reply.send(result.buffer);
282
- }
283
- function sendStream(reply, result, rangeHeader) {
284
- reply.type(result.contentType);
285
- if (result.range && result.bytes !== void 0) {
286
- const { start, end } = result.range;
287
- reply.code(206);
288
- reply.header("Content-Range", `bytes ${start}-${end}/${result.bytes}`);
289
- reply.header("Content-Length", String(end - start + 1));
290
- } else if (result.bytes !== void 0) {
291
- reply.header("Content-Length", String(result.bytes));
292
- if (rangeHeader) reply.request.log.debug({ url: reply.request.url }, "filesUploadPreset: adapter returned unsliced stream for a range request — sending full object");
293
- }
294
- return reply.send(result.stream);
295
- }
296
- function makeDeleteHandler(deps) {
297
- return async function deleteHandler(request, reply) {
298
- const { id } = request.params;
299
- const ctx = buildStorageContext(request, deps.contextFrom);
300
- if (!await deps.storage.delete(id, ctx)) throw new NotFoundError("File", id);
301
- return reply.code(204).send();
302
- };
303
- }
304
- function toNotFound(err, resource, id) {
305
- if (err instanceof NotFoundError) return err;
306
- const maybe = err;
307
- if (maybe?.statusCode === 404 || maybe?.code === "NOT_FOUND") return new NotFoundError(resource, id);
308
- if (typeof maybe?.message === "string" && /not\s*found/i.test(maybe.message)) return new NotFoundError(resource, id);
309
- return err;
310
- }
311
- /**
312
- * Create a files-upload preset bound to a `Storage` adapter.
313
- *
314
- * The preset uses `raw: true` routes so binary responses bypass arc's JSON
315
- * envelope. Upload still returns the standard `{ success: true, data }`
316
- * envelope manually because the response is structured metadata, not bytes.
317
- */
318
- function filesUploadPreset(options) {
319
- if (!options?.storage) throw new Error("filesUploadPreset: `storage` is required");
320
- const deps = {
321
- storage: options.storage,
322
- fieldName: options.fieldName ?? DEFAULT_FIELD_NAME,
323
- contextFrom: options.contextFrom ?? defaultContextFrom,
324
- applyFilenamePolicy: resolveFilenamePolicy(options.sanitizeFilename)
325
- };
326
- const maxFileSize = options.maxFileSize ?? DEFAULT_MAX_FILE_SIZE;
327
- const allowedMimeTypes = options.allowedMimeTypes;
328
- const includeRoutes = {
329
- upload: options.includeRoutes?.upload ?? true,
330
- read: options.includeRoutes?.read ?? true,
331
- delete: options.includeRoutes?.delete ?? true
332
- };
333
- return {
334
- name: "filesUpload",
335
- routes: (permissions) => {
336
- const routes = [];
337
- if (includeRoutes.upload) routes.push({
338
- method: "POST",
339
- path: "/upload",
340
- operation: "filesUpload.upload",
341
- summary: "Upload a file",
342
- description: "Accepts a multipart/form-data request and persists the bytes via the configured Storage adapter.",
343
- permissions: options.permissions?.upload ?? permissions.create ?? requireAuth(),
344
- preHandler: [multipartBody({
345
- maxFileSize,
346
- allowedMimeTypes,
347
- requiredFields: [deps.fieldName]
348
- })],
349
- raw: true,
350
- handler: makeUploadHandler(deps)
351
- });
352
- if (includeRoutes.read) routes.push({
353
- method: "GET",
354
- path: "/:id",
355
- operation: "filesUpload.read",
356
- summary: "Download a file",
357
- description: "Streams the stored bytes. Supports single-range `Range: bytes=start-end`.",
358
- permissions: options.permissions?.read ?? permissions.get ?? allowPublic(),
359
- raw: true,
360
- handler: makeReadHandler(deps),
361
- mcp: false
362
- });
363
- if (includeRoutes.delete) routes.push({
364
- method: "DELETE",
365
- path: "/:id",
366
- operation: "filesUpload.delete",
367
- summary: "Delete a file",
368
- permissions: options.permissions?.delete ?? permissions.delete ?? requireAuth(),
369
- raw: true,
370
- handler: makeDeleteHandler(deps)
371
- });
372
- return routes;
373
- }
374
- };
375
- }
376
- //#endregion
377
- export { filesUploadPreset as t };
@@ -1,54 +0,0 @@
1
- //#region src/cache/interface.d.ts
2
- /**
3
- * Generic Cache Store Interface
4
- *
5
- * Shared contract for reusable cache backends (memory, Redis, etc.).
6
- * Used by runtime systems such as dynamic permission matrices and QueryCache.
7
- */
8
- interface CacheLogger {
9
- warn(message: string, ...args: unknown[]): void;
10
- error(message: string, ...args: unknown[]): void;
11
- }
12
- interface CacheSetOptions {
13
- /** Time-to-live in milliseconds */
14
- ttlMs?: number;
15
- }
16
- interface CacheStats {
17
- /** Number of entries currently stored */
18
- entries: number;
19
- /** Estimated memory usage in bytes (-1 if unavailable) */
20
- memoryBytes: number;
21
- /** Cache hit count since creation */
22
- hits: number;
23
- /** Cache miss count since creation */
24
- misses: number;
25
- /** Number of entries evicted since creation */
26
- evictions: number;
27
- }
28
- interface CacheStore<TValue = unknown> {
29
- /** Store name for logs/diagnostics */
30
- readonly name: string;
31
- /**
32
- * Get cached value by key.
33
- * Returns undefined when missing or expired.
34
- */
35
- get(key: string): Promise<TValue | undefined>;
36
- /**
37
- * Set a cache value.
38
- * Store implementation handles TTL and eviction policy.
39
- */
40
- set(key: string, value: TValue, options?: CacheSetOptions): Promise<void>;
41
- /**
42
- * Delete a single cache key.
43
- */
44
- delete(key: string): Promise<void>;
45
- /**
46
- * Clear all keys in this store namespace.
47
- * Optional because distributed stores may not support cheap global clear.
48
- */
49
- clear?(): Promise<void>;
50
- /** Cache statistics for observability. */
51
- stats?(): CacheStats;
52
- }
53
- //#endregion
54
- export { CacheStore as i, CacheSetOptions as n, CacheStats as r, CacheLogger as t };