@classytic/arc 2.48.0 → 2.50.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 (213) hide show
  1. package/dist/{EventTransport-BWwg5YAU.mjs → EventTransport-B18mcj_M.mjs} +2 -2
  2. package/dist/{HookSystem-B9x-Y_k7.mjs → HookSystem-FUBaLTRm.mjs} +2 -2
  3. package/dist/{QueryCache-DdvrGG8Q.d.mts → QueryCache-BE47tmlO.d.mts} +36 -1
  4. package/dist/{ResourceRegistry-BcvEJoZd.mjs → ResourceRegistry-C5NM07fZ.mjs} +2 -2
  5. package/dist/{acquire-D2yj6Zzl.mjs → acquire-MHCnbDtH.mjs} +1 -1
  6. package/dist/audit/index.d.mts +1 -1
  7. package/dist/audit/index.mjs +4 -4
  8. package/dist/auth/audit.mjs +1 -1
  9. package/dist/auth/index.d.mts +2 -2
  10. package/dist/auth/index.mjs +53 -15
  11. package/dist/auth/redis-session.mjs +1 -1
  12. package/dist/{authorizationDecision-BZSJcPNE.mjs → authorizationDecision-BD8K4jdQ.mjs} +4 -4
  13. package/dist/{boundedMap-o2KZDCWy.mjs → boundedMap-CuCwos_X.mjs} +1 -1
  14. package/dist/{buildHandler-G3k59KY2.mjs → buildHandler-BttjNkTM.mjs} +23 -16
  15. package/dist/cache/index.d.mts +2 -2
  16. package/dist/cache/index.mjs +4 -4
  17. package/dist/{caching-CJIDPZOv.mjs → caching-CxUQLHfR.mjs} +3 -6
  18. package/dist/{claimed-D0A43wjT.mjs → claimed-CQ4ZpD8K.mjs} +1 -1
  19. package/dist/cleanup/index.d.mts +2 -2
  20. package/dist/cleanup/index.mjs +4 -4
  21. package/dist/cli/commands/describe.d.mts +1 -1
  22. package/dist/cli/commands/describe.mjs +3 -3
  23. package/dist/cli/commands/docs.mjs +3 -3
  24. package/dist/cli/commands/doctor.mjs +1 -1
  25. package/dist/cli/commands/generate.mjs +2 -2
  26. package/dist/cli/commands/init.mjs +2 -2
  27. package/dist/cli/commands/introspect.mjs +2 -2
  28. package/dist/cli/index.mjs +3 -3
  29. package/dist/{constants-D-faL5SX.mjs → constants-BZFsZwJh.mjs} +1 -1
  30. package/dist/context/index.mjs +5 -5
  31. package/dist/core/index.d.mts +3 -3
  32. package/dist/core/index.mjs +7 -7
  33. package/dist/{core-NSu1peyq.mjs → core-DWA1-5IE.mjs} +3 -3
  34. package/dist/{createActionRouter-DTSVv1VK.mjs → createActionRouter-fP3l2xVF.mjs} +54 -18
  35. package/dist/{createAggregationRouter-zEasm-ax.mjs → createAggregationRouter-BJZeOmBa.mjs} +13 -11
  36. package/dist/{createApp-CjqhkX1x.mjs → createApp-Db9JRumw.mjs} +332 -40
  37. package/dist/{createMcpServer-hSFeqRUb.d.mts → createMcpServer-CS2KOVP6.d.mts} +1 -1
  38. package/dist/{defineAggregation-DH2L6_v9.mjs → defineAggregation-BskqRz8M.mjs} +1 -1
  39. package/dist/{defineResource-zYCrhNaN.mjs → defineResource-B2vTvKzW.mjs} +8 -8
  40. package/dist/discovery/index.mjs +1 -1
  41. package/dist/docs/index.d.mts +1 -1
  42. package/dist/docs/index.mjs +3 -3
  43. package/dist/{elevation-z--rFcZ5.mjs → elevation-XoY0C73T.mjs} +6 -9
  44. package/dist/encryption/index.mjs +3 -3
  45. package/dist/{errorHandler-3_3oN-Uc.mjs → errorHandler-BYI-JQMm.mjs} +4 -7
  46. package/dist/{errors-DyY48oRi.mjs → errors-3xaK0i9n.mjs} +1 -1
  47. package/dist/{eventPlugin-Co9sABCg.mjs → eventPlugin-CVQ9ddnL.mjs} +9 -13
  48. package/dist/{eventTypes-HmAFyJmJ.mjs → eventTypes-UPYg7gW1.mjs} +2 -2
  49. package/dist/events/index.d.mts +18 -5
  50. package/dist/events/index.mjs +8 -8
  51. package/dist/events/transports/redis-stream-entry.mjs +4 -4
  52. package/dist/events/transports/redis.d.mts +35 -0
  53. package/dist/events/transports/redis.mjs +87 -11
  54. package/dist/factory/index.d.mts +4 -4
  55. package/dist/factory/index.mjs +6 -6
  56. package/dist/{fastify-augmentation-bzkWPt1f.d.mts → fastify-augmentation-baQc3MaO.d.mts} +2 -2
  57. package/dist/fieldTypes-CxRvCaaZ.mjs +80 -0
  58. package/dist/{fields-rfsl26Ov.mjs → fields-DLFcJiDe.mjs} +1 -1
  59. package/dist/{filter-merge-8glLr7Dk.mjs → filter-merge-Bvjk_8dV.mjs} +1 -1
  60. package/dist/{generate-BOfBueRt.mjs → generate-0OpCUjUv.mjs} +2 -2
  61. package/dist/{headers-CHSOqpcY.mjs → headers-BROW65-r.mjs} +2 -2
  62. package/dist/{health-ezwTHQh2.mjs → health-Cfh-kYI_.mjs} +1 -1
  63. package/dist/{health-DHvAIVmM.mjs → health-Cy6aOg1i.mjs} +1 -1
  64. package/dist/hooks/index.d.mts +1 -1
  65. package/dist/hooks/index.mjs +2 -2
  66. package/dist/http-cache/index.d.mts +2 -2
  67. package/dist/http-cache/index.mjs +4 -4
  68. package/dist/http-cache/purgers/cloudflare.mjs +2 -2
  69. package/dist/http-cache/purgers/fastly.mjs +2 -2
  70. package/dist/http-cache/testing/index.mjs +1 -1
  71. package/dist/idempotency/index.d.mts +1 -1
  72. package/dist/idempotency/index.mjs +10 -8
  73. package/dist/idempotency/redis.mjs +2 -2
  74. package/dist/{index-B5i9-vuP.d.mts → index-CMNpMBtW.d.mts} +1 -1
  75. package/dist/{index-BxZS-8So.d.mts → index-DKM2p5w5.d.mts} +48 -23
  76. package/dist/{index-Cy2-QffW.d.mts → index-DLCcLUQT.d.mts} +69 -6
  77. package/dist/{index-DFCCQ9AE.d.mts → index-DexdFs1a.d.mts} +1 -1
  78. package/dist/{index-D1X_C_qz.d.mts → index-Dhrks-hM.d.mts} +60 -10
  79. package/dist/index.d.mts +4 -4
  80. package/dist/index.mjs +11 -11
  81. package/dist/{init-MoE3eZNR.mjs → init-D7PQcvvL.mjs} +1 -1
  82. package/dist/integrations/event-gateway.mjs +2 -2
  83. package/dist/integrations/index.d.mts +2 -2
  84. package/dist/integrations/index.mjs +1 -1
  85. package/dist/integrations/jobs/index.mjs +3 -3
  86. package/dist/integrations/mcp/index.d.mts +5 -5
  87. package/dist/integrations/mcp/index.mjs +2 -2
  88. package/dist/integrations/mcp/testing.d.mts +2 -2
  89. package/dist/integrations/mcp/testing.mjs +2 -2
  90. package/dist/integrations/streamline.mjs +3 -3
  91. package/dist/integrations/webhooks.d.mts +1 -1
  92. package/dist/integrations/webhooks.mjs +4 -4
  93. package/dist/integrations/websocket-pushref-redis.mjs +1 -1
  94. package/dist/integrations/websocket-redis.mjs +1 -1
  95. package/dist/integrations/websocket.mjs +2 -2
  96. package/dist/{jsonBody-DZGiCawf.mjs → jsonBody-C0oREwUc.mjs} +2 -2
  97. package/dist/{keys-CrMOZuk6.mjs → keys-CGlPoVSn.mjs} +1 -1
  98. package/dist/{loadResources-CVQvYUhN.mjs → loadResources-Oi47dogA.mjs} +3 -3
  99. package/dist/{loadResourcesFromEntry-D0naccV2.mjs → loadResourcesFromEntry-BW-LexBz.mjs} +2 -2
  100. package/dist/logger/index.mjs +2 -2
  101. package/dist/{logger-VyMcSmVG.mjs → logger-BagW7_YA.mjs} +1 -1
  102. package/dist/{mcpPlugin-DQACaqVu.mjs → mcpPlugin-C6-wFsOX.mjs} +29 -26
  103. package/dist/{memory-Lpfu8Hga.mjs → memory-Bl7kv6TS.mjs} +3 -3
  104. package/dist/{metrics-DjVj1sg5.mjs → metrics-CqnMJKrJ.mjs} +4 -7
  105. package/dist/middleware/index.d.mts +1 -1
  106. package/dist/middleware/index.mjs +3 -3
  107. package/dist/migrations/index.mjs +2 -2
  108. package/dist/{module-BqPJpZ_L.mjs → module-lbEbHUfI.mjs} +1 -1
  109. package/dist/{multiTenant-KZj8j1uJ.d.mts → multiTenant-QtDzxx_K.d.mts} +1 -1
  110. package/dist/{multipartBody-BNgNv7r0.mjs → multipartBody-CqNezaB3.mjs} +1 -1
  111. package/dist/{observeSend-BKJHibJz.mjs → observeSend-BjilzlYl.mjs} +1 -1
  112. package/dist/{openapi-T90KrPR6.mjs → openapi-DXNbadgd.mjs} +7 -7
  113. package/dist/outbox-admin/index.d.mts +1 -1
  114. package/dist/outbox-admin/index.mjs +5 -5
  115. package/dist/{outbox-module-5Mnwcycy.d.mts → outbox-module-DzW6zwWJ.d.mts} +103 -10
  116. package/dist/{outbox-module-C874VgBr.mjs → outbox-module-k5rIszQ4.mjs} +197 -28
  117. package/dist/permissions/index.d.mts +2 -2
  118. package/dist/permissions/index.mjs +7 -7
  119. package/dist/{permissions-R9T2G1PH.mjs → permissions-BJylQopQ.mjs} +9 -9
  120. package/dist/{pipe-DzqbsZy-.mjs → pipe-D1cq8hET.mjs} +2 -2
  121. package/dist/pipeline/index.d.mts +1 -1
  122. package/dist/pipeline/index.mjs +2 -2
  123. package/dist/{plan-C0gkeABY.mjs → plan-iEgaS5_H.mjs} +1 -1
  124. package/dist/{plugin-BJcVOX5r.mjs → plugin-DsLr6L4O.mjs} +94 -50
  125. package/dist/plugins/index.d.mts +6 -5
  126. package/dist/plugins/index.mjs +19 -18
  127. package/dist/plugins/response-cache.mjs +4 -4
  128. package/dist/plugins/tracing-entry.mjs +2 -2
  129. package/dist/{pluralize-CrCpyoZs.mjs → pluralize-CX4ZvwCa.mjs} +1 -1
  130. package/dist/presets/filesUpload.d.mts +1 -1
  131. package/dist/presets/filesUpload.mjs +5 -5
  132. package/dist/presets/index.d.mts +2 -2
  133. package/dist/presets/index.mjs +2 -2
  134. package/dist/presets/multiTenant.d.mts +1 -1
  135. package/dist/presets/multiTenant.mjs +5 -5
  136. package/dist/presets/search.d.mts +1 -1
  137. package/dist/presets/search.mjs +2 -2
  138. package/dist/{presets-CNDvNYsz.mjs → presets-D_suT4OY.mjs} +4 -4
  139. package/dist/{projection-CIUe8b59.mjs → projection-CmjGjFih.mjs} +2 -2
  140. package/dist/{purger.types-f83fTzGy.mjs → purger.types-CZwkTZ7B.mjs} +1 -1
  141. package/dist/{queryCachePlugin-B2jpwFcv.mjs → queryCachePlugin-BDOPEAmH.mjs} +114 -14
  142. package/dist/{queryCachePlugin-DYQUyeJ9.d.mts → queryCachePlugin-DrQNnGws.d.mts} +1 -1
  143. package/dist/{rateLimitKey-BWx-qep0.mjs → rateLimitKey-igF1x64n.mjs} +1 -1
  144. package/dist/{realtime-D2tqi3d2.mjs → realtime-Cq_ugiWw.mjs} +75 -22
  145. package/dist/registry/index.d.mts +2 -2
  146. package/dist/registry/index.mjs +3 -3
  147. package/dist/{registry-Dl0k6UXy.mjs → registry-DmF9Akvn.mjs} +2 -2
  148. package/dist/{relay-ZYvS4xyW.mjs → relay-DA89IhFt.mjs} +200 -99
  149. package/dist/{renewingLease-DT4yLb29.mjs → renewingLease-DBtGUt8T.mjs} +1 -1
  150. package/dist/{replyHelpers-BJFN5AW7.mjs → replyHelpers-CUbeUc5q.mjs} +2 -2
  151. package/dist/{requestContext-Ct5la-SA.mjs → requestContext-DO9Qv0gw.mjs} +1 -1
  152. package/dist/{requirement-CxDxjB6V.mjs → requirement-C3GaQmkR.mjs} +1 -1
  153. package/dist/{resourceRateLimit-DCWglD7V.d.mts → resourceRateLimit-BPiESPtG.d.mts} +4 -0
  154. package/dist/{resourceRateLimit-D1oH2obv.mjs → resourceRateLimit-KKn-sFhb.mjs} +19 -4
  155. package/dist/{rolldown-runtime-BdTN42uL.mjs → rolldown-runtime-Ck1Tj4Ax.mjs} +1 -1
  156. package/dist/{routeValidator-DclDl5WJ.mjs → routeValidator-BF7n34xV.mjs} +47 -5
  157. package/dist/{runtimeCapabilities-ClWr60El.mjs → runtimeCapabilities-D0A4kkrC.mjs} +1 -1
  158. package/dist/{schedules-gVkRcs-9.mjs → schedules-CLrQRSTt.mjs} +6 -9
  159. package/dist/{schemaConverter-CIwB5wPO.mjs → schemaConverter-JEmU21fu.mjs} +2 -2
  160. package/dist/{actionPermissions-Dha8sAz2.mjs → schemaIR-wOffQlbq.mjs} +184 -16
  161. package/dist/schemas/index.mjs +1 -1
  162. package/dist/scim/index.mjs +2 -2
  163. package/dist/scope/index.d.mts +1 -1
  164. package/dist/scope/index.mjs +5 -5
  165. package/dist/{scope-VMZhdkbT.mjs → scope-CcTMRd7s.mjs} +4 -4
  166. package/dist/{shutdown-Bi19vH0z.mjs → shutdown-BIR-QBYM.mjs} +1 -1
  167. package/dist/{simpleEqualityMatcher-CaCS09fh.mjs → simpleEqualityMatcher-DqqJqovq.mjs} +1 -1
  168. package/dist/{sse-BqM359f1.mjs → sse-OEuPpgss.mjs} +9 -35
  169. package/dist/sseStats-DQqNN385.d.mts +112 -0
  170. package/dist/sseStream-DknHE2K5.mjs +166 -0
  171. package/dist/{store-helpers-rx-F2ZGR.mjs → store-helpers-D4vtEXt2.mjs} +1 -1
  172. package/dist/{streaming-CPChx3A7.mjs → streaming-CcIpcx02.mjs} +1 -1
  173. package/dist/{subscriberIdentity-CYNYw8p_.mjs → subscriberIdentity-PO6kimAl.mjs} +1 -1
  174. package/dist/{tenancy-BoWImS3K.mjs → tenancy-CH2Kuksc.mjs} +2 -2
  175. package/dist/{tenantPreparation-oqKCZQZM.mjs → tenantPreparation-BTGpblQW.mjs} +4 -4
  176. package/dist/testing/cleanupStoreContract.mjs +1 -1
  177. package/dist/testing/index.d.mts +4 -4
  178. package/dist/testing/index.mjs +324 -17
  179. package/dist/testing/outboxStoreContract.mjs +2 -2
  180. package/dist/testing/requiredPorts.mjs +2 -2
  181. package/dist/testing/storageContract.mjs +1 -1
  182. package/dist/{timing-Dsteq59c.mjs → timing-Dii5X7AP.mjs} +1 -1
  183. package/dist/{transactionContext-C1OgH-hW.mjs → transactionContext-DMPhYEOt.mjs} +1 -1
  184. package/dist/{typeGuards-DNlpASzd.mjs → typeGuards-C1o_XEyp.mjs} +1 -1
  185. package/dist/types/index.d.mts +1 -1
  186. package/dist/types/index.mjs +1 -1
  187. package/dist/types/storage.mjs +1 -1
  188. package/dist/{types-DduBiYaI.d.mts → types-B4E0sc6D.d.mts} +2 -2
  189. package/dist/{types-HFFSwF_K.mjs → types-BuV_cFqT.mjs} +4 -4
  190. package/dist/usage/index.d.mts +1 -1
  191. package/dist/usage/index.mjs +7 -7
  192. package/dist/{userHelpers-N-k-8dNF.mjs → userHelpers-D4m_pLSC.mjs} +1 -1
  193. package/dist/utils/index.d.mts +193 -34
  194. package/dist/utils/index.mjs +13 -13
  195. package/dist/{utils-C7w_RVlx.mjs → utils-CxLMXGn5.mjs} +761 -8
  196. package/dist/{validate-Brr4b_fH.mjs → validate-CZ975J8N.mjs} +3 -3
  197. package/dist/{versioning-S18y2-0C.d.mts → versioning-B07RgD27.d.mts} +2 -13
  198. package/dist/{versioning-CE5kdWOY.mjs → versioning-B2_8SBZo.mjs} +4 -7
  199. package/dist/{workScope-A3XBpYTa.mjs → workScope-B3W3r35s.mjs} +2 -2
  200. package/llms.txt +2 -2
  201. package/package.json +34 -34
  202. package/skills/arc/references/api-reference.md +2 -2
  203. package/skills/arc/references/auth-better-auth.md +1 -0
  204. package/skills/arc/references/events-outbox.md +7 -4
  205. package/skills/arc/references/events.md +2 -2
  206. package/skills/arc/references/production-api.md +4 -0
  207. package/skills/arc/references/production-boot.md +2 -0
  208. package/skills/arc/references/production-idempotency.md +1 -1
  209. package/skills/arc/references/production-realtime.md +28 -2
  210. package/skills/arc/references/validation.md +4 -0
  211. package/skills/arc/references/writes-hooks-errors.md +1 -0
  212. package/dist/schemaIR-A0IoD05P.mjs +0 -108
  213. package/dist/sseStream-qSa-F2Qm.mjs +0 -57
@@ -1,9 +1,9 @@
1
- /*! @classytic/arc v2.48.0 | MIT | https://classytic.com */
2
- import { t as __exportAll } from "./rolldown-runtime-BdTN42uL.mjs";
3
- import { i as versionKey, r as tagVersionKey } from "./keys-CrMOZuk6.mjs";
4
- import { n as declareRuntimeCapability } from "./runtimeCapabilities-ClWr60El.mjs";
5
- import { t as hasEvents } from "./typeGuards-DNlpASzd.mjs";
6
- import { t as MemoryCacheStore } from "./memory-Lpfu8Hga.mjs";
1
+ /*! @classytic/arc v2.50.0 | MIT | https://classytic.com */
2
+ import { t as __exportAll } from "./rolldown-runtime-Ck1Tj4Ax.mjs";
3
+ import { n as declareRuntimeCapability } from "./runtimeCapabilities-D0A4kkrC.mjs";
4
+ import { t as hasEvents } from "./typeGuards-C1o_XEyp.mjs";
5
+ import { t as MemoryCacheStore } from "./memory-Bl7kv6TS.mjs";
6
+ import { i as versionKey, r as tagVersionKey } from "./keys-CGlPoVSn.mjs";
7
7
  import fp from "fastify-plugin";
8
8
  // src/cache/QueryCache.ts
9
9
  const MISS = Object.freeze({
@@ -12,15 +12,31 @@ const MISS = Object.freeze({
12
12
  });
13
13
  var QueryCache = class {
14
14
  store;
15
- constructor(store) {
15
+ onStoreError;
16
+ /** Entry deletes the store refused: read as a miss here until replayed. */
17
+ pendingDeletes = /* @__PURE__ */ new Set();
18
+ /** Version keys whose bump the store refused: bumped once each when it answers again. */
19
+ pendingBumps = /* @__PURE__ */ new Set();
20
+ failing = false;
21
+ flushing;
22
+ constructor(store, options = {}) {
16
23
  this.store = store;
24
+ this.onStoreError = options.onStoreError;
17
25
  }
18
26
  async get(key) {
19
- const envelope = await this.store.get(key);
27
+ if (!await this.recovered() || this.pendingDeletes.has(key)) return MISS;
28
+ let envelope;
29
+ try {
30
+ envelope = await this.store.get(key);
31
+ this.ok();
32
+ } catch (err) {
33
+ this.failed(err, "get");
34
+ return MISS;
35
+ }
20
36
  if (!envelope?.createdAt) return MISS;
21
37
  const now = Date.now();
22
38
  if (now >= envelope.expiresAt) {
23
- await this.store.delete(key);
39
+ await this.invalidate(key);
24
40
  return MISS;
25
41
  }
26
42
  if (now < envelope.staleAfter) return {
@@ -45,14 +61,27 @@ var QueryCache = class {
45
61
  expiresAt: now + totalTtlSec * 1e3,
46
62
  tags: config.tags ?? []
47
63
  };
48
- await this.store.set(key, envelope, totalTtlSec);
64
+ try {
65
+ await this.store.set(key, envelope, totalTtlSec);
66
+ this.pendingDeletes.delete(key);
67
+ this.ok();
68
+ } catch (err) {
69
+ this.failed(err, "set");
70
+ }
49
71
  }
50
72
  async invalidate(key) {
51
- await this.store.delete(key);
73
+ try {
74
+ await this.store.delete(key);
75
+ this.pendingDeletes.delete(key);
76
+ this.ok();
77
+ } catch (err) {
78
+ this.pendingDeletes.add(key);
79
+ this.failed(err, "invalidate");
80
+ }
52
81
  }
53
82
  /** Get current version for a resource (defaults to 0 if not set) */
54
83
  async getResourceVersion(resource) {
55
- return await this.store.get(versionKey(resource)) ?? 0;
84
+ return this.readVersion(versionKey(resource));
56
85
  }
57
86
  /** Bump resource version — orphans all cached queries for this resource */
58
87
  async bumpResourceVersion(resource) {
@@ -60,12 +89,32 @@ var QueryCache = class {
60
89
  }
61
90
  /** Get current version for a tag */
62
91
  async getTagVersion(tag) {
63
- return await this.store.get(tagVersionKey(tag)) ?? 0;
92
+ return this.readVersion(tagVersionKey(tag));
64
93
  }
65
94
  /** Bump tag version — orphans all cached queries tagged with this tag */
66
95
  async bumpTagVersion(tag) {
67
96
  await this.bumpVersion(tagVersionKey(tag));
68
97
  }
98
+ /** The store is failing, or holds invalidations it refused: reads go to the source. */
99
+ get degraded() {
100
+ return this.failing || this.pendingDeletes.size > 0 || this.pendingBumps.size > 0;
101
+ }
102
+ /**
103
+ * A version the store cannot give is 0: entries are not read while it fails either, and
104
+ * a version bump it refused is replayed before any version is read again (`recovered`),
105
+ * so an entry cached before the outage is never served past an invalidation.
106
+ */
107
+ async readVersion(key) {
108
+ if (!await this.recovered()) return 0;
109
+ try {
110
+ const ver = await this.store.get(key);
111
+ this.ok();
112
+ return ver ?? 0;
113
+ } catch (err) {
114
+ this.failed(err, "version");
115
+ return 0;
116
+ }
117
+ }
69
118
  /**
70
119
  * Version-bump semantics:
71
120
  *
@@ -87,8 +136,20 @@ var QueryCache = class {
87
136
  * outlive that reset and entry TTLs are minutes-scale (staleTime +
88
137
  * gcTime). The read-modify-write fallback uses plain `set`, which
89
138
  * refreshes the TTL per bump — strictly longer-lived, equally safe.
139
+ *
140
+ * A bump the store refuses is remembered and replayed once it answers.
90
141
  */
91
142
  async bumpVersion(key) {
143
+ try {
144
+ await this.rawBump(key);
145
+ this.pendingBumps.delete(key);
146
+ this.ok();
147
+ } catch (err) {
148
+ this.pendingBumps.add(key);
149
+ this.failed(err, "bump");
150
+ }
151
+ }
152
+ async rawBump(key) {
92
153
  if (typeof this.store.increment === "function") {
93
154
  await this.store.increment(key, 1, VERSION_TTL_SECONDS);
94
155
  return;
@@ -97,6 +158,42 @@ var QueryCache = class {
97
158
  const next = Math.max(Date.now(), (current ?? 0) + 1);
98
159
  await this.store.set(key, next, VERSION_TTL_SECONDS);
99
160
  }
161
+ /**
162
+ * Replay refused invalidations before a read; `false` while the store still refuses a
163
+ * version bump (the caller then answers from the source). One replay at a time.
164
+ */
165
+ async recovered() {
166
+ if (this.pendingBumps.size === 0 && this.pendingDeletes.size === 0) return true;
167
+ this.flushing ??= this.flush().finally(() => {
168
+ this.flushing = void 0;
169
+ });
170
+ await this.flushing;
171
+ return this.pendingBumps.size === 0;
172
+ }
173
+ async flush() {
174
+ try {
175
+ for (const key of [...this.pendingBumps]) {
176
+ await this.rawBump(key);
177
+ this.pendingBumps.delete(key);
178
+ }
179
+ for (const key of [...this.pendingDeletes]) {
180
+ await this.store.delete(key);
181
+ this.pendingDeletes.delete(key);
182
+ }
183
+ this.ok();
184
+ } catch (err) {
185
+ this.failed(err, "replay");
186
+ }
187
+ }
188
+ ok() {
189
+ this.failing = false;
190
+ }
191
+ failed(err, operation) {
192
+ if (!this.failing) try {
193
+ this.onStoreError?.(err, operation);
194
+ } catch {}
195
+ this.failing = true;
196
+ }
100
197
  };
101
198
  /** See `bumpVersion` — effectively non-expiring, refreshed on every bump. */
102
199
  const VERSION_TTL_SECONDS = 31536e3;
@@ -110,7 +207,10 @@ const CRUD_SUFFIXES = /* @__PURE__ */ new Set([
110
207
  const queryCachePluginImpl = async (fastify, opts = {}) => {
111
208
  const ownsStore = opts.store === void 0;
112
209
  const store = opts.store ?? new MemoryCacheStore();
113
- const queryCache = new QueryCache(store);
210
+ const queryCache = new QueryCache(store, { onStoreError: (err, operation) => fastify.log.warn({
211
+ err: err instanceof Error ? err.message : String(err),
212
+ operation
213
+ }, "[arc] query cache store unavailable: reading from the source until it answers again") });
114
214
  declareRuntimeCapability(fastify, {
115
215
  subsystem: "cache.query",
116
216
  durability: store instanceof MemoryCacheStore ? "memory" : "shared",
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { r as CacheStore } from "./interface-WR1U0K7t.mjs";
3
- import { i as QueryCache } from "./QueryCache-DdvrGG8Q.mjs";
3
+ import { i as QueryCache } from "./QueryCache-BE47tmlO.mjs";
4
4
  import { FastifyPluginAsync } from "fastify";
5
5
  interface QueryCachePluginOptions {
6
6
  /** CacheStore instance. Default: MemoryCacheStore with default options. */
@@ -1,4 +1,4 @@
1
- /*! @classytic/arc v2.48.0 | MIT | https://classytic.com */
1
+ /*! @classytic/arc v2.50.0 | MIT | https://classytic.com */
2
2
  // src/scope/rateLimitKey.ts
3
3
  /**
4
4
  * Marks a key generator as SCOPE-AWARE, so `buildRateLimitOpts` can place the rate-limit
@@ -1,25 +1,73 @@
1
- /*! @classytic/arc v2.48.0 | MIT | https://classytic.com */
2
- import { t as __exportAll } from "./rolldown-runtime-BdTN42uL.mjs";
3
- import { t as arcLog } from "./logger-VyMcSmVG.mjs";
4
- import { t as simpleEqualityMatcher } from "./simpleEqualityMatcher-CaCS09fh.mjs";
5
- import { n as getUserRoles } from "./userHelpers-N-k-8dNF.mjs";
6
- import { n as isEventVisible, t as eventAudienceOf } from "./tenancy-BoWImS3K.mjs";
7
- import { t as applyFieldReadPermissions } from "./fields-rfsl26Ov.mjs";
8
- import { a as promoteStreamTokenToHeader } from "./streaming-CPChx3A7.mjs";
9
- import { n as evaluateAndApplyPermission } from "./authorizationDecision-BZSJcPNE.mjs";
10
- import { t as openSseStream } from "./sseStream-qSa-F2Qm.mjs";
11
- import { n as arcRouteValidatorCompiler } from "./routeValidator-DclDl5WJ.mjs";
1
+ /*! @classytic/arc v2.50.0 | MIT | https://classytic.com */
2
+ import { t as __exportAll } from "./rolldown-runtime-Ck1Tj4Ax.mjs";
3
+ import { n as arcRouteValidatorCompiler } from "./routeValidator-BF7n34xV.mjs";
4
+ import { n as isEventVisible, t as eventAudienceOf } from "./tenancy-CH2Kuksc.mjs";
5
+ import { t as arcLog } from "./logger-BagW7_YA.mjs";
6
+ import { n as evaluateAndApplyPermission } from "./authorizationDecision-BD8K4jdQ.mjs";
7
+ import { t as applyFieldReadPermissions } from "./fields-DLFcJiDe.mjs";
8
+ import { n as getUserRoles } from "./userHelpers-D4m_pLSC.mjs";
9
+ import { t as simpleEqualityMatcher } from "./simpleEqualityMatcher-DqqJqovq.mjs";
10
+ import { a as registerSseStats, r as openSseStream } from "./sseStream-DknHE2K5.mjs";
11
+ import { a as promoteStreamTokenToHeader } from "./streaming-CcIpcx02.mjs";
12
+ import { STREAM_FRAMES } from "@classytic/repo-core/sync";
12
13
  import fp from "fastify-plugin";
13
14
  // src/plugins/realtime.ts
14
- var realtime_exports = /* @__PURE__ */ __exportAll({
15
- DEFAULT_MAX_CONNECTION_MS: () => DEFAULT_MAX_CONNECTION_MS,
16
- buildChangeFrame: () => buildChangeFrame,
17
- connectionDeadlineMs: () => connectionDeadlineMs,
18
- default: () => realtime_default,
19
- realtimePlugin: () => realtimePlugin,
20
- resolveDelivery: () => resolveDelivery,
21
- resolveRowMatcher: () => resolveRowMatcher
22
- });
15
+ /**
16
+ * Realtime Plugin — permission-aware resource change subscriptions.
17
+ *
18
+ * `GET /realtime/:resource` (`:resource` = the resource NAME — the
19
+ * singular registry key, same identity MCP tools and introspection use,
20
+ * NOT the pluralized route prefix) streams that resource's CRUD events
21
+ * (`{resource}.created/.updated/.deleted`, emitted by arc's own event
22
+ * bridge) over SSE, gated and filtered by the SAME machinery that guards
23
+ * the REST routes:
24
+ *
25
+ * 1. CONNECT gate — the resource's `list` permission runs once; its row
26
+ * filters (`_policyFilters`) are snapshotted for the connection.
27
+ * 2. PER-EVENT filtering — matched against that snapshot IN PROCESS
28
+ * (adapter `matchesFilter`, else `simpleEqualityMatcher`). No per-event
29
+ * DB round-trip.
30
+ * 3. TENANT guard — an event carrying `organizationId` reaches only
31
+ * matching scopes, fail-closed for org-less callers, unless the resource
32
+ * set `tenantField: false`.
33
+ * 4. FIELD masking — per subscriber roles, so gated fields never hit the wire.
34
+ *
35
+ * FAIL-CLOSED: operator-shaped filters (`$or`/`$in`, e.g. from `requireGrant`)
36
+ * with no adapter `matchesFilter` REJECT the subscription at connect (501 +
37
+ * hint) rather than delivering unfiltered rows. Unmatchable events are dropped.
38
+ *
39
+ * MULTIPLEXING: `?resources=a,b,c` carries N feeds on one connection (cap
40
+ * {@link MAX_MULTIPLEX_RESOURCES}). Each is authorized independently with an
41
+ * ISOLATED snapshot; any denial rejects the whole subscription.
42
+ *
43
+ * `<resource>.left` is emitted when an update moves a record OUT of a
44
+ * subscriber's filter, so the client can drop a now-invisible row. Entering
45
+ * needs no frame — the `updated` frame carries the record.
46
+ *
47
+ * STALENESS: filters snapshot at connect, so revoked permissions persist until
48
+ * reconnect. The feed force-closes at the token's `exp`; `maxConnectionMs`
49
+ * bounds session/cookie auth that has none.
50
+ *
51
+ * NON-GOALS: no replay/resume (a change NOTIFIER, not an event store — use the
52
+ * outbox for guaranteed delivery, or `createReplayHub` from `@classytic/arc/utils`
53
+ * for a resumable custom stream over a repo-core `ChangeLogStore`); filters
54
+ * must be CONCRETE at connect, since a rule referencing a row absent from the payload cannot be evaluated in
55
+ * process; no presence/broadcast (`app.events` + sse cover that); no payload
56
+ * E2EE (TLS + field masking is the posture). Delivery is per-instance and
57
+ * follows the transport's semantics.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const app = await createApp({
62
+ * arcPlugins: { realtime: true }, // or { path, heartbeat, resources: [...] }
63
+ * resources: [orderResource],
64
+ * });
65
+ * // Browser:
66
+ * new EventSource(`/realtime/order?token=${jwt}`) // resource NAME
67
+ * .addEventListener('order.updated', (e) => render(JSON.parse(e.data)));
68
+ * ```
69
+ */
70
+ var realtime_exports = /* @__PURE__ */ __exportAll({ default: () => realtime_default });
23
71
  const log = arcLog("realtime");
24
72
  const CHANGE_OPERATIONS = [
25
73
  "created",
@@ -166,6 +214,10 @@ const realtimePlugin = async (fastify, opts = {}) => {
166
214
  }
167
215
  if (!path.includes(":resource")) throw new Error(`[arc-realtime] path must contain ':resource' (got '${path}')`);
168
216
  const activeConnections = /* @__PURE__ */ new Set();
217
+ registerSseStats(fastify, () => ({
218
+ connections: activeConnections.size,
219
+ keys: 0
220
+ }));
169
221
  const isProtected = (entry) => {
170
222
  const listCheck = entry.permissions?.list;
171
223
  return typeof listCheck === "function" && listCheck._isPublic !== true;
@@ -291,9 +343,10 @@ const realtimePlugin = async (fastify, opts = {}) => {
291
343
  stream.onCleanup(unsub);
292
344
  }
293
345
  }
294
- stream.write("ready", JSON.stringify({
346
+ stream.write(STREAM_FRAMES.READY, JSON.stringify({
295
347
  resources: subscriptions.map((s) => s.name),
296
- operations: [...operations]
348
+ operations: [...operations],
349
+ resumed: false
297
350
  }));
298
351
  };
299
352
  const lookupEntry = (name) => {
@@ -1,6 +1,6 @@
1
1
 
2
- import { F as ResourceDefinition, G as CrudRouteKey, M as ResourceRegistry, N as RouteRow, S as IntrospectionPluginOptions, V as ResolvedTenantPurge, j as RegisterOptions, o as RegistryEntry } from "../index-Cy2-QffW.mjs";
3
- import "../fastify-augmentation-bzkWPt1f.mjs";
2
+ import "../fastify-augmentation-baQc3MaO.mjs";
3
+ import { F as ResourceDefinition, G as CrudRouteKey, M as ResourceRegistry, N as RouteRow, S as IntrospectionPluginOptions, V as ResolvedTenantPurge, j as RegisterOptions, o as RegistryEntry } from "../index-DLCcLUQT.mjs";
4
4
  import { TenantPurgeProgress, TenantPurgeStrategy } from "@classytic/repo-core/repository";
5
5
  import { FastifyPluginAsync } from "fastify";
6
6
  interface AssertNoTenantDataOptions {
@@ -1,4 +1,4 @@
1
- /*! @classytic/arc v2.48.0 | MIT | https://classytic.com */
2
- import { a as getCascadingResources, i as cascadeDeleteForOrganization, n as buildResourceManifestFromRegistry, o as getCascadingResourcesWithMetadata, r as introspectionPlugin_default, s as assertNoTenantData, t as buildResourceManifest } from "../registry-Dl0k6UXy.mjs";
3
- import { t as ResourceRegistry } from "../ResourceRegistry-BcvEJoZd.mjs";
1
+ /*! @classytic/arc v2.50.0 | MIT | https://classytic.com */
2
+ import { a as getCascadingResources, i as cascadeDeleteForOrganization, n as buildResourceManifestFromRegistry, o as getCascadingResourcesWithMetadata, r as introspectionPlugin_default, s as assertNoTenantData, t as buildResourceManifest } from "../registry-DmF9Akvn.mjs";
3
+ import { t as ResourceRegistry } from "../ResourceRegistry-C5NM07fZ.mjs";
4
4
  export { ResourceRegistry, assertNoTenantData, buildResourceManifest, buildResourceManifestFromRegistry, cascadeDeleteForOrganization, getCascadingResources, getCascadingResourcesWithMetadata, introspectionPlugin_default as introspectionPlugin };
@@ -1,5 +1,5 @@
1
- /*! @classytic/arc v2.48.0 | MIT | https://classytic.com */
2
- import { t as CRUD_OPERATIONS } from "./constants-D-faL5SX.mjs";
1
+ /*! @classytic/arc v2.50.0 | MIT | https://classytic.com */
2
+ import { t as CRUD_OPERATIONS } from "./constants-BZFsZwJh.mjs";
3
3
  import fp from "fastify-plugin";
4
4
  // src/registry/assertNoTenantData.ts
5
5
  /**