@classytic/arc 1.1.0 → 2.1.3

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 (200) hide show
  1. package/README.md +247 -794
  2. package/bin/arc.js +91 -52
  3. package/dist/EventTransport-BkUDYZEb.d.mts +99 -0
  4. package/dist/HookSystem-BsGV-j2l.mjs +404 -0
  5. package/dist/ResourceRegistry-7Ic20ZMw.mjs +249 -0
  6. package/dist/adapters/index.d.mts +5 -0
  7. package/dist/adapters/index.mjs +3 -0
  8. package/dist/audit/index.d.mts +81 -0
  9. package/dist/audit/index.mjs +275 -0
  10. package/dist/audit/mongodb.d.mts +5 -0
  11. package/dist/audit/mongodb.mjs +3 -0
  12. package/dist/audited-CGdLiSlE.mjs +140 -0
  13. package/dist/auth/index.d.mts +188 -0
  14. package/dist/auth/index.mjs +1096 -0
  15. package/dist/auth/redis-session.d.mts +43 -0
  16. package/dist/auth/redis-session.mjs +75 -0
  17. package/dist/betterAuthOpenApi-DjWDddNc.mjs +249 -0
  18. package/dist/cache/index.d.mts +145 -0
  19. package/dist/cache/index.mjs +91 -0
  20. package/dist/caching-GSDJcA6-.mjs +93 -0
  21. package/dist/chunk-C7Uep-_p.mjs +20 -0
  22. package/dist/circuitBreaker-DYhWBW_D.mjs +1096 -0
  23. package/dist/cli/commands/describe.d.mts +18 -0
  24. package/dist/cli/commands/describe.mjs +238 -0
  25. package/dist/cli/commands/docs.d.mts +13 -0
  26. package/dist/cli/commands/docs.mjs +52 -0
  27. package/dist/cli/commands/{generate.d.ts → generate.d.mts} +3 -2
  28. package/dist/cli/commands/generate.mjs +357 -0
  29. package/dist/cli/commands/{init.d.ts → init.d.mts} +11 -8
  30. package/dist/cli/commands/{init.js → init.mjs} +807 -617
  31. package/dist/cli/commands/introspect.d.mts +10 -0
  32. package/dist/cli/commands/introspect.mjs +75 -0
  33. package/dist/cli/index.d.mts +16 -0
  34. package/dist/cli/index.mjs +156 -0
  35. package/dist/constants-DdXFXQtN.mjs +84 -0
  36. package/dist/core/index.d.mts +5 -0
  37. package/dist/core/index.mjs +4 -0
  38. package/dist/createApp-D2D5XXaV.mjs +559 -0
  39. package/dist/defineResource-PXzSJ15_.mjs +2197 -0
  40. package/dist/discovery/index.d.mts +46 -0
  41. package/dist/discovery/index.mjs +109 -0
  42. package/dist/docs/index.d.mts +162 -0
  43. package/dist/docs/index.mjs +74 -0
  44. package/dist/elevation-DGo5shaX.d.mts +87 -0
  45. package/dist/elevation-DSTbVvYj.mjs +113 -0
  46. package/dist/errorHandler-C3GY3_ow.mjs +108 -0
  47. package/dist/errorHandler-CW3OOeYq.d.mts +72 -0
  48. package/dist/errors-DAWRdiYP.d.mts +124 -0
  49. package/dist/errors-DBANPbGr.mjs +211 -0
  50. package/dist/eventPlugin-BEOvaDqo.mjs +229 -0
  51. package/dist/eventPlugin-H6wDDjGO.d.mts +124 -0
  52. package/dist/events/index.d.mts +53 -0
  53. package/dist/events/index.mjs +51 -0
  54. package/dist/events/transports/redis-stream-entry.d.mts +2 -0
  55. package/dist/events/transports/redis-stream-entry.mjs +177 -0
  56. package/dist/events/transports/redis.d.mts +76 -0
  57. package/dist/events/transports/redis.mjs +124 -0
  58. package/dist/externalPaths-SyPF2tgK.d.mts +50 -0
  59. package/dist/factory/index.d.mts +63 -0
  60. package/dist/factory/index.mjs +3 -0
  61. package/dist/fastifyAdapter-C8DlE0YH.d.mts +216 -0
  62. package/dist/fields-Bi_AVKSo.d.mts +109 -0
  63. package/dist/fields-CTd_CrKr.mjs +114 -0
  64. package/dist/hooks/index.d.mts +4 -0
  65. package/dist/hooks/index.mjs +3 -0
  66. package/dist/idempotency/index.d.mts +96 -0
  67. package/dist/idempotency/index.mjs +319 -0
  68. package/dist/idempotency/mongodb.d.mts +2 -0
  69. package/dist/idempotency/mongodb.mjs +114 -0
  70. package/dist/idempotency/redis.d.mts +2 -0
  71. package/dist/idempotency/redis.mjs +103 -0
  72. package/dist/index.d.mts +260 -0
  73. package/dist/index.mjs +104 -0
  74. package/dist/integrations/event-gateway.d.mts +46 -0
  75. package/dist/integrations/event-gateway.mjs +43 -0
  76. package/dist/integrations/index.d.mts +5 -0
  77. package/dist/integrations/index.mjs +1 -0
  78. package/dist/integrations/jobs.d.mts +103 -0
  79. package/dist/integrations/jobs.mjs +123 -0
  80. package/dist/integrations/streamline.d.mts +60 -0
  81. package/dist/integrations/streamline.mjs +125 -0
  82. package/dist/integrations/websocket.d.mts +82 -0
  83. package/dist/integrations/websocket.mjs +288 -0
  84. package/dist/interface-CSNjltAc.d.mts +77 -0
  85. package/dist/interface-DTbsvIWe.d.mts +54 -0
  86. package/dist/interface-e9XfSsUV.d.mts +1097 -0
  87. package/dist/introspectionPlugin-B3JkrjwU.mjs +53 -0
  88. package/dist/keys-DhqDRxv3.mjs +42 -0
  89. package/dist/logger-ByrvQWZO.mjs +78 -0
  90. package/dist/memory-B2v7KrCB.mjs +143 -0
  91. package/dist/migrations/index.d.mts +156 -0
  92. package/dist/migrations/index.mjs +260 -0
  93. package/dist/mongodb-ClykrfGo.d.mts +118 -0
  94. package/dist/mongodb-DNKEExbf.mjs +93 -0
  95. package/dist/mongodb-Dg8O_gvd.d.mts +71 -0
  96. package/dist/openapi-9nB_kiuR.mjs +525 -0
  97. package/dist/org/index.d.mts +68 -0
  98. package/dist/org/index.mjs +513 -0
  99. package/dist/org/types.d.mts +82 -0
  100. package/dist/org/types.mjs +1 -0
  101. package/dist/permissions/index.d.mts +278 -0
  102. package/dist/permissions/index.mjs +579 -0
  103. package/dist/plugins/index.d.mts +172 -0
  104. package/dist/plugins/index.mjs +522 -0
  105. package/dist/plugins/response-cache.d.mts +87 -0
  106. package/dist/plugins/response-cache.mjs +283 -0
  107. package/dist/plugins/tracing-entry.d.mts +2 -0
  108. package/dist/plugins/tracing-entry.mjs +185 -0
  109. package/dist/pluralize-CM-jZg7p.mjs +86 -0
  110. package/dist/policies/{index.d.ts → index.d.mts} +204 -170
  111. package/dist/policies/index.mjs +321 -0
  112. package/dist/presets/{index.d.ts → index.d.mts} +62 -131
  113. package/dist/presets/index.mjs +143 -0
  114. package/dist/presets/multiTenant.d.mts +24 -0
  115. package/dist/presets/multiTenant.mjs +113 -0
  116. package/dist/presets-BTeYbw7h.d.mts +57 -0
  117. package/dist/presets-CeFtfDR8.mjs +119 -0
  118. package/dist/prisma-C3iornoK.d.mts +274 -0
  119. package/dist/prisma-DJbMt3yf.mjs +627 -0
  120. package/dist/queryCachePlugin-B6R0d4av.mjs +138 -0
  121. package/dist/queryCachePlugin-Q6SYuHZ6.d.mts +71 -0
  122. package/dist/redis-UwjEp8Ea.d.mts +49 -0
  123. package/dist/redis-stream-CBg0upHI.d.mts +103 -0
  124. package/dist/registry/index.d.mts +11 -0
  125. package/dist/registry/index.mjs +4 -0
  126. package/dist/requestContext-xi6OKBL-.mjs +55 -0
  127. package/dist/schemaConverter-Dtg0Kt9T.mjs +98 -0
  128. package/dist/schemas/index.d.mts +63 -0
  129. package/dist/schemas/index.mjs +82 -0
  130. package/dist/scope/index.d.mts +21 -0
  131. package/dist/scope/index.mjs +65 -0
  132. package/dist/sessionManager-D_iEHjQl.d.mts +186 -0
  133. package/dist/sse-DkqQ1uxb.mjs +123 -0
  134. package/dist/testing/index.d.mts +907 -0
  135. package/dist/testing/index.mjs +1976 -0
  136. package/dist/tracing-8CEbhF0w.d.mts +70 -0
  137. package/dist/typeGuards-DwxA1t_L.mjs +9 -0
  138. package/dist/types/index.d.mts +946 -0
  139. package/dist/types/index.mjs +14 -0
  140. package/dist/types-B0dhNrnd.d.mts +445 -0
  141. package/dist/types-Beqn1Un7.mjs +38 -0
  142. package/dist/types-DelU6kln.mjs +25 -0
  143. package/dist/types-RLkFVgaw.d.mts +101 -0
  144. package/dist/utils/index.d.mts +747 -0
  145. package/dist/utils/index.mjs +6 -0
  146. package/package.json +194 -68
  147. package/dist/BaseController-DVAiHxEQ.d.ts +0 -233
  148. package/dist/adapters/index.d.ts +0 -237
  149. package/dist/adapters/index.js +0 -668
  150. package/dist/arcCorePlugin-CsShQdyP.d.ts +0 -273
  151. package/dist/audit/index.d.ts +0 -195
  152. package/dist/audit/index.js +0 -319
  153. package/dist/auth/index.d.ts +0 -47
  154. package/dist/auth/index.js +0 -174
  155. package/dist/cli/commands/docs.d.ts +0 -11
  156. package/dist/cli/commands/docs.js +0 -474
  157. package/dist/cli/commands/generate.js +0 -334
  158. package/dist/cli/commands/introspect.d.ts +0 -8
  159. package/dist/cli/commands/introspect.js +0 -338
  160. package/dist/cli/index.d.ts +0 -4
  161. package/dist/cli/index.js +0 -3269
  162. package/dist/core/index.d.ts +0 -220
  163. package/dist/core/index.js +0 -2786
  164. package/dist/createApp-Ce9wl8W9.d.ts +0 -77
  165. package/dist/docs/index.d.ts +0 -166
  166. package/dist/docs/index.js +0 -658
  167. package/dist/errors-8WIxGS_6.d.ts +0 -122
  168. package/dist/events/index.d.ts +0 -117
  169. package/dist/events/index.js +0 -89
  170. package/dist/factory/index.d.ts +0 -38
  171. package/dist/factory/index.js +0 -1652
  172. package/dist/hooks/index.d.ts +0 -4
  173. package/dist/hooks/index.js +0 -199
  174. package/dist/idempotency/index.d.ts +0 -323
  175. package/dist/idempotency/index.js +0 -500
  176. package/dist/index-B4t03KQ0.d.ts +0 -1366
  177. package/dist/index.d.ts +0 -135
  178. package/dist/index.js +0 -4756
  179. package/dist/migrations/index.d.ts +0 -185
  180. package/dist/migrations/index.js +0 -274
  181. package/dist/org/index.d.ts +0 -129
  182. package/dist/org/index.js +0 -220
  183. package/dist/permissions/index.d.ts +0 -144
  184. package/dist/permissions/index.js +0 -103
  185. package/dist/plugins/index.d.ts +0 -46
  186. package/dist/plugins/index.js +0 -1069
  187. package/dist/policies/index.js +0 -196
  188. package/dist/presets/index.js +0 -384
  189. package/dist/presets/multiTenant.d.ts +0 -39
  190. package/dist/presets/multiTenant.js +0 -112
  191. package/dist/registry/index.d.ts +0 -16
  192. package/dist/registry/index.js +0 -253
  193. package/dist/testing/index.d.ts +0 -618
  194. package/dist/testing/index.js +0 -48020
  195. package/dist/types/index.d.ts +0 -4
  196. package/dist/types/index.js +0 -8
  197. package/dist/types-B99TBmFV.d.ts +0 -76
  198. package/dist/types-BvckRbs2.d.ts +0 -143
  199. package/dist/utils/index.d.ts +0 -679
  200. package/dist/utils/index.js +0 -931
@@ -1,679 +0,0 @@
1
- export { A as ArcError, C as ConflictError, E as ErrorDetails, F as ForbiddenError, N as NotFoundError, a as OrgAccessDeniedError, O as OrgRequiredError, R as RateLimitError, S as ServiceUnavailableError, U as UnauthorizedError, V as ValidationError, c as createError, i as isArcError } from '../errors-8WIxGS_6.js';
2
- import { A as AnyRecord, Q as QueryParserInterface, ae as ParsedQuery } from '../index-B4t03KQ0.js';
3
- import 'mongoose';
4
- import 'fastify';
5
- import '../types-B99TBmFV.js';
6
-
7
- /**
8
- * Response Schemas
9
- *
10
- * Standard JSON Schema definitions for API responses.
11
- */
12
-
13
- interface JsonSchema {
14
- type: string;
15
- properties?: Record<string, JsonSchema | AnyRecord>;
16
- required?: string[];
17
- items?: JsonSchema | AnyRecord;
18
- additionalProperties?: boolean | JsonSchema;
19
- description?: string;
20
- example?: unknown;
21
- [key: string]: unknown;
22
- }
23
- /**
24
- * Base success response schema
25
- */
26
- declare const successResponseSchema: JsonSchema;
27
- /**
28
- * Error response schema
29
- */
30
- declare const errorResponseSchema: JsonSchema;
31
- /**
32
- * Pagination schema - matches MongoKit/Arc runtime format
33
- *
34
- * Runtime format (flat fields):
35
- * { page, limit, total, pages, hasNext, hasPrev }
36
- */
37
- declare const paginationSchema: JsonSchema;
38
- /**
39
- * Wrap a data schema in a success response
40
- */
41
- declare function wrapResponse(dataSchema: JsonSchema): JsonSchema;
42
- /**
43
- * Create a list response schema with pagination - matches MongoKit/Arc runtime format
44
- *
45
- * Runtime format:
46
- * { success, docs: [...], page, limit, total, pages, hasNext, hasPrev }
47
- *
48
- * Note: Uses 'docs' array (not 'data') with flat pagination fields
49
- */
50
- declare function listResponse(itemSchema: JsonSchema): JsonSchema;
51
- /**
52
- * Alias for listResponse - matches local responseSchemas.js naming
53
- */
54
- declare const paginateWrapper: typeof listResponse;
55
- /**
56
- * Create a single item response schema
57
- *
58
- * Runtime format: { success, data: {...} }
59
- */
60
- declare function itemResponse(itemSchema: JsonSchema): JsonSchema;
61
- /**
62
- * Alias for itemResponse - matches local responseSchemas.js naming
63
- */
64
- declare const itemWrapper: typeof itemResponse;
65
- /**
66
- * Create a create/update response schema
67
- */
68
- declare function mutationResponse(itemSchema: JsonSchema): JsonSchema;
69
- /**
70
- * Create a delete response schema
71
- *
72
- * Runtime format: { success, message }
73
- */
74
- declare function deleteResponse(): JsonSchema;
75
- /**
76
- * Alias for deleteResponse - matches local responseSchemas.js naming
77
- */
78
- declare const messageWrapper: typeof deleteResponse;
79
- declare const responses: {
80
- 200: (schema: JsonSchema) => {
81
- description: string;
82
- content: {
83
- 'application/json': {
84
- schema: JsonSchema;
85
- };
86
- };
87
- };
88
- 201: (schema: JsonSchema) => {
89
- description: string;
90
- content: {
91
- 'application/json': {
92
- schema: JsonSchema;
93
- };
94
- };
95
- };
96
- 400: {
97
- description: string;
98
- content: {
99
- 'application/json': {
100
- schema: {
101
- properties: {
102
- code: {
103
- type: string;
104
- example: string;
105
- };
106
- details: {
107
- type: string;
108
- properties: {
109
- errors: {
110
- type: string;
111
- items: {
112
- type: string;
113
- properties: {
114
- field: {
115
- type: string;
116
- };
117
- message: {
118
- type: string;
119
- };
120
- };
121
- };
122
- };
123
- };
124
- };
125
- };
126
- type: string;
127
- required?: string[];
128
- items?: JsonSchema | AnyRecord;
129
- additionalProperties?: boolean | JsonSchema;
130
- description?: string;
131
- example?: unknown;
132
- };
133
- };
134
- };
135
- };
136
- 401: {
137
- description: string;
138
- content: {
139
- 'application/json': {
140
- schema: {
141
- properties: {
142
- code: {
143
- type: string;
144
- example: string;
145
- };
146
- };
147
- type: string;
148
- required?: string[];
149
- items?: JsonSchema | AnyRecord;
150
- additionalProperties?: boolean | JsonSchema;
151
- description?: string;
152
- example?: unknown;
153
- };
154
- };
155
- };
156
- };
157
- 403: {
158
- description: string;
159
- content: {
160
- 'application/json': {
161
- schema: {
162
- properties: {
163
- code: {
164
- type: string;
165
- example: string;
166
- };
167
- };
168
- type: string;
169
- required?: string[];
170
- items?: JsonSchema | AnyRecord;
171
- additionalProperties?: boolean | JsonSchema;
172
- description?: string;
173
- example?: unknown;
174
- };
175
- };
176
- };
177
- };
178
- 404: {
179
- description: string;
180
- content: {
181
- 'application/json': {
182
- schema: {
183
- properties: {
184
- code: {
185
- type: string;
186
- example: string;
187
- };
188
- };
189
- type: string;
190
- required?: string[];
191
- items?: JsonSchema | AnyRecord;
192
- additionalProperties?: boolean | JsonSchema;
193
- description?: string;
194
- example?: unknown;
195
- };
196
- };
197
- };
198
- };
199
- 409: {
200
- description: string;
201
- content: {
202
- 'application/json': {
203
- schema: {
204
- properties: {
205
- code: {
206
- type: string;
207
- example: string;
208
- };
209
- };
210
- type: string;
211
- required?: string[];
212
- items?: JsonSchema | AnyRecord;
213
- additionalProperties?: boolean | JsonSchema;
214
- description?: string;
215
- example?: unknown;
216
- };
217
- };
218
- };
219
- };
220
- 500: {
221
- description: string;
222
- content: {
223
- 'application/json': {
224
- schema: {
225
- properties: {
226
- code: {
227
- type: string;
228
- example: string;
229
- };
230
- };
231
- type: string;
232
- required?: string[];
233
- items?: JsonSchema | AnyRecord;
234
- additionalProperties?: boolean | JsonSchema;
235
- description?: string;
236
- example?: unknown;
237
- };
238
- };
239
- };
240
- };
241
- };
242
- declare const queryParams: {
243
- pagination: {
244
- page: {
245
- type: string;
246
- minimum: number;
247
- default: number;
248
- description: string;
249
- };
250
- limit: {
251
- type: string;
252
- minimum: number;
253
- maximum: number;
254
- default: number;
255
- description: string;
256
- };
257
- };
258
- sorting: {
259
- sort: {
260
- type: string;
261
- description: string;
262
- example: string;
263
- };
264
- };
265
- filtering: {
266
- select: {
267
- type: string;
268
- description: string;
269
- example: string;
270
- };
271
- populate: {
272
- type: string;
273
- description: string;
274
- example: string;
275
- };
276
- };
277
- };
278
- /**
279
- * Get standard list query parameters schema
280
- */
281
- declare function getListQueryParams(): AnyRecord;
282
-
283
- /**
284
- * State Machine Utility
285
- *
286
- * Pure utility for validating state transitions in workflow systems.
287
- * Zero dependencies, framework-agnostic.
288
- *
289
- * @example
290
- * const orderState = createStateMachine('Order', {
291
- * approve: ['pending', 'draft'],
292
- * cancel: ['pending', 'approved'],
293
- * fulfill: ['approved'],
294
- * });
295
- *
296
- * // Check if transition is allowed
297
- * if (orderState.can('approve', currentStatus)) {
298
- * // Perform approval
299
- * }
300
- *
301
- * // Assert transition (throws if invalid)
302
- * orderState.assert('approve', currentStatus, ValidationError);
303
- */
304
- interface StateMachine {
305
- /**
306
- * Check if action can be performed from current status
307
- */
308
- can(action: string, status: string | null | undefined, context?: any): boolean;
309
- /**
310
- * Assert action can be performed, throw error if invalid
311
- * @param action - Action to perform
312
- * @param status - Current status
313
- * @param errorFactory - Optional error constructor
314
- * @param message - Optional custom error message
315
- */
316
- assert(action: string, status: string | null | undefined, errorFactory?: (msg: string) => Error, message?: string): void;
317
- /**
318
- * Get transition history
319
- */
320
- getHistory?(): TransitionHistoryEntry[];
321
- /**
322
- * Record a transition
323
- */
324
- recordTransition?(from: string, to: string, action: string, metadata?: any): void;
325
- /**
326
- * Clear history
327
- */
328
- clearHistory?(): void;
329
- /**
330
- * Get available actions for current status
331
- */
332
- getAvailableActions?(status: string): string[];
333
- }
334
- interface TransitionHistoryEntry {
335
- from: string;
336
- to: string;
337
- action: string;
338
- timestamp: Date;
339
- metadata?: any;
340
- }
341
- interface TransitionGuard {
342
- (context: {
343
- from: string;
344
- to: string;
345
- action: string;
346
- data?: any;
347
- }): boolean | Promise<boolean>;
348
- }
349
- interface TransitionAction {
350
- (context: {
351
- from: string;
352
- to: string;
353
- action: string;
354
- data?: any;
355
- }): void | Promise<void>;
356
- }
357
- type TransitionConfig = Record<string, string[] | {
358
- from: string[];
359
- to?: string;
360
- guard?: TransitionGuard;
361
- before?: TransitionAction;
362
- after?: TransitionAction;
363
- }>;
364
- /**
365
- * Create a state machine for validating transitions
366
- *
367
- * @param name - Name of the state machine (used in error messages)
368
- * @param transitions - Map of actions to allowed source statuses
369
- * @param options - Additional options (history, guards, actions)
370
- * @returns State machine with can() and assert() methods
371
- *
372
- * @example
373
- * // Basic usage
374
- * const transferState = createStateMachine('Transfer', {
375
- * approve: ['draft'],
376
- * dispatch: ['approved'],
377
- * receive: ['dispatched', 'in_transit'],
378
- * cancel: ['draft', 'approved'],
379
- * });
380
- *
381
- * @example
382
- * // With guards and actions
383
- * const orderState = createStateMachine('Order', {
384
- * approve: {
385
- * from: ['pending'],
386
- * to: 'approved',
387
- * guard: ({ data }) => data.paymentConfirmed,
388
- * before: ({ from, to }) => console.log(`Approving order from ${from} to ${to}`),
389
- * after: ({ data }) => sendApprovalEmail(data.customerId),
390
- * },
391
- * }, { trackHistory: true });
392
- */
393
- declare function createStateMachine(name: string, transitions?: TransitionConfig, options?: {
394
- trackHistory?: boolean;
395
- }): StateMachine;
396
-
397
- /**
398
- * Circuit Breaker Pattern
399
- *
400
- * Wraps external service calls with failure protection.
401
- * Prevents cascading failures by "opening" the circuit when
402
- * a service is failing, allowing it time to recover.
403
- *
404
- * States:
405
- * - CLOSED: Normal operation, requests pass through
406
- * - OPEN: Too many failures, all requests fail fast
407
- * - HALF_OPEN: Testing if service recovered, limited requests
408
- *
409
- * @example
410
- * import { CircuitBreaker } from '@classytic/arc/utils';
411
- *
412
- * const paymentBreaker = new CircuitBreaker(async (amount) => {
413
- * return await stripe.charges.create({ amount });
414
- * }, {
415
- * failureThreshold: 5,
416
- * resetTimeout: 30000,
417
- * timeout: 5000,
418
- * });
419
- *
420
- * try {
421
- * const result = await paymentBreaker.call(100);
422
- * } catch (error) {
423
- * // Handle failure or circuit open
424
- * }
425
- */
426
- declare enum CircuitState {
427
- CLOSED = "CLOSED",
428
- OPEN = "OPEN",
429
- HALF_OPEN = "HALF_OPEN"
430
- }
431
- interface CircuitBreakerOptions {
432
- /**
433
- * Number of failures before opening circuit
434
- * @default 5
435
- */
436
- failureThreshold?: number;
437
- /**
438
- * Time in ms before attempting to close circuit
439
- * @default 60000 (60 seconds)
440
- */
441
- resetTimeout?: number;
442
- /**
443
- * Request timeout in ms
444
- * @default 10000 (10 seconds)
445
- */
446
- timeout?: number;
447
- /**
448
- * Number of successful requests in HALF_OPEN before closing
449
- * @default 1
450
- */
451
- successThreshold?: number;
452
- /**
453
- * Fallback function when circuit is open
454
- */
455
- fallback?: (...args: any[]) => Promise<any>;
456
- /**
457
- * Callback when state changes
458
- */
459
- onStateChange?: (from: CircuitState, to: CircuitState) => void;
460
- /**
461
- * Callback on error
462
- */
463
- onError?: (error: Error) => void;
464
- /**
465
- * Name for logging/monitoring
466
- */
467
- name?: string;
468
- }
469
- interface CircuitBreakerStats {
470
- name?: string;
471
- state: CircuitState;
472
- failures: number;
473
- successes: number;
474
- totalCalls: number;
475
- openedAt: number | null;
476
- lastCallAt: number | null;
477
- }
478
- declare class CircuitBreakerError extends Error {
479
- state: CircuitState;
480
- constructor(message: string, state: CircuitState);
481
- }
482
- declare class CircuitBreaker<T extends (...args: any[]) => Promise<any>> {
483
- private readonly fn;
484
- private state;
485
- private failures;
486
- private successes;
487
- private totalCalls;
488
- private nextAttempt;
489
- private lastCallAt;
490
- private openedAt;
491
- private readonly failureThreshold;
492
- private readonly resetTimeout;
493
- private readonly timeout;
494
- private readonly successThreshold;
495
- private readonly fallback?;
496
- private readonly onStateChange?;
497
- private readonly onError?;
498
- private readonly name;
499
- constructor(fn: T, options?: CircuitBreakerOptions);
500
- /**
501
- * Call the wrapped function with circuit breaker protection
502
- */
503
- call(...args: Parameters<T>): Promise<ReturnType<T>>;
504
- /**
505
- * Execute function with timeout
506
- */
507
- private executeWithTimeout;
508
- /**
509
- * Handle successful call
510
- */
511
- private onSuccess;
512
- /**
513
- * Handle failed call
514
- */
515
- private onFailure;
516
- /**
517
- * Change circuit state
518
- */
519
- private setState;
520
- /**
521
- * Manually open the circuit
522
- */
523
- open(): void;
524
- /**
525
- * Manually close the circuit
526
- */
527
- close(): void;
528
- /**
529
- * Get current statistics
530
- */
531
- getStats(): CircuitBreakerStats;
532
- /**
533
- * Get current state
534
- */
535
- getState(): CircuitState;
536
- /**
537
- * Check if circuit is open
538
- */
539
- isOpen(): boolean;
540
- /**
541
- * Check if circuit is closed
542
- */
543
- isClosed(): boolean;
544
- /**
545
- * Reset statistics
546
- */
547
- reset(): void;
548
- }
549
- /**
550
- * Create a circuit breaker with sensible defaults
551
- *
552
- * @example
553
- * const emailBreaker = createCircuitBreaker(
554
- * async (to, subject, body) => sendEmail(to, subject, body),
555
- * { name: 'email-service' }
556
- * );
557
- */
558
- declare function createCircuitBreaker<T extends (...args: any[]) => Promise<any>>(fn: T, options?: CircuitBreakerOptions): CircuitBreaker<T>;
559
- /**
560
- * Circuit breaker registry for managing multiple breakers
561
- */
562
- declare class CircuitBreakerRegistry {
563
- private breakers;
564
- /**
565
- * Register a circuit breaker
566
- */
567
- register<T extends (...args: any[]) => Promise<any>>(name: string, fn: T, options?: Omit<CircuitBreakerOptions, 'name'>): CircuitBreaker<T>;
568
- /**
569
- * Get a circuit breaker by name
570
- */
571
- get(name: string): CircuitBreaker<any> | undefined;
572
- /**
573
- * Get all breakers
574
- */
575
- getAll(): Map<string, CircuitBreaker<any>>;
576
- /**
577
- * Get statistics for all breakers
578
- */
579
- getAllStats(): Record<string, CircuitBreakerStats>;
580
- /**
581
- * Reset all breakers
582
- */
583
- resetAll(): void;
584
- /**
585
- * Open all breakers
586
- */
587
- openAll(): void;
588
- /**
589
- * Close all breakers
590
- */
591
- closeAll(): void;
592
- }
593
- /**
594
- * Global circuit breaker registry
595
- */
596
- declare const circuitBreakerRegistry: CircuitBreakerRegistry;
597
-
598
- /**
599
- * Arc Query Parser - Default URL-to-Query Parser
600
- *
601
- * Framework-agnostic query parser that converts URL parameters to query options.
602
- * This is Arc's built-in parser; users can swap in MongoKit's QueryParser,
603
- * pgkit's parser, or any custom parser implementing QueryParserInterface.
604
- *
605
- * @example
606
- * // Use Arc default parser (auto-applied if no queryParser option)
607
- * defineResource({ name: 'product', adapter: ... });
608
- *
609
- * // Use MongoKit's QueryParser (recommended for MongoDB - has $lookup, aggregations, etc.)
610
- * import { QueryParser } from '@classytic/mongokit';
611
- * defineResource({
612
- * name: 'product',
613
- * adapter: ...,
614
- * queryParser: new QueryParser(),
615
- * });
616
- *
617
- * // Use custom parser for SQL databases
618
- * defineResource({
619
- * name: 'user',
620
- * adapter: ...,
621
- * queryParser: new PgQueryParser(),
622
- * });
623
- */
624
-
625
- interface ArcQueryParserOptions {
626
- /** Maximum allowed limit value (default: 1000) */
627
- maxLimit?: number;
628
- /** Default limit for pagination (default: 20) */
629
- defaultLimit?: number;
630
- /** Maximum regex pattern length (default: 500) */
631
- maxRegexLength?: number;
632
- /** Maximum search query length (default: 200) */
633
- maxSearchLength?: number;
634
- /** Maximum filter nesting depth (default: 10) */
635
- maxFilterDepth?: number;
636
- }
637
- /**
638
- * Arc's default query parser
639
- *
640
- * Converts URL query parameters to a structured query format:
641
- * - Pagination: ?page=1&limit=20
642
- * - Sorting: ?sort=-createdAt,name (- prefix = descending)
643
- * - Filtering: ?status=active&price[gte]=100&price[lte]=500
644
- * - Search: ?search=keyword
645
- * - Populate: ?populate=author,category
646
- * - Field selection: ?select=name,price,status
647
- * - Keyset pagination: ?after=cursor_value
648
- *
649
- * For advanced MongoDB features ($lookup, aggregations), use MongoKit's QueryParser.
650
- */
651
- declare class ArcQueryParser implements QueryParserInterface {
652
- private readonly maxLimit;
653
- private readonly defaultLimit;
654
- private readonly maxRegexLength;
655
- private readonly maxSearchLength;
656
- private readonly maxFilterDepth;
657
- /** Supported filter operators */
658
- private readonly operators;
659
- constructor(options?: ArcQueryParserOptions);
660
- /**
661
- * Parse URL query parameters into structured query options
662
- */
663
- parse(query: Record<string, unknown> | null | undefined): ParsedQuery;
664
- private parseNumber;
665
- private parseString;
666
- private parseSort;
667
- private parseSearch;
668
- private parseSelect;
669
- private parseFilters;
670
- private parseFilterValue;
671
- private coerceValue;
672
- private sanitizeRegex;
673
- }
674
- /**
675
- * Create a new ArcQueryParser instance
676
- */
677
- declare function createQueryParser(options?: ArcQueryParserOptions): ArcQueryParser;
678
-
679
- export { ArcQueryParser, type ArcQueryParserOptions, CircuitBreaker, CircuitBreakerError, type CircuitBreakerOptions, CircuitBreakerRegistry, type CircuitBreakerStats, CircuitState, type JsonSchema, type StateMachine, type TransitionConfig, circuitBreakerRegistry, createCircuitBreaker, createQueryParser, createStateMachine, deleteResponse, errorResponseSchema, getListQueryParams, itemResponse, itemWrapper, listResponse, messageWrapper, mutationResponse, paginateWrapper, paginationSchema, queryParams, responses, successResponseSchema, wrapResponse };