@classytic/arc 2.48.0 → 2.49.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.
- package/dist/{EventTransport-BWwg5YAU.mjs → EventTransport-DbHZK230.mjs} +2 -2
- package/dist/{HookSystem-B9x-Y_k7.mjs → HookSystem-DMoeJ6Do.mjs} +2 -2
- package/dist/{QueryCache-DdvrGG8Q.d.mts → QueryCache-BE47tmlO.d.mts} +36 -1
- package/dist/{ResourceRegistry-BcvEJoZd.mjs → ResourceRegistry-CP-iTcKy.mjs} +2 -2
- package/dist/{acquire-D2yj6Zzl.mjs → acquire-CB0va87C.mjs} +1 -1
- package/dist/audit/index.d.mts +1 -1
- package/dist/audit/index.mjs +4 -4
- package/dist/auth/audit.mjs +1 -1
- package/dist/auth/index.d.mts +2 -2
- package/dist/auth/index.mjs +53 -15
- package/dist/auth/redis-session.mjs +1 -1
- package/dist/{authorizationDecision-BZSJcPNE.mjs → authorizationDecision-DHO94aV2.mjs} +4 -4
- package/dist/{boundedMap-o2KZDCWy.mjs → boundedMap-C51EUUOm.mjs} +1 -1
- package/dist/{buildHandler-G3k59KY2.mjs → buildHandler-9DuwEKvr.mjs} +23 -16
- package/dist/cache/index.d.mts +2 -2
- package/dist/cache/index.mjs +4 -4
- package/dist/{caching-CJIDPZOv.mjs → caching-COTX3sDa.mjs} +3 -6
- package/dist/{claimed-D0A43wjT.mjs → claimed-C7T1nHlo.mjs} +1 -1
- package/dist/cleanup/index.d.mts +2 -2
- package/dist/cleanup/index.mjs +4 -4
- package/dist/cli/commands/describe.d.mts +1 -1
- package/dist/cli/commands/describe.mjs +3 -3
- package/dist/cli/commands/docs.mjs +3 -3
- package/dist/cli/commands/doctor.mjs +1 -1
- package/dist/cli/commands/generate.mjs +2 -2
- package/dist/cli/commands/init.mjs +2 -2
- package/dist/cli/commands/introspect.mjs +2 -2
- package/dist/cli/index.mjs +3 -3
- package/dist/{constants-D-faL5SX.mjs → constants-DOnfMd7i.mjs} +1 -1
- package/dist/context/index.mjs +5 -5
- package/dist/core/index.d.mts +3 -3
- package/dist/core/index.mjs +7 -7
- package/dist/{core-NSu1peyq.mjs → core-BoEdFDDw.mjs} +3 -3
- package/dist/{createActionRouter-DTSVv1VK.mjs → createActionRouter-CpTn15dm.mjs} +54 -18
- package/dist/{createAggregationRouter-zEasm-ax.mjs → createAggregationRouter-CD_Hydp0.mjs} +13 -11
- package/dist/{createApp-CjqhkX1x.mjs → createApp-Be6XTGD9.mjs} +332 -40
- package/dist/{createMcpServer-hSFeqRUb.d.mts → createMcpServer-CS2KOVP6.d.mts} +1 -1
- package/dist/{defineAggregation-DH2L6_v9.mjs → defineAggregation-BI5pRb8c.mjs} +1 -1
- package/dist/{defineResource-zYCrhNaN.mjs → defineResource-BAzNu5Um.mjs} +8 -8
- package/dist/discovery/index.mjs +1 -1
- package/dist/docs/index.d.mts +1 -1
- package/dist/docs/index.mjs +3 -3
- package/dist/{elevation-z--rFcZ5.mjs → elevation-DupGuM41.mjs} +6 -9
- package/dist/encryption/index.mjs +3 -3
- package/dist/{errorHandler-3_3oN-Uc.mjs → errorHandler-DA03vRqp.mjs} +4 -7
- package/dist/{errors-DyY48oRi.mjs → errors-BpYV859Y.mjs} +1 -1
- package/dist/{eventPlugin-Co9sABCg.mjs → eventPlugin-D7LYtYzL.mjs} +9 -13
- package/dist/{eventTypes-HmAFyJmJ.mjs → eventTypes-BqA-N-Uz.mjs} +2 -2
- package/dist/events/index.d.mts +18 -5
- package/dist/events/index.mjs +8 -8
- package/dist/events/transports/redis-stream-entry.mjs +4 -4
- package/dist/events/transports/redis.d.mts +35 -0
- package/dist/events/transports/redis.mjs +87 -11
- package/dist/factory/index.d.mts +4 -4
- package/dist/factory/index.mjs +6 -6
- package/dist/{fastify-augmentation-bzkWPt1f.d.mts → fastify-augmentation-baQc3MaO.d.mts} +2 -2
- package/dist/fieldTypes-EFWxCkZ5.mjs +80 -0
- package/dist/{fields-rfsl26Ov.mjs → fields-CT1Erg7o.mjs} +1 -1
- package/dist/{filter-merge-8glLr7Dk.mjs → filter-merge-B1eJ1pMx.mjs} +1 -1
- package/dist/{generate-BOfBueRt.mjs → generate-Cr0ULavs.mjs} +2 -2
- package/dist/{headers-CHSOqpcY.mjs → headers-D4bncIOf.mjs} +2 -2
- package/dist/{health-ezwTHQh2.mjs → health-BoFxrkJE.mjs} +1 -1
- package/dist/{health-DHvAIVmM.mjs → health-DN_pUVMX.mjs} +1 -1
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.mjs +2 -2
- package/dist/http-cache/index.d.mts +2 -2
- package/dist/http-cache/index.mjs +4 -4
- package/dist/http-cache/purgers/cloudflare.mjs +2 -2
- package/dist/http-cache/purgers/fastly.mjs +2 -2
- package/dist/http-cache/testing/index.mjs +1 -1
- package/dist/idempotency/index.d.mts +1 -1
- package/dist/idempotency/index.mjs +10 -8
- package/dist/idempotency/redis.mjs +2 -2
- package/dist/{index-B5i9-vuP.d.mts → index-CMNpMBtW.d.mts} +1 -1
- package/dist/{index-BxZS-8So.d.mts → index-DKM2p5w5.d.mts} +48 -23
- package/dist/{index-Cy2-QffW.d.mts → index-DLCcLUQT.d.mts} +69 -6
- package/dist/{index-DFCCQ9AE.d.mts → index-DexdFs1a.d.mts} +1 -1
- package/dist/{index-D1X_C_qz.d.mts → index-Dhrks-hM.d.mts} +60 -10
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +11 -11
- package/dist/{init-MoE3eZNR.mjs → init-C4a24wD2.mjs} +1 -1
- package/dist/integrations/event-gateway.mjs +2 -2
- package/dist/integrations/index.d.mts +2 -2
- package/dist/integrations/index.mjs +1 -1
- package/dist/integrations/jobs/index.mjs +3 -3
- package/dist/integrations/mcp/index.d.mts +5 -5
- package/dist/integrations/mcp/index.mjs +2 -2
- package/dist/integrations/mcp/testing.d.mts +2 -2
- package/dist/integrations/mcp/testing.mjs +2 -2
- package/dist/integrations/streamline.mjs +3 -3
- package/dist/integrations/webhooks.d.mts +1 -1
- package/dist/integrations/webhooks.mjs +4 -4
- package/dist/integrations/websocket-pushref-redis.mjs +1 -1
- package/dist/integrations/websocket-redis.mjs +1 -1
- package/dist/integrations/websocket.mjs +2 -2
- package/dist/{jsonBody-DZGiCawf.mjs → jsonBody-DoTt5BS6.mjs} +2 -2
- package/dist/{keys-CrMOZuk6.mjs → keys--l9n7aOC.mjs} +1 -1
- package/dist/{loadResources-CVQvYUhN.mjs → loadResources-rygByIQA.mjs} +3 -3
- package/dist/{loadResourcesFromEntry-D0naccV2.mjs → loadResourcesFromEntry-ItNBIQ5w.mjs} +2 -2
- package/dist/logger/index.mjs +2 -2
- package/dist/{logger-VyMcSmVG.mjs → logger-UbknHqHy.mjs} +1 -1
- package/dist/{mcpPlugin-DQACaqVu.mjs → mcpPlugin-CTkk4RP8.mjs} +29 -26
- package/dist/{memory-Lpfu8Hga.mjs → memory-C47xVsjX.mjs} +3 -3
- package/dist/{metrics-DjVj1sg5.mjs → metrics-TJyAb1Xk.mjs} +4 -7
- package/dist/middleware/index.d.mts +1 -1
- package/dist/middleware/index.mjs +3 -3
- package/dist/migrations/index.mjs +2 -2
- package/dist/{module-BqPJpZ_L.mjs → module-CWiqsXnh.mjs} +1 -1
- package/dist/{multiTenant-KZj8j1uJ.d.mts → multiTenant-QtDzxx_K.d.mts} +1 -1
- package/dist/{multipartBody-BNgNv7r0.mjs → multipartBody-BdG1qbn1.mjs} +1 -1
- package/dist/{observeSend-BKJHibJz.mjs → observeSend-DrA3ADFN.mjs} +1 -1
- package/dist/{openapi-T90KrPR6.mjs → openapi-D6MAbYpv.mjs} +7 -7
- package/dist/outbox-admin/index.d.mts +1 -1
- package/dist/outbox-admin/index.mjs +5 -5
- package/dist/{outbox-module-C874VgBr.mjs → outbox-module-D5QABFQW.mjs} +197 -28
- package/dist/{outbox-module-5Mnwcycy.d.mts → outbox-module-DzW6zwWJ.d.mts} +103 -10
- package/dist/permissions/index.d.mts +2 -2
- package/dist/permissions/index.mjs +7 -7
- package/dist/{permissions-R9T2G1PH.mjs → permissions-CFsmdYUt.mjs} +9 -9
- package/dist/{pipe-DzqbsZy-.mjs → pipe-B_05AgGt.mjs} +2 -2
- package/dist/pipeline/index.d.mts +1 -1
- package/dist/pipeline/index.mjs +2 -2
- package/dist/{plan-C0gkeABY.mjs → plan-BnlNJhrj.mjs} +1 -1
- package/dist/{plugin-BJcVOX5r.mjs → plugin-CrMPYbdj.mjs} +94 -50
- package/dist/plugins/index.d.mts +6 -5
- package/dist/plugins/index.mjs +19 -18
- package/dist/plugins/response-cache.mjs +4 -4
- package/dist/plugins/tracing-entry.mjs +2 -2
- package/dist/{pluralize-CrCpyoZs.mjs → pluralize-oVIxJ4CY.mjs} +1 -1
- package/dist/presets/filesUpload.d.mts +1 -1
- package/dist/presets/filesUpload.mjs +5 -5
- package/dist/presets/index.d.mts +2 -2
- package/dist/presets/index.mjs +2 -2
- package/dist/presets/multiTenant.d.mts +1 -1
- package/dist/presets/multiTenant.mjs +5 -5
- package/dist/presets/search.d.mts +1 -1
- package/dist/presets/search.mjs +2 -2
- package/dist/{presets-CNDvNYsz.mjs → presets-CUd3L7v6.mjs} +4 -4
- package/dist/{projection-CIUe8b59.mjs → projection-DowJlIto.mjs} +2 -2
- package/dist/{purger.types-f83fTzGy.mjs → purger.types-BjKy8869.mjs} +1 -1
- package/dist/{queryCachePlugin-B2jpwFcv.mjs → queryCachePlugin-BvB3k_Fh.mjs} +114 -14
- package/dist/{queryCachePlugin-DYQUyeJ9.d.mts → queryCachePlugin-DrQNnGws.d.mts} +1 -1
- package/dist/{rateLimitKey-BWx-qep0.mjs → rateLimitKey-56nH1cWN.mjs} +1 -1
- package/dist/{realtime-D2tqi3d2.mjs → realtime-DXGBPtYK.mjs} +19 -22
- package/dist/registry/index.d.mts +2 -2
- package/dist/registry/index.mjs +3 -3
- package/dist/{registry-Dl0k6UXy.mjs → registry-Biz-6sEZ.mjs} +2 -2
- package/dist/{relay-ZYvS4xyW.mjs → relay-DEIoMntZ.mjs} +200 -99
- package/dist/{renewingLease-DT4yLb29.mjs → renewingLease-BCJpW9-u.mjs} +1 -1
- package/dist/{replyHelpers-BJFN5AW7.mjs → replyHelpers-DliJNb0-.mjs} +2 -2
- package/dist/{requestContext-Ct5la-SA.mjs → requestContext-tUgLt9Ky.mjs} +1 -1
- package/dist/{requirement-CxDxjB6V.mjs → requirement-0l2DApiQ.mjs} +1 -1
- package/dist/{resourceRateLimit-DCWglD7V.d.mts → resourceRateLimit-BPiESPtG.d.mts} +4 -0
- package/dist/{resourceRateLimit-D1oH2obv.mjs → resourceRateLimit-iSXF8rLH.mjs} +19 -4
- package/dist/{rolldown-runtime-BdTN42uL.mjs → rolldown-runtime-gKJR3o-6.mjs} +1 -1
- package/dist/{routeValidator-DclDl5WJ.mjs → routeValidator-xNYA4rr1.mjs} +47 -5
- package/dist/{runtimeCapabilities-ClWr60El.mjs → runtimeCapabilities-BQK-GrYe.mjs} +1 -1
- package/dist/{schedules-gVkRcs-9.mjs → schedules-D9iMVFhF.mjs} +6 -9
- package/dist/{schemaConverter-CIwB5wPO.mjs → schemaConverter-cIh4oX9a.mjs} +2 -2
- package/dist/{actionPermissions-Dha8sAz2.mjs → schemaIR-BsY4y9VP.mjs} +184 -16
- package/dist/schemas/index.mjs +1 -1
- package/dist/scim/index.mjs +2 -2
- package/dist/scope/index.d.mts +1 -1
- package/dist/scope/index.mjs +5 -5
- package/dist/{scope-VMZhdkbT.mjs → scope-QyhM9w8z.mjs} +4 -4
- package/dist/{shutdown-Bi19vH0z.mjs → shutdown-BM7Q0h4B.mjs} +1 -1
- package/dist/{sse-BqM359f1.mjs → sse-ofvlcTQQ.mjs} +9 -35
- package/dist/sseStats-DQqNN385.d.mts +112 -0
- package/dist/sseStream-BxQW7hPq.mjs +166 -0
- package/dist/{store-helpers-rx-F2ZGR.mjs → store-helpers-_FRhHDyv.mjs} +1 -1
- package/dist/{simpleEqualityMatcher-CaCS09fh.mjs → streamFrames-B3ZJfI02.mjs} +19 -2
- package/dist/{streaming-CPChx3A7.mjs → streaming-HZr63UiM.mjs} +1 -1
- package/dist/{subscriberIdentity-CYNYw8p_.mjs → subscriberIdentity-DSgnoT_D.mjs} +1 -1
- package/dist/{tenancy-BoWImS3K.mjs → tenancy-_ukT0oBt.mjs} +2 -2
- package/dist/{tenantPreparation-oqKCZQZM.mjs → tenantPreparation-DSlQI53c.mjs} +4 -4
- package/dist/testing/cleanupStoreContract.mjs +1 -1
- package/dist/testing/index.d.mts +4 -4
- package/dist/testing/index.mjs +324 -17
- package/dist/testing/outboxStoreContract.mjs +2 -2
- package/dist/testing/requiredPorts.mjs +2 -2
- package/dist/testing/storageContract.mjs +1 -1
- package/dist/{timing-Dsteq59c.mjs → timing-Z8p-Zlw1.mjs} +1 -1
- package/dist/{transactionContext-C1OgH-hW.mjs → transactionContext-DBbSTfY3.mjs} +1 -1
- package/dist/{typeGuards-DNlpASzd.mjs → typeGuards-_6nNQqgq.mjs} +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.mjs +1 -1
- package/dist/types/storage.mjs +1 -1
- package/dist/{types-DduBiYaI.d.mts → types-B4E0sc6D.d.mts} +2 -2
- package/dist/{types-HFFSwF_K.mjs → types-CrOlZ4rY.mjs} +4 -4
- package/dist/usage/index.d.mts +1 -1
- package/dist/usage/index.mjs +7 -7
- package/dist/{userHelpers-N-k-8dNF.mjs → userHelpers-CBKx3XJN.mjs} +1 -1
- package/dist/utils/index.d.mts +239 -34
- package/dist/utils/index.mjs +13 -13
- package/dist/{utils-C7w_RVlx.mjs → utils--HE8R8sH.mjs} +761 -8
- package/dist/{validate-Brr4b_fH.mjs → validate-BUeE2MLR.mjs} +3 -3
- package/dist/{versioning-S18y2-0C.d.mts → versioning-B07RgD27.d.mts} +2 -13
- package/dist/{versioning-CE5kdWOY.mjs → versioning-qYgqwOhL.mjs} +4 -7
- package/dist/{workScope-A3XBpYTa.mjs → workScope-C-1QHNmV.mjs} +2 -2
- package/llms.txt +2 -2
- package/package.json +34 -34
- package/skills/arc/references/api-reference.md +2 -2
- package/skills/arc/references/auth-better-auth.md +1 -0
- package/skills/arc/references/events-outbox.md +7 -4
- package/skills/arc/references/events.md +2 -2
- package/skills/arc/references/production-api.md +4 -0
- package/skills/arc/references/production-boot.md +2 -0
- package/skills/arc/references/production-idempotency.md +1 -1
- package/skills/arc/references/production-realtime.md +28 -2
- package/skills/arc/references/validation.md +4 -0
- package/skills/arc/references/writes-hooks-errors.md +1 -0
- package/dist/schemaIR-A0IoD05P.mjs +0 -108
- package/dist/sseStream-qSa-F2Qm.mjs +0 -57
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import {
|
|
3
|
-
import { n as
|
|
4
|
-
import { t as
|
|
1
|
+
/*! @classytic/arc v2.49.0 | MIT | https://classytic.com */
|
|
2
|
+
import { t as arcLog } from "./logger-UbknHqHy.mjs";
|
|
3
|
+
import { n as evictToSize, r as touch } from "./boundedMap-C51EUUOm.mjs";
|
|
4
|
+
import { n as createSafeGetOne, t as createIsDuplicateKeyError } from "./store-helpers-_FRhHDyv.mjs";
|
|
5
|
+
import { t as claimedAttempts } from "./claimed-C7T1nHlo.mjs";
|
|
5
6
|
import { and, anyOf, eq, lte, ne, or } from "@classytic/repo-core/filter";
|
|
6
7
|
import { InvalidOutboxEventError, OutboxConflictError, OutboxOwnershipError, outboxPayloadFingerprint } from "@classytic/primitives/outbox";
|
|
7
8
|
import { update } from "@classytic/repo-core/update";
|
|
@@ -80,6 +81,17 @@ function repositoryAsOutboxStore(repository, options) {
|
|
|
80
81
|
if (Array.isArray(result)) return result;
|
|
81
82
|
return result?.data ?? [];
|
|
82
83
|
};
|
|
84
|
+
/** Learnt from a claim read whose page envelope carries a `limit` below the one asked. */
|
|
85
|
+
let claimCap;
|
|
86
|
+
const noteClaimPage = (result, asked) => {
|
|
87
|
+
if (Array.isArray(result) || typeof result !== "object" || result === null) return;
|
|
88
|
+
const pageLimit = result.limit;
|
|
89
|
+
if (typeof pageLimit !== "number" || !(pageLimit > 0) || pageLimit >= asked) return;
|
|
90
|
+
if (claimCap !== void 0 && claimCap <= pageLimit) return;
|
|
91
|
+
const first = claimCap === void 0;
|
|
92
|
+
claimCap = pageLimit;
|
|
93
|
+
if (first) arcLog("events").warn(`OUTBOX_CLAIM_CAPPED: the outbox repository returned at most ${pageLimit} rows for one claim (asked ${asked}, got ${pageLimit}); the relay's batchSize is lowered to ${pageLimit}. Raise the repository's page maxLimit (mongokit createOutboxRepository: { pagination: { maxLimit } }) or lower batchSize to silence this.`);
|
|
94
|
+
};
|
|
83
95
|
const isDuplicateKeyError = createIsDuplicateKeyError(repository);
|
|
84
96
|
const safeGetOne = createSafeGetOne(repository);
|
|
85
97
|
const isWellFormed = (event) => !!event && typeof event.type === "string" && !!event.meta?.id;
|
|
@@ -105,12 +117,14 @@ function repositoryAsOutboxStore(repository, options) {
|
|
|
105
117
|
const typeFilter = options?.types?.length ? anyOf("type", options.types) : null;
|
|
106
118
|
const now = /* @__PURE__ */ new Date();
|
|
107
119
|
const candidateFilter = typeFilter ? and(claimableFilter(now), typeFilter) : claimableFilter(now);
|
|
108
|
-
const
|
|
120
|
+
const page = await r.getAll({
|
|
109
121
|
filters: candidateFilter,
|
|
110
122
|
sort: { createdAt: 1 },
|
|
111
123
|
page: 1,
|
|
112
124
|
limit
|
|
113
|
-
})
|
|
125
|
+
});
|
|
126
|
+
noteClaimPage(page, limit);
|
|
127
|
+
const candidates = unwrapDocs(page);
|
|
114
128
|
if (candidates.length === 0) return [];
|
|
115
129
|
const claimed = (await Promise.all(candidates.map((candidate) => {
|
|
116
130
|
const claimNow = /* @__PURE__ */ new Date();
|
|
@@ -155,6 +169,9 @@ function repositoryAsOutboxStore(repository, options) {
|
|
|
155
169
|
* `@classytic/primitives/outbox`.
|
|
156
170
|
*/
|
|
157
171
|
transactionalSave: true,
|
|
172
|
+
get claimCap() {
|
|
173
|
+
return claimCap;
|
|
174
|
+
},
|
|
158
175
|
async save(event, options) {
|
|
159
176
|
if (!event?.type || typeof event.type !== "string") throw new InvalidOutboxEventError("event.type is required");
|
|
160
177
|
if (!event.meta?.id || typeof event.meta.id !== "string") throw new InvalidOutboxEventError("event.meta.id is required");
|
|
@@ -195,6 +212,7 @@ function repositoryAsOutboxStore(repository, options) {
|
|
|
195
212
|
page: 1,
|
|
196
213
|
limit
|
|
197
214
|
});
|
|
215
|
+
noteClaimPage(result, limit);
|
|
198
216
|
return unwrapDocs(result).map((d) => d.event).filter(isWellFormed);
|
|
199
217
|
},
|
|
200
218
|
async claimPending(options) {
|
|
@@ -394,6 +412,14 @@ const DEFAULT_LEASE_MS = 3e4;
|
|
|
394
412
|
* the store).
|
|
395
413
|
*/
|
|
396
414
|
const MAX_TRACKED_ATTEMPTS = 1e4;
|
|
415
|
+
/**
|
|
416
|
+
* Share of the lease a pass may spend before it stops publishing claimed rows.
|
|
417
|
+
* The rest absorbs the last publish + ack and clock skew between claimants: a
|
|
418
|
+
* row published after its lease expired may already be re-claimed elsewhere.
|
|
419
|
+
*/
|
|
420
|
+
const LEASE_PUBLISH_FRACTION = .8;
|
|
421
|
+
/** Share of the lease the adaptive claim sizes a batch to, from the measured per-event time. */
|
|
422
|
+
const LEASE_CLAIM_FRACTION = .5;
|
|
397
423
|
var EventOutbox = class {
|
|
398
424
|
_store;
|
|
399
425
|
_transport;
|
|
@@ -418,6 +444,11 @@ var EventOutbox = class {
|
|
|
418
444
|
* durable count wins — see the failure path in `relayBatch`.
|
|
419
445
|
*/
|
|
420
446
|
_attempts = /* @__PURE__ */ new Map();
|
|
447
|
+
/**
|
|
448
|
+
* Measured ms per event (publish + ack), rising at once on a slower batch and
|
|
449
|
+
* decaying slowly. Undefined until a batch has published something.
|
|
450
|
+
*/
|
|
451
|
+
_perEventMs;
|
|
421
452
|
constructor(opts) {
|
|
422
453
|
if (opts.repository) this._store = repositoryAsOutboxStore(opts.repository);
|
|
423
454
|
else if (opts.store) this._store = opts.store;
|
|
@@ -438,6 +469,15 @@ var EventOutbox = class {
|
|
|
438
469
|
return this._consumerId;
|
|
439
470
|
}
|
|
440
471
|
/**
|
|
472
|
+
* Rows claimed per {@link relayBatch} (the `batchSize` option, default 100), lowered to
|
|
473
|
+
* the store's `claimCap` once a claim came back clamped (`repositoryAsOutboxStore`).
|
|
474
|
+
* A pass that attempted this many rows hit the limit, so more may be pending.
|
|
475
|
+
*/
|
|
476
|
+
get batchSize() {
|
|
477
|
+
const cap = this._store.claimCap;
|
|
478
|
+
return typeof cap === "number" && cap > 0 ? Math.min(this._batchSize, cap) : this._batchSize;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
441
481
|
* Store event in outbox.
|
|
442
482
|
*
|
|
443
483
|
* Validates that `event.type` and `event.meta.id` are present — throws
|
|
@@ -529,9 +569,22 @@ var EventOutbox = class {
|
|
|
529
569
|
* claimed the event), the event is NOT counted as relayed. The other
|
|
530
570
|
* worker will re-publish — at-least-once semantics preserved.
|
|
531
571
|
*
|
|
572
|
+
* - **Types**: `options.types` claims only events of those types (exact
|
|
573
|
+
* names, oldest first), so a priority pass is not queued behind a backlog
|
|
574
|
+
* of other types. Needs a store with `claimPending` / `claimPendingFenced`
|
|
575
|
+
* (both honour `OutboxClaimOptions.types`); on the single-worker
|
|
576
|
+
* `getPending` fallback the filter is ignored and the oldest rows go out.
|
|
577
|
+
*
|
|
578
|
+
* - **Lease budget**: on a leasing store each row is published only while
|
|
579
|
+
* the claim's lease has budget left, and acked right after its publish.
|
|
580
|
+
* Rows past the budget are not published (`leaseDeferred`); they are
|
|
581
|
+
* re-claimed after expiry. The claim size adapts to the measured per-event
|
|
582
|
+
* time so a batch fits the lease. See wiki/delivery-guarantees.md.
|
|
583
|
+
*
|
|
532
584
|
* @returns Per-kind outcome counts for the batch
|
|
533
585
|
*/
|
|
534
|
-
async relayBatch() {
|
|
586
|
+
async relayBatch(options) {
|
|
587
|
+
const types = options?.types?.length ? options.types : void 0;
|
|
535
588
|
const empty = {
|
|
536
589
|
relayed: 0,
|
|
537
590
|
attempted: 0,
|
|
@@ -545,13 +598,16 @@ var EventOutbox = class {
|
|
|
545
598
|
};
|
|
546
599
|
if (!this._transport) return empty;
|
|
547
600
|
const claimStartedAt = Date.now();
|
|
601
|
+
const leased = typeof this._store.claimPendingFenced === "function" || typeof this._store.claimPending === "function";
|
|
602
|
+
const limit = leased ? this._claimLimit() : this.batchSize;
|
|
548
603
|
const fenceTokens = /* @__PURE__ */ new Map();
|
|
549
604
|
const durableAttempts = /* @__PURE__ */ new Map();
|
|
550
605
|
let pending;
|
|
551
606
|
if (typeof this._store.claimPendingFenced === "function") pending = (await this._store.claimPendingFenced({
|
|
552
|
-
limit
|
|
607
|
+
limit,
|
|
553
608
|
consumerId: this._consumerId,
|
|
554
|
-
leaseMs: this._leaseMs
|
|
609
|
+
leaseMs: this._leaseMs,
|
|
610
|
+
...types ? { types } : {}
|
|
555
611
|
})).map((c) => {
|
|
556
612
|
if (c.event?.meta?.id) {
|
|
557
613
|
fenceTokens.set(c.event.meta.id, c.fencingToken);
|
|
@@ -561,13 +617,15 @@ var EventOutbox = class {
|
|
|
561
617
|
return c.event;
|
|
562
618
|
});
|
|
563
619
|
else if (this._store.claimPending) pending = await this._store.claimPending({
|
|
564
|
-
limit
|
|
620
|
+
limit,
|
|
565
621
|
consumerId: this._consumerId,
|
|
566
|
-
leaseMs: this._leaseMs
|
|
622
|
+
leaseMs: this._leaseMs,
|
|
623
|
+
...types ? { types } : {}
|
|
567
624
|
});
|
|
568
|
-
else pending = await this._store.getPending(this.
|
|
625
|
+
else pending = await this._store.getPending(this.batchSize);
|
|
569
626
|
const claimMs = Date.now() - claimStartedAt;
|
|
570
627
|
const publishStartedAt = Date.now();
|
|
628
|
+
const leaseDeadline = leased ? claimStartedAt + this._leaseMs * LEASE_PUBLISH_FRACTION : Number.POSITIVE_INFINITY;
|
|
571
629
|
const valid = [];
|
|
572
630
|
let malformed = 0;
|
|
573
631
|
for (const event of pending) {
|
|
@@ -587,97 +645,53 @@ var EventOutbox = class {
|
|
|
587
645
|
deadLettered: 0
|
|
588
646
|
};
|
|
589
647
|
const canPublishMany = this._usePublishMany && typeof this._transport.publishMany === "function";
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
publishOutcomes.set(event.meta.id, err instanceof Error ? err : new Error(String(err)));
|
|
606
|
-
if (!canFail) break;
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
if (this._onPublished) for (const event of valid) {
|
|
610
|
-
if (publishOutcomes.get(event.meta.id) !== null) continue;
|
|
611
|
-
try {
|
|
612
|
-
this._onPublished(event);
|
|
613
|
-
} catch {}
|
|
614
|
-
}
|
|
615
|
-
let stopBatch = false;
|
|
616
|
-
for (const event of valid) {
|
|
617
|
-
if (stopBatch) break;
|
|
618
|
-
const publishErr = publishOutcomes.get(event.meta.id);
|
|
619
|
-
if (publishErr instanceof Error) {
|
|
620
|
-
counts.publishFailed++;
|
|
621
|
-
this._reportError("publish_failed", publishErr, event);
|
|
622
|
-
if (!canFail) {
|
|
623
|
-
stopBatch = true;
|
|
624
|
-
continue;
|
|
625
|
-
}
|
|
626
|
-
const localAttempts = (this._attempts.get(event.meta.id) ?? 0) + 1;
|
|
627
|
-
const attempts = Math.max(localAttempts, durableAttempts.get(event.meta.id) ?? 0);
|
|
628
|
-
touch(this._attempts, event.meta.id, attempts);
|
|
629
|
-
evictToSize(this._attempts, MAX_TRACKED_ATTEMPTS);
|
|
630
|
-
const fenceToken = fenceTokens.get(event.meta.id);
|
|
631
|
-
let failOpts = {
|
|
632
|
-
consumerId: this._consumerId,
|
|
633
|
-
...fenceToken !== void 0 ? { fencingToken: fenceToken } : {}
|
|
634
|
-
};
|
|
635
|
-
if (this._failurePolicy) try {
|
|
636
|
-
const decision = await this._failurePolicy({
|
|
637
|
-
event,
|
|
638
|
-
error: publishErr,
|
|
639
|
-
attempts
|
|
640
|
-
});
|
|
641
|
-
failOpts = {
|
|
642
|
-
...failOpts,
|
|
643
|
-
...decision
|
|
644
|
-
};
|
|
645
|
-
} catch (policyErr) {
|
|
646
|
-
this._reportError("fail_failed", policyErr, event);
|
|
647
|
-
}
|
|
648
|
+
const settleCtx = {
|
|
649
|
+
canFail: typeof this._store.fail === "function",
|
|
650
|
+
counts,
|
|
651
|
+
fenceTokens,
|
|
652
|
+
durableAttempts
|
|
653
|
+
};
|
|
654
|
+
/** Rows published and settled (ack/fail) this batch, and their summed time. */
|
|
655
|
+
let settled = 0;
|
|
656
|
+
let settleMs = 0;
|
|
657
|
+
let leaseDeferred = 0;
|
|
658
|
+
if (canPublishMany && valid.length > 0) {
|
|
659
|
+
if (Date.now() >= leaseDeadline) leaseDeferred = valid.length;
|
|
660
|
+
else {
|
|
661
|
+
const startedAt = Date.now();
|
|
662
|
+
let publishOutcomes;
|
|
648
663
|
try {
|
|
649
|
-
await this.
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
} catch (failErr) {
|
|
655
|
-
if (failErr instanceof OutboxOwnershipError) {
|
|
656
|
-
counts.ownershipMismatches++;
|
|
657
|
-
this._reportError("ownership_mismatch", failErr, event);
|
|
658
|
-
} else {
|
|
659
|
-
counts.failHookErrors++;
|
|
660
|
-
this._reportError("fail_failed", failErr, event);
|
|
661
|
-
}
|
|
664
|
+
publishOutcomes = batchOutcomes(valid, await this._transport.publishMany?.(valid));
|
|
665
|
+
} catch (batchErr) {
|
|
666
|
+
publishOutcomes = /* @__PURE__ */ new Map();
|
|
667
|
+
const err = batchErr instanceof Error ? batchErr : new Error(String(batchErr));
|
|
668
|
+
for (const ev of valid) publishOutcomes.set(ev.meta.id, err);
|
|
662
669
|
}
|
|
663
|
-
|
|
670
|
+
for (const event of valid) if (publishOutcomes.get(event.meta.id) === null) this._notifyPublished(event);
|
|
671
|
+
for (const event of valid) if (await this._settle(event, publishOutcomes.get(event.meta.id) ?? null, settleCtx)) break;
|
|
672
|
+
settled = valid.length;
|
|
673
|
+
settleMs = Date.now() - startedAt;
|
|
664
674
|
}
|
|
675
|
+
} else for (const [index, event] of valid.entries()) {
|
|
676
|
+
const nextMs = Math.max(settled > 0 ? settleMs / settled : 0, this._perEventMs ?? 0);
|
|
677
|
+
if (Date.now() + nextMs > leaseDeadline) {
|
|
678
|
+
leaseDeferred = valid.length - index;
|
|
679
|
+
break;
|
|
680
|
+
}
|
|
681
|
+
const startedAt = Date.now();
|
|
682
|
+
let publishErr = null;
|
|
665
683
|
try {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
...ackFenceToken !== void 0 ? { fencingToken: ackFenceToken } : {}
|
|
670
|
-
});
|
|
671
|
-
counts.relayed++;
|
|
672
|
-
this._attempts.delete(event.meta.id);
|
|
673
|
-
} catch (ackErr) {
|
|
674
|
-
counts.ackFailed++;
|
|
675
|
-
if (ackErr instanceof OutboxOwnershipError) {
|
|
676
|
-
counts.ownershipMismatches++;
|
|
677
|
-
this._reportError("ownership_mismatch", ackErr, event);
|
|
678
|
-
} else this._reportError("acknowledge_failed", ackErr, event);
|
|
684
|
+
await this._transport.publish(event);
|
|
685
|
+
} catch (err) {
|
|
686
|
+
publishErr = err instanceof Error ? err : new Error(String(err));
|
|
679
687
|
}
|
|
688
|
+
if (publishErr === null) this._notifyPublished(event);
|
|
689
|
+
const stop = await this._settle(event, publishErr, settleCtx);
|
|
690
|
+
settled++;
|
|
691
|
+
settleMs += Date.now() - startedAt;
|
|
692
|
+
if (stop) break;
|
|
680
693
|
}
|
|
694
|
+
if (settled > 0) this._recordPerEventMs(settleMs / settled);
|
|
681
695
|
return {
|
|
682
696
|
relayed: counts.relayed,
|
|
683
697
|
attempted: valid.length,
|
|
@@ -687,12 +701,99 @@ var EventOutbox = class {
|
|
|
687
701
|
malformed,
|
|
688
702
|
failHookErrors: counts.failHookErrors,
|
|
689
703
|
deadLettered: counts.deadLettered,
|
|
690
|
-
usedPublishMany: canPublishMany && valid.length > 0,
|
|
704
|
+
usedPublishMany: canPublishMany && valid.length > 0 && leaseDeferred < valid.length,
|
|
691
705
|
claimMs,
|
|
692
|
-
publishMs: Date.now() - publishStartedAt
|
|
706
|
+
publishMs: Date.now() - publishStartedAt,
|
|
707
|
+
...leaseDeferred > 0 ? { leaseDeferred } : {}
|
|
693
708
|
};
|
|
694
709
|
}
|
|
695
710
|
/**
|
|
711
|
+
* Rows to claim: `batchSize`, or fewer when the measured per-event time says a
|
|
712
|
+
* full batch would outlive {@link LEASE_CLAIM_FRACTION} of the lease.
|
|
713
|
+
*/
|
|
714
|
+
_claimLimit() {
|
|
715
|
+
const batchSize = this.batchSize;
|
|
716
|
+
if (this._perEventMs === void 0 || this._perEventMs <= 0) return batchSize;
|
|
717
|
+
const fit = Math.floor(this._leaseMs * LEASE_CLAIM_FRACTION / this._perEventMs);
|
|
718
|
+
return Math.max(1, Math.min(batchSize, fit));
|
|
719
|
+
}
|
|
720
|
+
_recordPerEventMs(sample) {
|
|
721
|
+
const prev = this._perEventMs;
|
|
722
|
+
this._perEventMs = prev === void 0 ? sample : Math.max(sample, prev * .7 + sample * .3);
|
|
723
|
+
}
|
|
724
|
+
_notifyPublished(event) {
|
|
725
|
+
if (!this._onPublished) return;
|
|
726
|
+
try {
|
|
727
|
+
this._onPublished(event);
|
|
728
|
+
} catch {}
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Ack a published event, or `fail()` a rejected one. Returns `true` when the
|
|
732
|
+
* batch must stop (a failure on a store without `fail`).
|
|
733
|
+
*/
|
|
734
|
+
async _settle(event, publishErr, ctx) {
|
|
735
|
+
const { canFail, counts, fenceTokens, durableAttempts } = ctx;
|
|
736
|
+
if (publishErr instanceof Error) {
|
|
737
|
+
counts.publishFailed++;
|
|
738
|
+
this._reportError("publish_failed", publishErr, event);
|
|
739
|
+
if (!canFail) return true;
|
|
740
|
+
const localAttempts = (this._attempts.get(event.meta.id) ?? 0) + 1;
|
|
741
|
+
const attempts = Math.max(localAttempts, durableAttempts.get(event.meta.id) ?? 0);
|
|
742
|
+
touch(this._attempts, event.meta.id, attempts);
|
|
743
|
+
evictToSize(this._attempts, MAX_TRACKED_ATTEMPTS);
|
|
744
|
+
const fenceToken = fenceTokens.get(event.meta.id);
|
|
745
|
+
let failOpts = {
|
|
746
|
+
consumerId: this._consumerId,
|
|
747
|
+
...fenceToken !== void 0 ? { fencingToken: fenceToken } : {}
|
|
748
|
+
};
|
|
749
|
+
if (this._failurePolicy) try {
|
|
750
|
+
const decision = await this._failurePolicy({
|
|
751
|
+
event,
|
|
752
|
+
error: publishErr,
|
|
753
|
+
attempts
|
|
754
|
+
});
|
|
755
|
+
failOpts = {
|
|
756
|
+
...failOpts,
|
|
757
|
+
...decision
|
|
758
|
+
};
|
|
759
|
+
} catch (policyErr) {
|
|
760
|
+
this._reportError("fail_failed", policyErr, event);
|
|
761
|
+
}
|
|
762
|
+
try {
|
|
763
|
+
await this._store.fail?.(event.meta.id, normalizeError(publishErr), failOpts);
|
|
764
|
+
if (failOpts.deadLetter) {
|
|
765
|
+
counts.deadLettered++;
|
|
766
|
+
this._attempts.delete(event.meta.id);
|
|
767
|
+
}
|
|
768
|
+
} catch (failErr) {
|
|
769
|
+
if (failErr instanceof OutboxOwnershipError) {
|
|
770
|
+
counts.ownershipMismatches++;
|
|
771
|
+
this._reportError("ownership_mismatch", failErr, event);
|
|
772
|
+
} else {
|
|
773
|
+
counts.failHookErrors++;
|
|
774
|
+
this._reportError("fail_failed", failErr, event);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
return false;
|
|
778
|
+
}
|
|
779
|
+
try {
|
|
780
|
+
const ackFenceToken = fenceTokens.get(event.meta.id);
|
|
781
|
+
await this._store.acknowledge(event.meta.id, {
|
|
782
|
+
consumerId: this._consumerId,
|
|
783
|
+
...ackFenceToken !== void 0 ? { fencingToken: ackFenceToken } : {}
|
|
784
|
+
});
|
|
785
|
+
counts.relayed++;
|
|
786
|
+
this._attempts.delete(event.meta.id);
|
|
787
|
+
} catch (ackErr) {
|
|
788
|
+
counts.ackFailed++;
|
|
789
|
+
if (ackErr instanceof OutboxOwnershipError) {
|
|
790
|
+
counts.ownershipMismatches++;
|
|
791
|
+
this._reportError("ownership_mismatch", ackErr, event);
|
|
792
|
+
} else this._reportError("acknowledge_failed", ackErr, event);
|
|
793
|
+
}
|
|
794
|
+
return false;
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
696
797
|
* Fetch current dead-lettered events as typed {@link DeadLetteredEvent}
|
|
697
798
|
* envelopes. Delegates to {@link OutboxStore.getDeadLettered} — returns
|
|
698
799
|
* `[]` when the store doesn't implement it.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { t as __exportAll } from "./rolldown-runtime-
|
|
1
|
+
/*! @classytic/arc v2.49.0 | MIT | https://classytic.com */
|
|
2
|
+
import { t as __exportAll } from "./rolldown-runtime-gKJR3o-6.mjs";
|
|
3
3
|
import { toCanonicalList } from "@classytic/repo-core/pagination";
|
|
4
4
|
import fp from "fastify-plugin";
|
|
5
5
|
// src/plugins/replyHelpers.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
1
|
+
/*! @classytic/arc v2.49.0 | MIT | https://classytic.com */
|
|
2
2
|
// src/idempotency/requirement.ts
|
|
3
3
|
/** What is wrong with a route's idempotency declaration, or `undefined` when it is sound. */
|
|
4
4
|
function idempotencyConfigProblem(config) {
|
|
@@ -6,10 +6,14 @@ interface ResourceRateLimitPolicy {
|
|
|
6
6
|
timeWindow: string;
|
|
7
7
|
/** Explicit route overrides own a separate budget. */
|
|
8
8
|
bucket?: string;
|
|
9
|
+
/** Routes sharing a `groupId` share one budget, across resources; it supersedes `bucket`. */
|
|
10
|
+
groupId?: string;
|
|
9
11
|
}
|
|
10
12
|
interface ResourceRateLimitContext {
|
|
11
13
|
scope?: RequestScope;
|
|
12
14
|
ip?: string;
|
|
15
|
+
/** The host's `keyGenerator` result; when set it replaces the scope/IP key. */
|
|
16
|
+
key?: string;
|
|
13
17
|
}
|
|
14
18
|
interface ResourceRateLimitDecision {
|
|
15
19
|
readonly allowed: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { t as createTenantKeyGenerator } from "./rateLimitKey-
|
|
1
|
+
/*! @classytic/arc v2.49.0 | MIT | https://classytic.com */
|
|
2
|
+
import { t as createTenantKeyGenerator } from "./rateLimitKey-56nH1cWN.mjs";
|
|
3
3
|
// src/permissions/resourceRateLimit.ts
|
|
4
4
|
function decision(allowed, max, remaining, ttlSeconds) {
|
|
5
5
|
const reset = Math.max(1, ttlSeconds);
|
|
@@ -17,6 +17,12 @@ function decision(allowed, max, remaining, ttlSeconds) {
|
|
|
17
17
|
/** Policy namespacing must reach the store key, not merely the local limiter cache. */
|
|
18
18
|
function policyIdentity(resource, policy) {
|
|
19
19
|
if (!Number.isSafeInteger(policy.max) || policy.max <= 0) throw new Error("rateLimit.max must be a positive safe integer.");
|
|
20
|
+
if (policy.groupId !== void 0) return JSON.stringify([
|
|
21
|
+
"arc-group",
|
|
22
|
+
policy.groupId,
|
|
23
|
+
policy.max,
|
|
24
|
+
resourceRateLimitWindowMs(policy.timeWindow)
|
|
25
|
+
]);
|
|
20
26
|
return JSON.stringify([
|
|
21
27
|
"arc-resource",
|
|
22
28
|
resource,
|
|
@@ -27,7 +33,16 @@ function policyIdentity(resource, policy) {
|
|
|
27
33
|
}
|
|
28
34
|
const RESOURCE_RATE_LIMITER = Symbol.for("arc.resourceRateLimiter");
|
|
29
35
|
const tenantKey = createTenantKeyGenerator();
|
|
36
|
+
/** The budget's owner inside the store key: the resource, or the group that spans resources. */
|
|
37
|
+
function budgetOwner(resource, policy) {
|
|
38
|
+
return policy.groupId === void 0 ? resource : `group:${policy.groupId}`;
|
|
39
|
+
}
|
|
30
40
|
function resourceRateLimitKey(resource, context) {
|
|
41
|
+
if (context.key !== void 0) return JSON.stringify([
|
|
42
|
+
resource,
|
|
43
|
+
"key",
|
|
44
|
+
context.key
|
|
45
|
+
]);
|
|
31
46
|
const actor = tenantKey({
|
|
32
47
|
scope: context.scope,
|
|
33
48
|
ip: context.ip ?? "anonymous"
|
|
@@ -95,7 +110,7 @@ function resolveResourceRateLimiter(app, durability = "memory") {
|
|
|
95
110
|
limiters.set(identity, consume);
|
|
96
111
|
}
|
|
97
112
|
const req = {
|
|
98
|
-
ip: JSON.stringify([identity, resourceRateLimitKey(resource, context)]),
|
|
113
|
+
ip: JSON.stringify([identity, resourceRateLimitKey(budgetOwner(resource, policy), context)]),
|
|
99
114
|
routeOptions: { config: {} }
|
|
100
115
|
};
|
|
101
116
|
const result = await consume(req);
|
|
@@ -114,7 +129,7 @@ function createMemoryResourceRateLimiter(capacity = 1e4) {
|
|
|
114
129
|
async consume(resource, policy, context) {
|
|
115
130
|
const now = Date.now();
|
|
116
131
|
const windowMs = resourceRateLimitWindowMs(policy.timeWindow);
|
|
117
|
-
const key = JSON.stringify([policyIdentity(resource, policy), resourceRateLimitKey(resource, context)]);
|
|
132
|
+
const key = JSON.stringify([policyIdentity(resource, policy), resourceRateLimitKey(budgetOwner(resource, policy), context)]);
|
|
118
133
|
let slot = windows.get(key);
|
|
119
134
|
if (!slot || slot.expires <= now) {
|
|
120
135
|
if (windows.size >= capacity) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
1
|
+
/*! @classytic/arc v2.49.0 | MIT | https://classytic.com */
|
|
2
2
|
import { AjvCompiler } from "@fastify/ajv-compiler";
|
|
3
3
|
// src/core/routeValidator.ts
|
|
4
4
|
/**
|
|
@@ -10,6 +10,13 @@ import { AjvCompiler } from "@fastify/ajv-compiler";
|
|
|
10
10
|
* carry their own `validatorCompiler` unless the instance was built by `createApp`, whose root
|
|
11
11
|
* AJV already runs these options (plus the host's `ajv.keywords`).
|
|
12
12
|
* Pinned by `tests/core/route-validator-bare-host.test.ts`.
|
|
13
|
+
*
|
|
14
|
+
* Type coercion runs ONLY on the URL parts (`querystring`, `params`, `headers`), which arrive as
|
|
15
|
+
* strings. A JSON body is already typed: coercing it rewrites values by the FIRST matching
|
|
16
|
+
* `anyOf` branch, so `{ value: false }` against `anyOf [number, boolean, string]` reached the
|
|
17
|
+
* handler as `0`. Bodies compile on a sibling AJV with `coerceTypes: false` unless the host opts
|
|
18
|
+
* back in with `createApp({ ajv: { coerceBody: true } })`.
|
|
19
|
+
* Pinned by `tests/core/route-validator-body-coercion.test.ts`.
|
|
13
20
|
*/
|
|
14
21
|
/** The AJV options `createApp` configures and arc's own routes are compiled with. */
|
|
15
22
|
function arcAjvCustomOptions(extraKeywords = []) {
|
|
@@ -28,15 +35,42 @@ function markArcRootValidator(fastify) {
|
|
|
28
35
|
/** One pool for the process: `@fastify/ajv-compiler` caches an AJV per (shared schemas, options). */
|
|
29
36
|
const buildFromPool = AjvCompiler();
|
|
30
37
|
/**
|
|
38
|
+
* The root `schemaController.compilersFactory.buildValidator` `createApp` installs: Fastify's own
|
|
39
|
+
* AJV pool, but `body` compiles on an AJV whose `coerceTypes` is `false` (unless `coerceBody`).
|
|
40
|
+
* A custom factory makes Fastify skip its header-schema lower-casing, so headers are lower-cased here.
|
|
41
|
+
*/
|
|
42
|
+
function arcValidatorBuilder(options = {}) {
|
|
43
|
+
const build = (externalSchemas, ajvServerOptions = {}) => {
|
|
44
|
+
const fromPool = (customOptions) => buildFromPool(externalSchemas, {
|
|
45
|
+
...ajvServerOptions,
|
|
46
|
+
customOptions
|
|
47
|
+
});
|
|
48
|
+
const customOptions = { ...ajvServerOptions.customOptions ?? {} };
|
|
49
|
+
const urlCompile = fromPool(customOptions);
|
|
50
|
+
const bodyCompile = options.coerceBody === true ? urlCompile : fromPool({
|
|
51
|
+
...customOptions,
|
|
52
|
+
coerceTypes: false
|
|
53
|
+
});
|
|
54
|
+
return (route) => {
|
|
55
|
+
if (route.httpPart === "body") return bodyCompile(route);
|
|
56
|
+
if (route.httpPart === "headers") return urlCompile({
|
|
57
|
+
...route,
|
|
58
|
+
schema: lowerCaseHeaderSchema(route.schema)
|
|
59
|
+
});
|
|
60
|
+
return urlCompile(route);
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
return build;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
31
66
|
* The `validatorCompiler` an arc-built route registers with — `undefined` under `createApp`
|
|
32
67
|
* (the root already validates this way). Schemas added with `fastify.addSchema` stay
|
|
33
68
|
* `$ref`-able: the shared pool is read when Fastify compiles the route.
|
|
34
69
|
*/
|
|
35
70
|
function arcRouteValidatorCompiler(fastify) {
|
|
36
71
|
if (fastify.arcRootValidator === true) return void 0;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
72
|
+
const build = arcValidatorBuilder();
|
|
73
|
+
return (route) => build(sharedSchemas(fastify), { customOptions: arcAjvCustomOptions() })(route);
|
|
40
74
|
}
|
|
41
75
|
/** The instance's `addSchema` pool, in the shape AJV accepts (a schema is an object or boolean). */
|
|
42
76
|
function sharedSchemas(fastify) {
|
|
@@ -61,9 +95,17 @@ function lowerCaseHeaderSchema(schema) {
|
|
|
61
95
|
for (const [key, value] of Object.entries(schema.properties)) properties[key.toLowerCase()] = value;
|
|
62
96
|
out.properties = properties;
|
|
63
97
|
}
|
|
98
|
+
for (const key of [
|
|
99
|
+
"allOf",
|
|
100
|
+
"anyOf",
|
|
101
|
+
"oneOf"
|
|
102
|
+
]) {
|
|
103
|
+
const branches = schema[key];
|
|
104
|
+
if (Array.isArray(branches)) out[key] = branches.map(lowerCaseHeaderSchema);
|
|
105
|
+
}
|
|
64
106
|
return out;
|
|
65
107
|
}
|
|
66
108
|
function isPlainObject(value) {
|
|
67
109
|
return typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
|
|
68
110
|
}
|
|
69
|
-
export { arcRouteValidatorCompiler as n,
|
|
111
|
+
export { markArcRootValidator as i, arcRouteValidatorCompiler as n, arcValidatorBuilder as r, arcAjvCustomOptions as t };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { t as __exportAll } from "./rolldown-runtime-
|
|
3
|
-
import {
|
|
4
|
-
import { t as
|
|
5
|
-
import {
|
|
1
|
+
/*! @classytic/arc v2.49.0 | MIT | https://classytic.com */
|
|
2
|
+
import { t as __exportAll } from "./rolldown-runtime-gKJR3o-6.mjs";
|
|
3
|
+
import { t as runWorkScope } from "./workScope-C-1QHNmV.mjs";
|
|
4
|
+
import { t as startRenewingLease } from "./renewingLease-BCJpW9-u.mjs";
|
|
5
|
+
import { a as runShutdown, i as runAdmittedWork, r as registerShutdownParticipant } from "./shutdown-BM7Q0h4B.mjs";
|
|
6
6
|
import fp from "fastify-plugin";
|
|
7
7
|
import { civilDateOf, civilDateToInstant, isValidTimeZone, localTimeParts } from "@classytic/primitives/timezone";
|
|
8
8
|
// src/plugins/dailyGate.ts
|
|
@@ -109,10 +109,7 @@ function createMemoryDailyLedger() {
|
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
// src/plugins/schedules.ts
|
|
112
|
-
var schedules_exports = /* @__PURE__ */ __exportAll({
|
|
113
|
-
default: () => schedules_default,
|
|
114
|
-
schedulesPlugin: () => schedulesPlugin
|
|
115
|
-
});
|
|
112
|
+
var schedules_exports = /* @__PURE__ */ __exportAll({ default: () => schedules_default });
|
|
116
113
|
const MIN_SAFE_INTERVAL_MS = 1e3;
|
|
117
114
|
const MAX_DEFAULT_LEASE_MS = 3e5;
|
|
118
115
|
const schedulesPlugin = async (fastify, opts) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { t as arcLog } from "./logger-
|
|
1
|
+
/*! @classytic/arc v2.49.0 | MIT | https://classytic.com */
|
|
2
|
+
import { t as arcLog } from "./logger-UbknHqHy.mjs";
|
|
3
3
|
// src/utils/schemaConverter.ts
|
|
4
4
|
/**
|
|
5
5
|
* Schema Converter — Detect-First, Convert-Only-When-Needed
|