@classytic/arc 1.1.0 → 2.1.2

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 (322) hide show
  1. package/README.md +247 -794
  2. package/bin/arc.js +91 -52
  3. package/dist/EventTransport-BD2U0BTc.d.mts +100 -0
  4. package/dist/EventTransport-BD2U0BTc.d.mts.map +1 -0
  5. package/dist/HookSystem-BsGV-j2l.mjs +405 -0
  6. package/dist/HookSystem-BsGV-j2l.mjs.map +1 -0
  7. package/dist/ResourceRegistry-DsN4KJjV.mjs +250 -0
  8. package/dist/ResourceRegistry-DsN4KJjV.mjs.map +1 -0
  9. package/dist/adapters/index.d.mts +5 -0
  10. package/dist/adapters/index.mjs +3 -0
  11. package/dist/audit/index.d.mts +82 -0
  12. package/dist/audit/index.d.mts.map +1 -0
  13. package/dist/audit/index.mjs +276 -0
  14. package/dist/audit/index.mjs.map +1 -0
  15. package/dist/audit/mongodb.d.mts +5 -0
  16. package/dist/audit/mongodb.mjs +3 -0
  17. package/dist/audited-C3T5DTUx.mjs +141 -0
  18. package/dist/audited-C3T5DTUx.mjs.map +1 -0
  19. package/dist/auth/index.d.mts +189 -0
  20. package/dist/auth/index.d.mts.map +1 -0
  21. package/dist/auth/index.mjs +1102 -0
  22. package/dist/auth/index.mjs.map +1 -0
  23. package/dist/auth/redis-session.d.mts +44 -0
  24. package/dist/auth/redis-session.d.mts.map +1 -0
  25. package/dist/auth/redis-session.mjs +76 -0
  26. package/dist/auth/redis-session.mjs.map +1 -0
  27. package/dist/betterAuthOpenApi-BrHKeSAx.mjs +250 -0
  28. package/dist/betterAuthOpenApi-BrHKeSAx.mjs.map +1 -0
  29. package/dist/cache/index.d.mts +146 -0
  30. package/dist/cache/index.d.mts.map +1 -0
  31. package/dist/cache/index.mjs +92 -0
  32. package/dist/cache/index.mjs.map +1 -0
  33. package/dist/caching-Bl28lYsR.mjs +94 -0
  34. package/dist/caching-Bl28lYsR.mjs.map +1 -0
  35. package/dist/chunk-C7Uep-_p.mjs +20 -0
  36. package/dist/circuitBreaker-DeY4FCjs.mjs +1097 -0
  37. package/dist/circuitBreaker-DeY4FCjs.mjs.map +1 -0
  38. package/dist/cli/commands/describe.d.mts +19 -0
  39. package/dist/cli/commands/describe.d.mts.map +1 -0
  40. package/dist/cli/commands/describe.mjs +239 -0
  41. package/dist/cli/commands/describe.mjs.map +1 -0
  42. package/dist/cli/commands/docs.d.mts +14 -0
  43. package/dist/cli/commands/docs.d.mts.map +1 -0
  44. package/dist/cli/commands/docs.mjs +53 -0
  45. package/dist/cli/commands/docs.mjs.map +1 -0
  46. package/dist/cli/commands/{generate.d.ts → generate.d.mts} +3 -1
  47. package/dist/cli/commands/generate.d.mts.map +1 -0
  48. package/dist/cli/commands/generate.mjs +358 -0
  49. package/dist/cli/commands/generate.mjs.map +1 -0
  50. package/dist/cli/commands/{init.d.ts → init.d.mts} +12 -8
  51. package/dist/cli/commands/init.d.mts.map +1 -0
  52. package/dist/cli/commands/{init.js → init.mjs} +807 -616
  53. package/dist/cli/commands/init.mjs.map +1 -0
  54. package/dist/cli/commands/introspect.d.mts +11 -0
  55. package/dist/cli/commands/introspect.d.mts.map +1 -0
  56. package/dist/cli/commands/introspect.mjs +76 -0
  57. package/dist/cli/commands/introspect.mjs.map +1 -0
  58. package/dist/cli/index.d.mts +17 -0
  59. package/dist/cli/index.d.mts.map +1 -0
  60. package/dist/cli/index.mjs +157 -0
  61. package/dist/cli/index.mjs.map +1 -0
  62. package/dist/constants-DdXFXQtN.mjs +85 -0
  63. package/dist/constants-DdXFXQtN.mjs.map +1 -0
  64. package/dist/core/index.d.mts +5 -0
  65. package/dist/core/index.mjs +4 -0
  66. package/dist/createApp-CUgNqegw.mjs +560 -0
  67. package/dist/createApp-CUgNqegw.mjs.map +1 -0
  68. package/dist/defineResource-k0_BDn8v.mjs +2197 -0
  69. package/dist/defineResource-k0_BDn8v.mjs.map +1 -0
  70. package/dist/discovery/index.d.mts +47 -0
  71. package/dist/discovery/index.d.mts.map +1 -0
  72. package/dist/discovery/index.mjs +110 -0
  73. package/dist/discovery/index.mjs.map +1 -0
  74. package/dist/docs/index.d.mts +163 -0
  75. package/dist/docs/index.d.mts.map +1 -0
  76. package/dist/docs/index.mjs +73 -0
  77. package/dist/docs/index.mjs.map +1 -0
  78. package/dist/elevation-BRy3yFWT.mjs +113 -0
  79. package/dist/elevation-BRy3yFWT.mjs.map +1 -0
  80. package/dist/elevation-B_2dRLVP.d.mts +88 -0
  81. package/dist/elevation-B_2dRLVP.d.mts.map +1 -0
  82. package/dist/errorHandler-BbcgBmIH.d.mts +73 -0
  83. package/dist/errorHandler-BbcgBmIH.d.mts.map +1 -0
  84. package/dist/errorHandler-C1okiriz.mjs +109 -0
  85. package/dist/errorHandler-C1okiriz.mjs.map +1 -0
  86. package/dist/errors-B9bZok84.mjs +212 -0
  87. package/dist/errors-B9bZok84.mjs.map +1 -0
  88. package/dist/errors-ChKiFz62.d.mts +125 -0
  89. package/dist/errors-ChKiFz62.d.mts.map +1 -0
  90. package/dist/eventPlugin-CTrLH3mt.d.mts +125 -0
  91. package/dist/eventPlugin-CTrLH3mt.d.mts.map +1 -0
  92. package/dist/eventPlugin-DGR_B2on.mjs +230 -0
  93. package/dist/eventPlugin-DGR_B2on.mjs.map +1 -0
  94. package/dist/events/index.d.mts +54 -0
  95. package/dist/events/index.d.mts.map +1 -0
  96. package/dist/events/index.mjs +52 -0
  97. package/dist/events/index.mjs.map +1 -0
  98. package/dist/events/transports/redis-stream-entry.d.mts +2 -0
  99. package/dist/events/transports/redis-stream-entry.mjs +178 -0
  100. package/dist/events/transports/redis-stream-entry.mjs.map +1 -0
  101. package/dist/events/transports/redis.d.mts +77 -0
  102. package/dist/events/transports/redis.d.mts.map +1 -0
  103. package/dist/events/transports/redis.mjs +125 -0
  104. package/dist/events/transports/redis.mjs.map +1 -0
  105. package/dist/externalPaths-DlINfKbP.d.mts +51 -0
  106. package/dist/externalPaths-DlINfKbP.d.mts.map +1 -0
  107. package/dist/factory/index.d.mts +64 -0
  108. package/dist/factory/index.d.mts.map +1 -0
  109. package/dist/factory/index.mjs +3 -0
  110. package/dist/fastifyAdapter-BkrGrlFi.d.mts +217 -0
  111. package/dist/fastifyAdapter-BkrGrlFi.d.mts.map +1 -0
  112. package/dist/fields-DyaDVX4J.d.mts +110 -0
  113. package/dist/fields-DyaDVX4J.d.mts.map +1 -0
  114. package/dist/fields-iagOozy0.mjs +115 -0
  115. package/dist/fields-iagOozy0.mjs.map +1 -0
  116. package/dist/hooks/index.d.mts +4 -0
  117. package/dist/hooks/index.mjs +3 -0
  118. package/dist/idempotency/index.d.mts +97 -0
  119. package/dist/idempotency/index.d.mts.map +1 -0
  120. package/dist/idempotency/index.mjs +320 -0
  121. package/dist/idempotency/index.mjs.map +1 -0
  122. package/dist/idempotency/mongodb.d.mts +2 -0
  123. package/dist/idempotency/mongodb.mjs +115 -0
  124. package/dist/idempotency/mongodb.mjs.map +1 -0
  125. package/dist/idempotency/redis.d.mts +2 -0
  126. package/dist/idempotency/redis.mjs +104 -0
  127. package/dist/idempotency/redis.mjs.map +1 -0
  128. package/dist/index.d.mts +261 -0
  129. package/dist/index.d.mts.map +1 -0
  130. package/dist/index.mjs +105 -0
  131. package/dist/index.mjs.map +1 -0
  132. package/dist/integrations/event-gateway.d.mts +47 -0
  133. package/dist/integrations/event-gateway.d.mts.map +1 -0
  134. package/dist/integrations/event-gateway.mjs +44 -0
  135. package/dist/integrations/event-gateway.mjs.map +1 -0
  136. package/dist/integrations/index.d.mts +5 -0
  137. package/dist/integrations/index.mjs +1 -0
  138. package/dist/integrations/jobs.d.mts +104 -0
  139. package/dist/integrations/jobs.d.mts.map +1 -0
  140. package/dist/integrations/jobs.mjs +124 -0
  141. package/dist/integrations/jobs.mjs.map +1 -0
  142. package/dist/integrations/streamline.d.mts +61 -0
  143. package/dist/integrations/streamline.d.mts.map +1 -0
  144. package/dist/integrations/streamline.mjs +126 -0
  145. package/dist/integrations/streamline.mjs.map +1 -0
  146. package/dist/integrations/websocket.d.mts +83 -0
  147. package/dist/integrations/websocket.d.mts.map +1 -0
  148. package/dist/integrations/websocket.mjs +289 -0
  149. package/dist/integrations/websocket.mjs.map +1 -0
  150. package/dist/interface-B01JvPVc.d.mts +78 -0
  151. package/dist/interface-B01JvPVc.d.mts.map +1 -0
  152. package/dist/interface-CZe8IkMf.d.mts +55 -0
  153. package/dist/interface-CZe8IkMf.d.mts.map +1 -0
  154. package/dist/interface-Ch8HU9uM.d.mts +1098 -0
  155. package/dist/interface-Ch8HU9uM.d.mts.map +1 -0
  156. package/dist/introspectionPlugin-rFdO8ZUa.mjs +54 -0
  157. package/dist/introspectionPlugin-rFdO8ZUa.mjs.map +1 -0
  158. package/dist/keys-BqNejWup.mjs +43 -0
  159. package/dist/keys-BqNejWup.mjs.map +1 -0
  160. package/dist/logger-Df2O2WsW.mjs +79 -0
  161. package/dist/logger-Df2O2WsW.mjs.map +1 -0
  162. package/dist/memory-cQgelFOj.mjs +144 -0
  163. package/dist/memory-cQgelFOj.mjs.map +1 -0
  164. package/dist/migrations/index.d.mts +157 -0
  165. package/dist/migrations/index.d.mts.map +1 -0
  166. package/dist/migrations/index.mjs +261 -0
  167. package/dist/migrations/index.mjs.map +1 -0
  168. package/dist/mongodb-BfJVlUJH.mjs +94 -0
  169. package/dist/mongodb-BfJVlUJH.mjs.map +1 -0
  170. package/dist/mongodb-CGzRbfAK.d.mts +119 -0
  171. package/dist/mongodb-CGzRbfAK.d.mts.map +1 -0
  172. package/dist/mongodb-JN-9JA7K.d.mts +72 -0
  173. package/dist/mongodb-JN-9JA7K.d.mts.map +1 -0
  174. package/dist/openapi-G3Cw7XuM.mjs +524 -0
  175. package/dist/openapi-G3Cw7XuM.mjs.map +1 -0
  176. package/dist/org/index.d.mts +69 -0
  177. package/dist/org/index.d.mts.map +1 -0
  178. package/dist/org/index.mjs +514 -0
  179. package/dist/org/index.mjs.map +1 -0
  180. package/dist/org/types.d.mts +83 -0
  181. package/dist/org/types.d.mts.map +1 -0
  182. package/dist/org/types.mjs +1 -0
  183. package/dist/permissions/index.d.mts +279 -0
  184. package/dist/permissions/index.d.mts.map +1 -0
  185. package/dist/permissions/index.mjs +579 -0
  186. package/dist/permissions/index.mjs.map +1 -0
  187. package/dist/plugins/index.d.mts +173 -0
  188. package/dist/plugins/index.d.mts.map +1 -0
  189. package/dist/plugins/index.mjs +523 -0
  190. package/dist/plugins/index.mjs.map +1 -0
  191. package/dist/plugins/response-cache.d.mts +88 -0
  192. package/dist/plugins/response-cache.d.mts.map +1 -0
  193. package/dist/plugins/response-cache.mjs +284 -0
  194. package/dist/plugins/response-cache.mjs.map +1 -0
  195. package/dist/plugins/tracing-entry.d.mts +2 -0
  196. package/dist/plugins/tracing-entry.mjs +186 -0
  197. package/dist/plugins/tracing-entry.mjs.map +1 -0
  198. package/dist/pluralize-CEweyOEm.mjs +87 -0
  199. package/dist/pluralize-CEweyOEm.mjs.map +1 -0
  200. package/dist/policies/{index.d.ts → index.d.mts} +204 -169
  201. package/dist/policies/index.d.mts.map +1 -0
  202. package/dist/policies/index.mjs +322 -0
  203. package/dist/policies/index.mjs.map +1 -0
  204. package/dist/presets/{index.d.ts → index.d.mts} +63 -131
  205. package/dist/presets/index.d.mts.map +1 -0
  206. package/dist/presets/index.mjs +144 -0
  207. package/dist/presets/index.mjs.map +1 -0
  208. package/dist/presets/multiTenant.d.mts +25 -0
  209. package/dist/presets/multiTenant.d.mts.map +1 -0
  210. package/dist/presets/multiTenant.mjs +114 -0
  211. package/dist/presets/multiTenant.mjs.map +1 -0
  212. package/dist/presets-BITljm96.mjs +120 -0
  213. package/dist/presets-BITljm96.mjs.map +1 -0
  214. package/dist/presets-DzSMwlKj.d.mts +58 -0
  215. package/dist/presets-DzSMwlKj.d.mts.map +1 -0
  216. package/dist/prisma-DJbMt3yf.mjs +628 -0
  217. package/dist/prisma-DJbMt3yf.mjs.map +1 -0
  218. package/dist/prisma-Dg9GoVdj.d.mts +275 -0
  219. package/dist/prisma-Dg9GoVdj.d.mts.map +1 -0
  220. package/dist/queryCachePlugin-7THaI5mt.d.mts +72 -0
  221. package/dist/queryCachePlugin-7THaI5mt.d.mts.map +1 -0
  222. package/dist/queryCachePlugin-DMBnp2Q0.mjs +139 -0
  223. package/dist/queryCachePlugin-DMBnp2Q0.mjs.map +1 -0
  224. package/dist/redis-D-JAeLtm.d.mts +50 -0
  225. package/dist/redis-D-JAeLtm.d.mts.map +1 -0
  226. package/dist/redis-stream-Bdh_vUU8.d.mts +104 -0
  227. package/dist/redis-stream-Bdh_vUU8.d.mts.map +1 -0
  228. package/dist/registry/index.d.mts +12 -0
  229. package/dist/registry/index.d.mts.map +1 -0
  230. package/dist/registry/index.mjs +4 -0
  231. package/dist/requestContext-QQD6ROJc.mjs +56 -0
  232. package/dist/requestContext-QQD6ROJc.mjs.map +1 -0
  233. package/dist/schemaConverter-BwrmWroW.mjs +99 -0
  234. package/dist/schemaConverter-BwrmWroW.mjs.map +1 -0
  235. package/dist/schemas/index.d.mts +64 -0
  236. package/dist/schemas/index.d.mts.map +1 -0
  237. package/dist/schemas/index.mjs +83 -0
  238. package/dist/schemas/index.mjs.map +1 -0
  239. package/dist/scope/index.d.mts +22 -0
  240. package/dist/scope/index.d.mts.map +1 -0
  241. package/dist/scope/index.mjs +66 -0
  242. package/dist/scope/index.mjs.map +1 -0
  243. package/dist/sessionManager-jPKLbHE0.d.mts +187 -0
  244. package/dist/sessionManager-jPKLbHE0.d.mts.map +1 -0
  245. package/dist/sse-B3c3_yZp.mjs +124 -0
  246. package/dist/sse-B3c3_yZp.mjs.map +1 -0
  247. package/dist/testing/index.d.mts +908 -0
  248. package/dist/testing/index.d.mts.map +1 -0
  249. package/dist/testing/index.mjs +1977 -0
  250. package/dist/testing/index.mjs.map +1 -0
  251. package/dist/tracing-Cc7vVQPp.d.mts +71 -0
  252. package/dist/tracing-Cc7vVQPp.d.mts.map +1 -0
  253. package/dist/typeGuards-DhMNLuvU.mjs +10 -0
  254. package/dist/typeGuards-DhMNLuvU.mjs.map +1 -0
  255. package/dist/types/index.d.mts +947 -0
  256. package/dist/types/index.d.mts.map +1 -0
  257. package/dist/types/index.mjs +15 -0
  258. package/dist/types/index.mjs.map +1 -0
  259. package/dist/types-Beqn1Un7.mjs +39 -0
  260. package/dist/types-Beqn1Un7.mjs.map +1 -0
  261. package/dist/types-CIgB7UUl.d.mts +446 -0
  262. package/dist/types-CIgB7UUl.d.mts.map +1 -0
  263. package/dist/types-aYB4V7uN.d.mts +87 -0
  264. package/dist/types-aYB4V7uN.d.mts.map +1 -0
  265. package/dist/utils/index.d.mts +748 -0
  266. package/dist/utils/index.d.mts.map +1 -0
  267. package/dist/utils/index.mjs +6 -0
  268. package/package.json +194 -68
  269. package/dist/BaseController-DVAiHxEQ.d.ts +0 -233
  270. package/dist/adapters/index.d.ts +0 -237
  271. package/dist/adapters/index.js +0 -668
  272. package/dist/arcCorePlugin-CsShQdyP.d.ts +0 -273
  273. package/dist/audit/index.d.ts +0 -195
  274. package/dist/audit/index.js +0 -319
  275. package/dist/auth/index.d.ts +0 -47
  276. package/dist/auth/index.js +0 -174
  277. package/dist/cli/commands/docs.d.ts +0 -11
  278. package/dist/cli/commands/docs.js +0 -474
  279. package/dist/cli/commands/generate.js +0 -334
  280. package/dist/cli/commands/introspect.d.ts +0 -8
  281. package/dist/cli/commands/introspect.js +0 -338
  282. package/dist/cli/index.d.ts +0 -4
  283. package/dist/cli/index.js +0 -3269
  284. package/dist/core/index.d.ts +0 -220
  285. package/dist/core/index.js +0 -2786
  286. package/dist/createApp-Ce9wl8W9.d.ts +0 -77
  287. package/dist/docs/index.d.ts +0 -166
  288. package/dist/docs/index.js +0 -658
  289. package/dist/errors-8WIxGS_6.d.ts +0 -122
  290. package/dist/events/index.d.ts +0 -117
  291. package/dist/events/index.js +0 -89
  292. package/dist/factory/index.d.ts +0 -38
  293. package/dist/factory/index.js +0 -1652
  294. package/dist/hooks/index.d.ts +0 -4
  295. package/dist/hooks/index.js +0 -199
  296. package/dist/idempotency/index.d.ts +0 -323
  297. package/dist/idempotency/index.js +0 -500
  298. package/dist/index-B4t03KQ0.d.ts +0 -1366
  299. package/dist/index.d.ts +0 -135
  300. package/dist/index.js +0 -4756
  301. package/dist/migrations/index.d.ts +0 -185
  302. package/dist/migrations/index.js +0 -274
  303. package/dist/org/index.d.ts +0 -129
  304. package/dist/org/index.js +0 -220
  305. package/dist/permissions/index.d.ts +0 -144
  306. package/dist/permissions/index.js +0 -103
  307. package/dist/plugins/index.d.ts +0 -46
  308. package/dist/plugins/index.js +0 -1069
  309. package/dist/policies/index.js +0 -196
  310. package/dist/presets/index.js +0 -384
  311. package/dist/presets/multiTenant.d.ts +0 -39
  312. package/dist/presets/multiTenant.js +0 -112
  313. package/dist/registry/index.d.ts +0 -16
  314. package/dist/registry/index.js +0 -253
  315. package/dist/testing/index.d.ts +0 -618
  316. package/dist/testing/index.js +0 -48020
  317. package/dist/types/index.d.ts +0 -4
  318. package/dist/types/index.js +0 -8
  319. package/dist/types-B99TBmFV.d.ts +0 -76
  320. package/dist/types-BvckRbs2.d.ts +0 -143
  321. package/dist/utils/index.d.ts +0 -679
  322. package/dist/utils/index.js +0 -931
@@ -1,185 +0,0 @@
1
- import mongoose from 'mongoose';
2
-
3
- /**
4
- * Schema Versioning and Migrations System
5
- *
6
- * Manages database schema changes over time with version tracking.
7
- * Supports forward migrations, rollbacks, and schema compatibility layers.
8
- *
9
- * @example
10
- * import { defineMigration, MigrationRunner } from '@classytic/arc/migrations';
11
- *
12
- * const productV2 = defineMigration({
13
- * version: 2,
14
- * resource: 'product',
15
- * up: async (db) => {
16
- * await db.collection('products').updateMany(
17
- * {},
18
- * { $rename: { 'oldField': 'newField' } }
19
- * );
20
- * },
21
- * down: async (db) => {
22
- * await db.collection('products').updateMany(
23
- * {},
24
- * { $rename: { 'newField': 'oldField' } }
25
- * );
26
- * },
27
- * });
28
- *
29
- * const runner = new MigrationRunner(mongoose.connection.db);
30
- * await runner.up(); // Run all pending migrations
31
- */
32
-
33
- interface Migration {
34
- /** Migration version (sequential number) */
35
- version: number;
36
- /** Resource name this migration applies to */
37
- resource: string;
38
- /** Description of the migration */
39
- description?: string;
40
- /**
41
- * Forward migration (apply schema change)
42
- */
43
- up: (db: mongoose.mongo.Db) => Promise<void>;
44
- /**
45
- * Backward migration (revert schema change)
46
- */
47
- down: (db: mongoose.mongo.Db) => Promise<void>;
48
- /**
49
- * Optional validation that data is compatible after migration
50
- */
51
- validate?: (db: mongoose.mongo.Db) => Promise<boolean>;
52
- }
53
- interface MigrationRecord {
54
- version: number;
55
- resource: string;
56
- description?: string;
57
- appliedAt: Date;
58
- executionTime: number;
59
- }
60
- /**
61
- * Define a migration
62
- */
63
- declare function defineMigration(migration: Migration): Migration;
64
- /**
65
- * Migration Runner
66
- *
67
- * Manages execution of migrations with tracking and rollback support.
68
- */
69
- declare class MigrationRunner {
70
- private readonly db;
71
- private readonly collectionName;
72
- constructor(db: mongoose.mongo.Db);
73
- /**
74
- * Run all pending migrations
75
- */
76
- up(migrations: Migration[]): Promise<void>;
77
- /**
78
- * Rollback last migration
79
- */
80
- down(migrations: Migration[]): Promise<void>;
81
- /**
82
- * Rollback to specific version
83
- */
84
- downTo(migrations: Migration[], targetVersion: number): Promise<void>;
85
- /**
86
- * Get all applied migrations
87
- */
88
- getAppliedMigrations(): Promise<MigrationRecord[]>;
89
- /**
90
- * Get pending migrations
91
- */
92
- getPendingMigrations(migrations: Migration[]): Promise<Migration[]>;
93
- /**
94
- * Check if migrations are up to date
95
- */
96
- isUpToDate(migrations: Migration[]): Promise<boolean>;
97
- /**
98
- * Run a single migration
99
- */
100
- private runMigration;
101
- /**
102
- * Record a completed migration
103
- */
104
- private recordMigration;
105
- /**
106
- * Remove a migration record
107
- */
108
- private removeMigration;
109
- }
110
- /**
111
- * Schema version definition for resources
112
- */
113
- interface SchemaVersion {
114
- version: number;
115
- migrations: Migration[];
116
- }
117
- /**
118
- * Add versioning to resource definition
119
- *
120
- * @example
121
- * export default defineResource({
122
- * name: 'product',
123
- * version: 2,
124
- * migrations: [productV1ToV2Migration],
125
- * // ... rest of resource definition
126
- * });
127
- */
128
- declare function withSchemaVersion(version: number, migrations: Migration[]): SchemaVersion;
129
- /**
130
- * Global migration registry
131
- */
132
- declare class MigrationRegistry {
133
- private migrations;
134
- /**
135
- * Register a migration
136
- */
137
- register(migration: Migration): void;
138
- /**
139
- * Register multiple migrations
140
- */
141
- registerMany(migrations: Migration[]): void;
142
- /**
143
- * Get all migrations for a resource
144
- */
145
- getForResource(resource: string): Migration[];
146
- /**
147
- * Get all migrations
148
- */
149
- getAll(): Migration[];
150
- /**
151
- * Get migration by resource and version
152
- */
153
- get(resource: string, version: number): Migration | undefined;
154
- /**
155
- * Clear all registrations
156
- */
157
- clear(): void;
158
- }
159
- /**
160
- * Global migration registry instance
161
- */
162
- declare const migrationRegistry: MigrationRegistry;
163
- /**
164
- * Common migration helpers
165
- */
166
- declare const migrationHelpers: {
167
- /**
168
- * Rename a field across all documents
169
- */
170
- renameField: (collection: string, oldName: string, newName: string) => Migration;
171
- /**
172
- * Add a new field with default value
173
- */
174
- addField: (collection: string, fieldName: string, defaultValue: any) => Migration;
175
- /**
176
- * Remove a field
177
- */
178
- removeField: (collection: string, fieldName: string) => Migration;
179
- /**
180
- * Create an index
181
- */
182
- createIndex: (collection: string, fields: Record<string, 1 | -1>, options?: any) => Migration;
183
- };
184
-
185
- export { type Migration, type MigrationRecord, MigrationRegistry, MigrationRunner, type SchemaVersion, defineMigration, migrationHelpers, migrationRegistry, withSchemaVersion };
@@ -1,274 +0,0 @@
1
- import 'mongoose';
2
-
3
- // src/migrations/index.ts
4
- function defineMigration(migration) {
5
- return migration;
6
- }
7
- var MigrationRunner = class {
8
- constructor(db) {
9
- this.db = db;
10
- }
11
- collectionName = "_migrations";
12
- /**
13
- * Run all pending migrations
14
- */
15
- async up(migrations) {
16
- const applied = await this.getAppliedMigrations();
17
- const appliedVersions = new Set(applied.map((m) => `${m.resource}:${m.version}`));
18
- const pending = migrations.filter((m) => !appliedVersions.has(`${m.resource}:${m.version}`)).sort((a, b) => a.version - b.version);
19
- if (pending.length === 0) {
20
- console.log("No pending migrations");
21
- return;
22
- }
23
- console.log(`Running ${pending.length} migration(s)...
24
- `);
25
- for (const migration of pending) {
26
- await this.runMigration(migration, "up");
27
- }
28
- console.log("\nAll migrations completed successfully");
29
- }
30
- /**
31
- * Rollback last migration
32
- */
33
- async down(migrations) {
34
- const applied = await this.getAppliedMigrations();
35
- if (applied.length === 0) {
36
- console.log("No migrations to rollback");
37
- return;
38
- }
39
- const last = applied[applied.length - 1];
40
- if (!last) {
41
- console.log("No migrations to rollback");
42
- return;
43
- }
44
- const migration = migrations.find(
45
- (m) => m.resource === last.resource && m.version === last.version
46
- );
47
- if (!migration) {
48
- throw new Error(
49
- `Migration ${last.resource}:${last.version} not found in migration files`
50
- );
51
- }
52
- console.log(`Rolling back ${migration.resource} v${migration.version}...`);
53
- await this.runMigration(migration, "down", true);
54
- console.log("Rollback completed");
55
- }
56
- /**
57
- * Rollback to specific version
58
- */
59
- async downTo(migrations, targetVersion) {
60
- const applied = await this.getAppliedMigrations();
61
- const toRollback = applied.filter((m) => m.version > targetVersion).reverse();
62
- if (toRollback.length === 0) {
63
- console.log(`Already at or below version ${targetVersion}`);
64
- return;
65
- }
66
- console.log(`Rolling back ${toRollback.length} migration(s)...
67
- `);
68
- for (const record of toRollback) {
69
- const migration = migrations.find(
70
- (m) => m.resource === record.resource && m.version === record.version
71
- );
72
- if (!migration) {
73
- throw new Error(`Migration ${record.resource}:${record.version} not found`);
74
- }
75
- await this.runMigration(migration, "down", true);
76
- }
77
- console.log("\nRollback completed");
78
- }
79
- /**
80
- * Get all applied migrations
81
- */
82
- async getAppliedMigrations() {
83
- const collection = this.db.collection(this.collectionName);
84
- const records = await collection.find({}).sort({ appliedAt: 1 }).toArray();
85
- return records;
86
- }
87
- /**
88
- * Get pending migrations
89
- */
90
- async getPendingMigrations(migrations) {
91
- const applied = await this.getAppliedMigrations();
92
- const appliedVersions = new Set(applied.map((m) => `${m.resource}:${m.version}`));
93
- return migrations.filter((m) => !appliedVersions.has(`${m.resource}:${m.version}`));
94
- }
95
- /**
96
- * Check if migrations are up to date
97
- */
98
- async isUpToDate(migrations) {
99
- const pending = await this.getPendingMigrations(migrations);
100
- return pending.length === 0;
101
- }
102
- /**
103
- * Run a single migration
104
- */
105
- async runMigration(migration, direction, isRollback = false) {
106
- const start = Date.now();
107
- const action = direction === "up" ? "Applying" : "Rolling back";
108
- console.log(
109
- `${action} ${migration.resource} v${migration.version}${migration.description ? `: ${migration.description}` : ""}...`
110
- );
111
- try {
112
- if (direction === "up") {
113
- await migration.up(this.db);
114
- if (migration.validate) {
115
- const valid = await migration.validate(this.db);
116
- if (!valid) {
117
- throw new Error("Migration validation failed");
118
- }
119
- }
120
- await this.recordMigration(migration, Date.now() - start);
121
- } else {
122
- await migration.down(this.db);
123
- if (isRollback) {
124
- await this.removeMigration(migration);
125
- }
126
- }
127
- const duration = Date.now() - start;
128
- console.log(`✅ ${migration.resource} v${migration.version} (${duration}ms)`);
129
- } catch (error) {
130
- console.error(
131
- `❌ ${migration.resource} v${migration.version} failed:`,
132
- error.message
133
- );
134
- throw error;
135
- }
136
- }
137
- /**
138
- * Record a completed migration
139
- */
140
- async recordMigration(migration, executionTime) {
141
- const collection = this.db.collection(this.collectionName);
142
- await collection.insertOne({
143
- version: migration.version,
144
- resource: migration.resource,
145
- description: migration.description,
146
- appliedAt: /* @__PURE__ */ new Date(),
147
- executionTime
148
- });
149
- }
150
- /**
151
- * Remove a migration record
152
- */
153
- async removeMigration(migration) {
154
- const collection = this.db.collection(this.collectionName);
155
- await collection.deleteOne({
156
- version: migration.version,
157
- resource: migration.resource
158
- });
159
- }
160
- };
161
- function withSchemaVersion(version, migrations) {
162
- return { version, migrations };
163
- }
164
- var MigrationRegistry = class {
165
- migrations = /* @__PURE__ */ new Map();
166
- /**
167
- * Register a migration
168
- */
169
- register(migration) {
170
- const existing = this.migrations.get(migration.resource) || [];
171
- existing.push(migration);
172
- existing.sort((a, b) => a.version - b.version);
173
- this.migrations.set(migration.resource, existing);
174
- }
175
- /**
176
- * Register multiple migrations
177
- */
178
- registerMany(migrations) {
179
- for (const migration of migrations) {
180
- this.register(migration);
181
- }
182
- }
183
- /**
184
- * Get all migrations for a resource
185
- */
186
- getForResource(resource) {
187
- return this.migrations.get(resource) || [];
188
- }
189
- /**
190
- * Get all migrations
191
- */
192
- getAll() {
193
- const all = [];
194
- for (const migrations of this.migrations.values()) {
195
- all.push(...migrations);
196
- }
197
- return all.sort((a, b) => a.version - b.version);
198
- }
199
- /**
200
- * Get migration by resource and version
201
- */
202
- get(resource, version) {
203
- const migrations = this.migrations.get(resource) || [];
204
- return migrations.find((m) => m.version === version);
205
- }
206
- /**
207
- * Clear all registrations
208
- */
209
- clear() {
210
- this.migrations.clear();
211
- }
212
- };
213
- var migrationRegistry = new MigrationRegistry();
214
- var migrationHelpers = {
215
- /**
216
- * Rename a field across all documents
217
- */
218
- renameField: (collection, oldName, newName) => defineMigration({
219
- version: 0,
220
- resource: collection,
221
- description: `Rename ${oldName} to ${newName}`,
222
- up: async (db) => {
223
- await db.collection(collection).updateMany({}, { $rename: { [oldName]: newName } });
224
- },
225
- down: async (db) => {
226
- await db.collection(collection).updateMany({}, { $rename: { [newName]: oldName } });
227
- }
228
- }),
229
- /**
230
- * Add a new field with default value
231
- */
232
- addField: (collection, fieldName, defaultValue) => defineMigration({
233
- version: 0,
234
- resource: collection,
235
- description: `Add ${fieldName} field`,
236
- up: async (db) => {
237
- await db.collection(collection).updateMany({ [fieldName]: { $exists: false } }, { $set: { [fieldName]: defaultValue } });
238
- },
239
- down: async (db) => {
240
- await db.collection(collection).updateMany({}, { $unset: { [fieldName]: "" } });
241
- }
242
- }),
243
- /**
244
- * Remove a field
245
- */
246
- removeField: (collection, fieldName) => defineMigration({
247
- version: 0,
248
- resource: collection,
249
- description: `Remove ${fieldName} field`,
250
- up: async (db) => {
251
- await db.collection(collection).updateMany({}, { $unset: { [fieldName]: "" } });
252
- },
253
- down: async (db) => {
254
- console.warn(`Cannot restore ${fieldName} field - data was deleted`);
255
- }
256
- }),
257
- /**
258
- * Create an index
259
- */
260
- createIndex: (collection, fields, options) => defineMigration({
261
- version: 0,
262
- resource: collection,
263
- description: `Create index on ${Object.keys(fields).join(", ")}`,
264
- up: async (db) => {
265
- await db.collection(collection).createIndex(fields, options);
266
- },
267
- down: async (db) => {
268
- const indexName = options?.name || Object.keys(fields).join("_");
269
- await db.collection(collection).dropIndex(indexName);
270
- }
271
- })
272
- };
273
-
274
- export { MigrationRegistry, MigrationRunner, defineMigration, migrationHelpers, migrationRegistry, withSchemaVersion };
@@ -1,129 +0,0 @@
1
- import { RouteHandlerMethod, FastifyPluginAsync } from 'fastify';
2
- import { b as RequestContext, Z as OrgScopeOptions, z as RouteHandler } from '../index-B4t03KQ0.js';
3
- import { U as UserBase } from '../types-B99TBmFV.js';
4
- import 'mongoose';
5
-
6
- /**
7
- * 🏢 Smart Organization Scope Plugin
8
- *
9
- * Intelligent organization filtering that adapts to authentication context.
10
- *
11
- * Philosophy: "Be Lenient with Public, Strict with Authenticated"
12
- * - Public routes: Allow without org filter (shows all)
13
- * - Authenticated routes: Validate org access
14
- * - Admin routes: Bypass restrictions
15
- *
16
- * Usage Pattern:
17
- * - This plugin adds a `organizationScoped()` decorator factory to fastify
18
- * - Apply it per-route as preHandler, NOT as a global hook
19
- * - Resources can opt-in to org scoping individually
20
- *
21
- * @example
22
- * // Register the plugin
23
- * await fastify.register(orgScopePlugin, {
24
- * header: 'x-organization-id',
25
- * bypassRoles: ['superadmin'],
26
- * });
27
- *
28
- * // Use per-route (required org)
29
- * fastify.get('/invoices', {
30
- * preHandler: [fastify.authenticate, fastify.organizationScoped({ required: true })]
31
- * }, handler);
32
- *
33
- * // Optional org scoping (shows all if no header)
34
- * fastify.get('/products', {
35
- * preHandler: [fastify.organizationScoped({ required: false })]
36
- * }, handler);
37
- */
38
-
39
- interface OrganizationScopedOptions {
40
- /** Require org header (default: true) */
41
- required?: boolean;
42
- }
43
- declare module 'fastify' {
44
- interface FastifyRequest {
45
- context?: RequestContext;
46
- organizationId?: string;
47
- }
48
- interface FastifyInstance {
49
- organizationScoped: (options?: OrganizationScopedOptions) => RouteHandlerMethod;
50
- createOrgContext: (orgId: string, options?: Partial<RequestContext>) => RequestContext;
51
- }
52
- }
53
- /**
54
- * Create org context object
55
- */
56
- declare function createOrgContext(orgId: string, options?: Partial<RequestContext>): RequestContext;
57
- declare const orgScopePlugin: FastifyPluginAsync<OrgScopeOptions>;
58
- declare const _default: FastifyPluginAsync<OrgScopeOptions>;
59
-
60
- /**
61
- * Organization Guard Middleware
62
- *
63
- * Ensures organization context is present before handler execution.
64
- *
65
- * @example
66
- * // Require org context
67
- * fastify.get('/invoices', {
68
- * preHandler: [fastify.authenticate, orgGuard()]
69
- * }, handler);
70
- *
71
- * // Require specific org roles
72
- * fastify.post('/invoices', {
73
- * preHandler: [fastify.authenticate, orgGuard({ roles: ['admin', 'accountant'] })]
74
- * }, handler);
75
- */
76
-
77
- interface OrgGuardOptions {
78
- /** Require organization context (default: true) */
79
- requireOrgContext?: boolean;
80
- /** Required org-level roles */
81
- roles?: string[];
82
- /** Allow superadmin without org context */
83
- allowGlobal?: boolean;
84
- }
85
- /**
86
- * Create org guard middleware
87
- */
88
- declare function orgGuard(options?: OrgGuardOptions): RouteHandler;
89
- /**
90
- * Shorthand for requiring org context
91
- */
92
- declare function requireOrg(): RouteHandler;
93
- /**
94
- * Require org context with specific roles
95
- */
96
- declare function requireOrgRole(...roles: string[]): RouteHandler;
97
-
98
- /**
99
- * Organization Membership Utilities
100
- *
101
- * Server-side membership validation.
102
- */
103
-
104
- interface OrgMembershipOptions {
105
- /** Path to user's organizations array */
106
- userOrgsPath?: string;
107
- /** Roles that bypass membership check */
108
- bypassRoles?: string[];
109
- /** Optional DB lookup function */
110
- validateFromDb?: (userId: string, orgId: string) => Promise<boolean>;
111
- }
112
- interface OrgRolesOptions {
113
- /** Path to user's organizations array */
114
- userOrgsPath?: string;
115
- }
116
- /**
117
- * Check if user is member of organization
118
- */
119
- declare function orgMembershipCheck(user: UserBase | undefined | null, orgId: string | undefined | null, options?: OrgMembershipOptions): Promise<boolean>;
120
- /**
121
- * Get user's role in organization
122
- */
123
- declare function getOrgRoles(user: UserBase | undefined | null, orgId: string | undefined | null, options?: OrgRolesOptions): string[];
124
- /**
125
- * Check if user has specific role in organization
126
- */
127
- declare function hasOrgRole(user: UserBase | undefined | null, orgId: string | undefined | null, roles: string | string[], options?: OrgRolesOptions): boolean;
128
-
129
- export { type OrgGuardOptions, type OrgMembershipOptions, type OrgRolesOptions, OrgScopeOptions, type OrganizationScopedOptions, createOrgContext, getOrgRoles, hasOrgRole, orgGuard, orgMembershipCheck, _default as orgScopePlugin, orgScopePlugin as orgScopePluginFn, requireOrg, requireOrgRole };