@classytic/arc 2.10.3 → 2.11.0

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 (153) hide show
  1. package/README.md +1 -1
  2. package/dist/{BaseController-CbKKIflT.mjs → BaseController-JNV08qOT.mjs} +595 -537
  3. package/dist/{queryCachePlugin-BKbWjgDG.d.mts → QueryCache-DOBNHBE0.d.mts} +2 -32
  4. package/dist/actionPermissions-C8YYU92K.mjs +22 -0
  5. package/dist/adapters/index.d.mts +2 -2
  6. package/dist/adapters/index.mjs +1 -1
  7. package/dist/{adapters-BXY4i-hw.mjs → adapters-D0tT2Tyo.mjs} +54 -0
  8. package/dist/audit/index.d.mts +2 -2
  9. package/dist/audit/index.mjs +15 -17
  10. package/dist/auth/index.d.mts +4 -4
  11. package/dist/auth/index.mjs +3 -3
  12. package/dist/auth/redis-session.d.mts +1 -1
  13. package/dist/{betterAuthOpenApi-BBRVhjQN.mjs → betterAuthOpenApi-DwxtK3uG.mjs} +1 -1
  14. package/dist/cache/index.d.mts +3 -2
  15. package/dist/cache/index.mjs +3 -3
  16. package/dist/cli/commands/docs.mjs +2 -2
  17. package/dist/cli/commands/generate.mjs +37 -27
  18. package/dist/cli/commands/init.mjs +47 -34
  19. package/dist/cli/commands/introspect.mjs +1 -1
  20. package/dist/context/index.d.mts +58 -0
  21. package/dist/context/index.mjs +2 -0
  22. package/dist/core/index.d.mts +3 -3
  23. package/dist/core/index.mjs +4 -3
  24. package/dist/core-DXdSSFW-.mjs +1037 -0
  25. package/dist/createActionRouter-BwaSM0No.mjs +166 -0
  26. package/dist/{createApp-BuvPma24.mjs → createApp-DvNYEhpb.mjs} +118 -36
  27. package/dist/docs/index.d.mts +2 -2
  28. package/dist/docs/index.mjs +1 -1
  29. package/dist/{elevation-C7hgL_aI.mjs → elevation-DOFoxoDs.mjs} +1 -1
  30. package/dist/errorHandler-Co3lnVmJ.d.mts +114 -0
  31. package/dist/{eventPlugin-DCUjuiQT.mjs → eventPlugin--5HIkdPU.mjs} +1 -1
  32. package/dist/{eventPlugin-CxWgpd6K.d.mts → eventPlugin-CUNjYYRY.d.mts} +1 -1
  33. package/dist/events/index.d.mts +4 -4
  34. package/dist/events/index.mjs +69 -51
  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 +2 -2
  39. package/dist/{fields-Lo1VUDpt.d.mts → fields-C8Y0XLAu.d.mts} +1 -1
  40. package/dist/hooks/index.d.mts +1 -1
  41. package/dist/hooks/index.mjs +1 -1
  42. package/dist/idempotency/index.d.mts +3 -3
  43. package/dist/idempotency/index.mjs +38 -27
  44. package/dist/idempotency/redis.d.mts +1 -1
  45. package/dist/{index-ChIw3776.d.mts → index-BYCqHCVu.d.mts} +4 -4
  46. package/dist/{index-Cl0uoKd5.d.mts → index-Cm0vUrr_.d.mts} +2100 -1688
  47. package/dist/{index-DStwgFUK.d.mts → index-DAushRTt.d.mts} +29 -10
  48. package/dist/index-DsJ1MNfC.d.mts +1179 -0
  49. package/dist/{index-8qw4y6ff.d.mts → index-t8pLpPFW.d.mts} +13 -10
  50. package/dist/index.d.mts +7 -251
  51. package/dist/index.mjs +8 -128
  52. package/dist/integrations/event-gateway.d.mts +2 -2
  53. package/dist/integrations/event-gateway.mjs +1 -1
  54. package/dist/integrations/index.d.mts +2 -2
  55. package/dist/integrations/mcp/index.d.mts +2 -2
  56. package/dist/integrations/mcp/index.mjs +1 -1
  57. package/dist/integrations/mcp/testing.d.mts +1 -1
  58. package/dist/integrations/mcp/testing.mjs +1 -1
  59. package/dist/integrations/streamline.d.mts +46 -5
  60. package/dist/integrations/streamline.mjs +50 -21
  61. package/dist/integrations/websocket-redis.d.mts +1 -1
  62. package/dist/integrations/websocket.d.mts +2 -154
  63. package/dist/integrations/websocket.mjs +292 -224
  64. package/dist/{keys-qcD-TVJl.mjs → keys-CARyUjiR.mjs} +2 -0
  65. package/dist/{loadResources-BAzJItAJ.mjs → loadResources-YNwKHvRA.mjs} +3 -1
  66. package/dist/logger/index.d.mts +81 -0
  67. package/dist/{logger-DLg8-Ueg.mjs → logger/index.mjs} +1 -6
  68. package/dist/middleware/index.d.mts +109 -0
  69. package/dist/middleware/index.mjs +70 -0
  70. package/dist/multipartBody-CvTR1Un6.mjs +123 -0
  71. package/dist/{openapi-B5F8AddX.mjs → openapi-C0L9ar7m.mjs} +9 -7
  72. package/dist/org/index.d.mts +2 -2
  73. package/dist/permissions/index.d.mts +2 -2
  74. package/dist/permissions/index.mjs +1 -3
  75. package/dist/{permissions-Dk6mshja.mjs → permissions-B4vU9L0Q.mjs} +220 -2
  76. package/dist/pipe-DVoIheVC.mjs +62 -0
  77. package/dist/pipeline/index.d.mts +62 -0
  78. package/dist/pipeline/index.mjs +53 -0
  79. package/dist/plugins/index.d.mts +25 -5
  80. package/dist/plugins/index.mjs +10 -10
  81. package/dist/plugins/response-cache.mjs +1 -1
  82. package/dist/plugins/tracing-entry.d.mts +1 -1
  83. package/dist/plugins/tracing-entry.mjs +42 -24
  84. package/dist/presets/filesUpload.d.mts +4 -4
  85. package/dist/presets/filesUpload.mjs +255 -1
  86. package/dist/presets/index.d.mts +1 -1
  87. package/dist/presets/index.mjs +2 -2
  88. package/dist/presets/multiTenant.d.mts +1 -1
  89. package/dist/presets/multiTenant.mjs +48 -8
  90. package/dist/presets/search.d.mts +2 -2
  91. package/dist/presets/search.mjs +1 -1
  92. package/dist/{presets-fLJVXdVn.mjs → presets-k604Lj99.mjs} +1 -1
  93. package/dist/queryCachePlugin-BUXBSm4F.d.mts +34 -0
  94. package/dist/{queryCachePlugin-DQCEfJis.mjs → queryCachePlugin-Bq6bO6vc.mjs} +3 -3
  95. package/dist/{redis-DqyeggCa.d.mts → redis-Cm1gnRDf.d.mts} +1 -1
  96. package/dist/{redis-stream-CakIQmwR.d.mts → redis-stream-CM8TXTix.d.mts} +1 -1
  97. package/dist/registry/index.d.mts +1 -1
  98. package/dist/registry/index.mjs +2 -2
  99. package/dist/{requestContext-xHIKedG6.mjs → requestContext-CfRkaxwf.mjs} +1 -1
  100. package/dist/{resourceToTools-BElv3xPT.mjs → resourceToTools--okX6QBr.mjs} +534 -415
  101. package/dist/routerShared-DeESFp4a.mjs +515 -0
  102. package/dist/schemaIR-BlG9bY7v.mjs +137 -0
  103. package/dist/scope/index.d.mts +2 -2
  104. package/dist/scope/index.mjs +1 -1
  105. package/dist/{sse-yBCgOLGu.mjs → sse-V7aXc3bW.mjs} +1 -1
  106. package/dist/{store-helpers-ZCSMJJAX.mjs → store-helpers-BhrzxvyQ.mjs} +4 -0
  107. package/dist/testing/index.d.mts +367 -711
  108. package/dist/testing/index.mjs +646 -1434
  109. package/dist/testing/storageContract.d.mts +1 -1
  110. package/dist/{tracing-65B51Dw3.d.mts → tracing-DokiEsuz.d.mts} +9 -4
  111. package/dist/types/index.d.mts +5 -5
  112. package/dist/types/index.mjs +1 -3
  113. package/dist/types/storage.d.mts +1 -1
  114. package/dist/{types-Co8k3NyS.d.mts → types-CgikqKAj.d.mts} +133 -21
  115. package/dist/{types-Btdda02s.d.mts → types-D9NqiYIw.d.mts} +1 -1
  116. package/dist/utils/index.d.mts +2 -898
  117. package/dist/utils/index.mjs +4 -5
  118. package/dist/utils-D3Yxnrwr.mjs +1639 -0
  119. package/dist/versioning-M9lNLhO8.d.mts +117 -0
  120. package/dist/websocket-CyJ1VIFI.d.mts +186 -0
  121. package/package.json +26 -8
  122. package/skills/arc/SKILL.md +124 -39
  123. package/skills/arc/references/testing.md +212 -183
  124. package/dist/applyPermissionResult-QhV1Pa-g.mjs +0 -37
  125. package/dist/core-CcR01lup.mjs +0 -1411
  126. package/dist/createActionRouter-Bp_5c_2b.mjs +0 -249
  127. package/dist/errorHandler-DRQ3EqfL.d.mts +0 -218
  128. package/dist/errors-CCSsMpXE.d.mts +0 -140
  129. package/dist/fields-bxkeltzz.mjs +0 -126
  130. package/dist/filesUpload-t21LS-py.mjs +0 -377
  131. package/dist/queryParser-DBqBB6AC.mjs +0 -352
  132. package/dist/types-Csi3FLfq.mjs +0 -27
  133. package/dist/utils-B2fNOD_i.mjs +0 -929
  134. /package/dist/{EventTransport-CUw5NNWe.d.mts → EventTransport-CfVEGaEl.d.mts} +0 -0
  135. /package/dist/{HookSystem-BNYKnrXF.mjs → HookSystem-CGsMd6oK.mjs} +0 -0
  136. /package/dist/{ResourceRegistry-BPd6NQDm.mjs → ResourceRegistry-DkAeAuTX.mjs} +0 -0
  137. /package/dist/{caching-CBpK_SCM.mjs → caching-CheW3m-S.mjs} +0 -0
  138. /package/dist/{elevation-C5SwtkAn.d.mts → elevation-s5ykdNHr.d.mts} +0 -0
  139. /package/dist/{errorHandler-Bb49BvPD.mjs → errorHandler-BQm8ZxTK.mjs} +0 -0
  140. /package/dist/{externalPaths-BQ8QijNH.d.mts → externalPaths-Bapitwvd.d.mts} +0 -0
  141. /package/dist/{interface-CSbZdv_3.d.mts → interface-CkkWm5uR.d.mts} +0 -0
  142. /package/dist/{interface-D218ikEo.d.mts → interface-Da0r7Lna.d.mts} +0 -0
  143. /package/dist/{memory-B5Amv9A1.mjs → memory-DikHSvWa.mjs} +0 -0
  144. /package/dist/{metrics-DuhiSEZI.mjs → metrics-Csh4nsvv.mjs} +0 -0
  145. /package/dist/{pluralize-A0tWEl1K.mjs → pluralize-BneOJkpi.mjs} +0 -0
  146. /package/dist/{registry-B3lRFBWo.mjs → registry-D63ee7fl.mjs} +0 -0
  147. /package/dist/{replyHelpers-CXtJDAZ0.mjs → replyHelpers-ByllIXXV.mjs} +0 -0
  148. /package/dist/{schemaConverter-BxFDdtXu.mjs → schemaConverter-B0oKLuqI.mjs} +0 -0
  149. /package/dist/{sessionManager-BkzVU8h2.d.mts → sessionManager-D-oNWHz3.d.mts} +0 -0
  150. /package/dist/{storage-CVk_SEn2.d.mts → storage-BwGQXUpd.d.mts} +0 -0
  151. /package/dist/{typeGuards-Cj5Rgvlg.mjs → typeGuards-CcFZXgU7.mjs} +0 -0
  152. /package/dist/{types-BD85MlEK.d.mts → types-tgR4Pt8F.d.mts} +0 -0
  153. /package/dist/{versioning-C2U_bLY0.mjs → versioning-CGPjkqAg.mjs} +0 -0
@@ -1,352 +0,0 @@
1
- import { m as RESERVED_QUERY_PARAMS } from "./constants-BhY1OHoH.mjs";
2
- //#region src/utils/queryParser.ts
3
- /**
4
- * Arc Query Parser - Default URL-to-Query Parser
5
- *
6
- * Framework-agnostic query parser that converts URL parameters to query options.
7
- * This is Arc's built-in parser; users can swap in MongoKit's QueryParser,
8
- * pgkit's parser, or any custom parser implementing QueryParserInterface.
9
- *
10
- * @example
11
- * // Use Arc default parser (auto-applied if no queryParser option)
12
- * defineResource({ name: 'product', adapter: ... });
13
- *
14
- * // Use MongoKit's QueryParser (recommended for MongoDB - has $lookup, aggregations, etc.)
15
- * import { QueryParser } from '@classytic/mongokit';
16
- * defineResource({
17
- * name: 'product',
18
- * adapter: ...,
19
- * queryParser: new QueryParser(),
20
- * });
21
- *
22
- * // Use custom parser for SQL databases
23
- * defineResource({
24
- * name: 'user',
25
- * adapter: ...,
26
- * queryParser: new PgQueryParser(),
27
- * });
28
- */
29
- /**
30
- * Regex patterns that can cause catastrophic backtracking (ReDoS attacks)
31
- * Detects:
32
- * - Quantifiers: {n,m}
33
- * - Possessive quantifiers: *+, ++, ?+
34
- * - Nested quantifiers: (a+)+, (a*)*
35
- * - Backreferences: \1, \2, etc.
36
- */
37
- const DANGEROUS_REGEX_PATTERNS = /(\{[0-9,]+\}|\*\+|\+\+|\?\+|(\(.+\))\+|\(\?:|\\[0-9]|(\[.+\]).+(\[.+\]))/;
38
- /**
39
- * Arc's default query parser
40
- *
41
- * Converts URL query parameters to a structured query format:
42
- * - Pagination: ?page=1&limit=20
43
- * - Sorting: ?sort=-createdAt,name (- prefix = descending)
44
- * - Filtering: ?status=active&price[gte]=100&price[lte]=500
45
- * - Search: ?search=keyword
46
- * - Populate: ?populate=author,category
47
- * - Field selection: ?select=name,price,status
48
- * - Keyset pagination: ?after=cursor_value
49
- *
50
- * For advanced MongoDB features ($lookup, aggregations), use MongoKit's QueryParser.
51
- */
52
- var ArcQueryParser = class {
53
- maxLimit;
54
- defaultLimit;
55
- maxRegexLength;
56
- maxSearchLength;
57
- maxFilterDepth;
58
- _allowedFilterFields;
59
- _allowedSortFields;
60
- _allowedOperators;
61
- /** Allowed filter fields (used by MCP for auto-derive) */
62
- allowedFilterFields;
63
- /** Allowed sort fields (used by MCP for sort descriptions) */
64
- allowedSortFields;
65
- /** Allowed operators (used by MCP for operator descriptions) */
66
- allowedOperators;
67
- /** Supported filter operators */
68
- operators = {
69
- eq: "$eq",
70
- ne: "$ne",
71
- gt: "$gt",
72
- gte: "$gte",
73
- lt: "$lt",
74
- lte: "$lte",
75
- in: "$in",
76
- nin: "$nin",
77
- like: "$regex",
78
- contains: "$regex",
79
- regex: "$regex",
80
- exists: "$exists"
81
- };
82
- constructor(options = {}) {
83
- this.maxLimit = options.maxLimit ?? 1e3;
84
- this.defaultLimit = options.defaultLimit ?? 20;
85
- this.maxRegexLength = options.maxRegexLength ?? 200;
86
- this.maxSearchLength = options.maxSearchLength ?? 200;
87
- this.maxFilterDepth = options.maxFilterDepth ?? 10;
88
- if (options.allowedFilterFields) {
89
- this._allowedFilterFields = new Set(options.allowedFilterFields);
90
- this.allowedFilterFields = options.allowedFilterFields;
91
- }
92
- if (options.allowedSortFields) {
93
- this._allowedSortFields = new Set(options.allowedSortFields);
94
- this.allowedSortFields = options.allowedSortFields;
95
- }
96
- if (options.allowedOperators) {
97
- this._allowedOperators = new Set(options.allowedOperators);
98
- this.allowedOperators = options.allowedOperators;
99
- }
100
- }
101
- /**
102
- * Parse URL query parameters into structured query options
103
- */
104
- parse(query) {
105
- const q = query ?? {};
106
- const page = this.parseNumber(q.page, 1);
107
- const limit = Math.min(this.parseNumber(q.limit, this.defaultLimit), this.maxLimit);
108
- const after = this.parseString(q.after ?? q.cursor);
109
- const sort = this.parseSort(q.sort);
110
- const { populate, populateOptions } = this.parsePopulate(q.populate);
111
- const search = this.parseSearch(q.search);
112
- const select = this.parseSelect(q.select);
113
- return {
114
- filters: this.parseFilters(q),
115
- limit,
116
- sort,
117
- populate,
118
- populateOptions,
119
- search,
120
- page: after ? void 0 : page,
121
- after,
122
- select
123
- };
124
- }
125
- parseNumber(value, defaultValue) {
126
- if (value === void 0 || value === null) return defaultValue;
127
- const num = parseInt(String(value), 10);
128
- return Number.isNaN(num) ? defaultValue : Math.max(1, num);
129
- }
130
- parseString(value) {
131
- if (value === void 0 || value === null) return void 0;
132
- const str = String(value).trim();
133
- return str.length > 0 ? str : void 0;
134
- }
135
- /**
136
- * Parse populate parameter — handles both simple string and bracket notation.
137
- *
138
- * Simple: ?populate=author,category → { populate: 'author,category' }
139
- * Bracket: ?populate[author][select]=name,email → { populateOptions: [{ path: 'author', select: 'name email' }] }
140
- */
141
- parsePopulate(value) {
142
- if (value === void 0 || value === null) return {};
143
- if (typeof value === "string") {
144
- const trimmed = value.trim();
145
- return trimmed.length > 0 ? { populate: trimmed } : {};
146
- }
147
- if (typeof value === "object" && !Array.isArray(value)) {
148
- const obj = value;
149
- const keys = Object.keys(obj);
150
- if (keys.length === 0) return {};
151
- const options = [];
152
- for (const path of keys) {
153
- if (!/^[a-zA-Z_][a-zA-Z0-9_.]*$/.test(path)) continue;
154
- const config = obj[path];
155
- if (typeof config === "object" && config !== null && !Array.isArray(config)) {
156
- const cfg = config;
157
- const option = { path };
158
- if (typeof cfg.select === "string") option.select = cfg.select.split(",").map((s) => s.trim()).filter(Boolean).join(" ");
159
- if (typeof cfg.match === "object" && cfg.match !== null) option.match = cfg.match;
160
- options.push(option);
161
- } else options.push({ path });
162
- }
163
- return options.length > 0 ? { populateOptions: options } : {};
164
- }
165
- return {};
166
- }
167
- parseSort(value) {
168
- if (!value) return void 0;
169
- const sortStr = String(value);
170
- const result = {};
171
- for (const field of sortStr.split(",")) {
172
- const trimmed = field.trim();
173
- if (!trimmed) continue;
174
- if (!/^-?[a-zA-Z_][a-zA-Z0-9_.]*$/.test(trimmed)) continue;
175
- const fieldName = trimmed.startsWith("-") ? trimmed.slice(1) : trimmed;
176
- if (this._allowedSortFields && !this._allowedSortFields.has(fieldName)) continue;
177
- if (trimmed.startsWith("-")) result[fieldName] = -1;
178
- else result[fieldName] = 1;
179
- }
180
- return Object.keys(result).length > 0 ? result : void 0;
181
- }
182
- parseSearch(value) {
183
- if (!value) return void 0;
184
- const search = String(value).trim();
185
- if (search.length === 0) return void 0;
186
- if (search.length > this.maxSearchLength) return search.slice(0, this.maxSearchLength);
187
- return search;
188
- }
189
- parseSelect(value) {
190
- if (!value) return void 0;
191
- const selectStr = String(value);
192
- const result = {};
193
- for (const field of selectStr.split(",")) {
194
- const trimmed = field.trim();
195
- if (!trimmed) continue;
196
- if (!/^-?[a-zA-Z_][a-zA-Z0-9_.]*$/.test(trimmed)) continue;
197
- if (trimmed.startsWith("-")) result[trimmed.slice(1)] = 0;
198
- else result[trimmed] = 1;
199
- }
200
- return Object.keys(result).length > 0 ? result : void 0;
201
- }
202
- /**
203
- * Check if a value exceeds the maximum nesting depth.
204
- * Prevents filter bombs where deeply nested objects consume excessive memory/CPU.
205
- */
206
- exceedsDepth(obj, currentDepth = 0) {
207
- if (currentDepth > this.maxFilterDepth) return true;
208
- if (obj === null || obj === void 0) return false;
209
- if (Array.isArray(obj)) return obj.some((v) => this.exceedsDepth(v, currentDepth));
210
- if (typeof obj !== "object") return false;
211
- return Object.values(obj).some((v) => this.exceedsDepth(v, currentDepth + 1));
212
- }
213
- parseFilters(query) {
214
- const filters = {};
215
- for (const [key, value] of Object.entries(query)) {
216
- if (RESERVED_QUERY_PARAMS.has(key)) continue;
217
- if (value === void 0 || value === null) continue;
218
- if (!/^[a-zA-Z_][a-zA-Z0-9_.]*$/.test(key)) continue;
219
- if (this._allowedFilterFields && !this._allowedFilterFields.has(key)) continue;
220
- if (this.exceedsDepth(value)) continue;
221
- if (typeof value === "object" && value !== null && !Array.isArray(value)) {
222
- const operatorObj = value;
223
- const operatorKeys = Object.keys(operatorObj);
224
- const allOperators = operatorKeys.every((op) => this.operators[op] && (!this._allowedOperators || this._allowedOperators.has(op)));
225
- const allKnownOperators = operatorKeys.every((op) => this.operators[op]);
226
- if (allOperators && operatorKeys.length > 0) {
227
- const mongoFilters = {};
228
- for (const [op, opValue] of Object.entries(operatorObj)) {
229
- const mongoOp = this.operators[op];
230
- if (mongoOp) mongoFilters[mongoOp] = this.parseFilterValue(opValue, op);
231
- }
232
- filters[key] = mongoFilters;
233
- continue;
234
- }
235
- if (allKnownOperators && this._allowedOperators) continue;
236
- }
237
- const match = key.match(/^([a-zA-Z_][a-zA-Z0-9_.]*)(?:\[([a-z]+)\])?$/);
238
- if (!match) continue;
239
- const [, fieldName, operator] = match;
240
- if (!fieldName) continue;
241
- if (operator && this.operators[operator] && (!this._allowedOperators || this._allowedOperators.has(operator))) {
242
- const mongoOp = this.operators[operator];
243
- const parsedValue = this.parseFilterValue(value, operator);
244
- if (!filters[fieldName]) filters[fieldName] = {};
245
- filters[fieldName][mongoOp] = parsedValue;
246
- } else if (!operator) filters[fieldName] = this.parseFilterValue(value);
247
- }
248
- return filters;
249
- }
250
- parseFilterValue(value, operator) {
251
- if (operator === "in" || operator === "nin") {
252
- if (Array.isArray(value)) return value.map((v) => this.coerceValue(v));
253
- if (typeof value === "string" && value.includes(",")) return value.split(",").map((v) => this.coerceValue(v.trim()));
254
- return [this.coerceValue(value)];
255
- }
256
- if (operator === "like" || operator === "contains" || operator === "regex") return this.sanitizeRegex(String(value));
257
- if (operator === "exists") {
258
- const str = String(value).toLowerCase();
259
- return str === "true" || str === "1";
260
- }
261
- return this.coerceValue(value);
262
- }
263
- coerceValue(value) {
264
- if (value === "true") return true;
265
- if (value === "false") return false;
266
- if (value === "null") return null;
267
- if (typeof value === "string") {
268
- const num = Number(value);
269
- if (!Number.isNaN(num) && value.trim() !== "") return num;
270
- }
271
- return value;
272
- }
273
- /**
274
- * Generate OpenAPI-compatible JSON Schema for query parameters.
275
- * Arc's defineResource() auto-detects this method and uses it
276
- * to document list endpoint query parameters in OpenAPI/Swagger.
277
- */
278
- getQuerySchema() {
279
- const operatorLines = Object.entries(this.operators).map(([op, mongoOp]) => {
280
- return ` ${op} → ${mongoOp}: ${{
281
- eq: "Equal (default when no operator specified)",
282
- ne: "Not equal",
283
- gt: "Greater than",
284
- gte: "Greater than or equal",
285
- lt: "Less than",
286
- lte: "Less than or equal",
287
- in: "In list (comma-separated values)",
288
- nin: "Not in list",
289
- like: "Pattern match (case-insensitive)",
290
- contains: "Contains substring (case-insensitive)",
291
- regex: "Regex pattern",
292
- exists: "Field exists (true/false)"
293
- }[op] || op}`;
294
- });
295
- return {
296
- type: "object",
297
- properties: {
298
- page: {
299
- type: "integer",
300
- description: "Page number for offset pagination",
301
- default: 1,
302
- minimum: 1
303
- },
304
- limit: {
305
- type: "integer",
306
- description: "Number of items per page",
307
- default: this.defaultLimit,
308
- minimum: 1,
309
- maximum: this.maxLimit
310
- },
311
- sort: {
312
- type: "string",
313
- description: "Sort fields (comma-separated). Prefix with - for descending. Example: -createdAt,name"
314
- },
315
- search: {
316
- type: "string",
317
- description: "Full-text search query",
318
- maxLength: this.maxSearchLength
319
- },
320
- select: {
321
- type: "string",
322
- description: "Fields to include/exclude (comma-separated). Prefix with - to exclude. Example: name,email,-password"
323
- },
324
- populate: {
325
- type: "string",
326
- description: "Fields to populate/join (comma-separated). Example: author,category"
327
- },
328
- after: {
329
- type: "string",
330
- description: "Cursor value for keyset pagination"
331
- },
332
- _filterOperators: {
333
- type: "string",
334
- description: ["Available filter operators (use as field[operator]=value):", ...operatorLines].join("\n")
335
- }
336
- }
337
- };
338
- }
339
- sanitizeRegex(pattern) {
340
- let sanitized = pattern.slice(0, this.maxRegexLength);
341
- if (DANGEROUS_REGEX_PATTERNS.test(sanitized)) sanitized = sanitized.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
342
- return sanitized;
343
- }
344
- };
345
- /**
346
- * Create a new ArcQueryParser instance
347
- */
348
- function createQueryParser(options) {
349
- return new ArcQueryParser(options);
350
- }
351
- //#endregion
352
- export { createQueryParser as n, ArcQueryParser as t };
@@ -1,27 +0,0 @@
1
- //#region src/types/base.ts
2
- /** Extract user ID from a user object (supports both id and _id). */
3
- function getUserId(user) {
4
- if (!user) return void 0;
5
- const id = user.id ?? user._id;
6
- return id ? String(id) : void 0;
7
- }
8
- /**
9
- * Wrap data in Arc's standard `{ success: true, data }` envelope.
10
- *
11
- * @example
12
- * ```typescript
13
- * handler: async (req, reply) => {
14
- * const data = await getResults();
15
- * return envelope(data); // → { success: true, data }
16
- * }
17
- * ```
18
- */
19
- function envelope(data, meta) {
20
- return {
21
- success: true,
22
- data,
23
- ...meta
24
- };
25
- }
26
- //#endregion
27
- export { getUserId as n, envelope as t };