@ref0/git 0.4.0 → 0.7.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/access/namespace.d.mts +2 -0
- package/dist/access/private-refs.d.mts +6 -29
- package/dist/access/private-refs.mjs +31 -17
- package/dist/access/public.d.mts +6 -0
- package/dist/access/public.mjs +9 -0
- package/dist/auth/access-jwt.d.mts +10 -6
- package/dist/auth/access-jwt.mjs +59 -40
- package/dist/auth/auth-namespace.d.mts +6 -0
- package/dist/auth/auth-namespace.mjs +12 -0
- package/dist/auth/auth.d.mts +3 -6
- package/dist/auth/auth.mjs +2 -9
- package/dist/auth/authorize.mjs +13 -9
- package/dist/auth/fences.d.mts +1 -1
- package/dist/auth/host-function.mjs +17 -8
- package/dist/auth/identify.d.mts +5 -3
- package/dist/auth/identify.mjs +2 -1
- package/dist/auth/namespaces.d.mts +2 -2
- package/dist/auth/token-rows.mjs +1 -1
- package/dist/auth/tokens-layer.d.mts +42 -0
- package/dist/auth/tokens-layer.mjs +29 -0
- package/dist/auth/tokens-namespace.d.mts +2 -0
- package/dist/auth/tokens-public.d.mts +6 -0
- package/dist/auth/tokens-public.mjs +29 -0
- package/dist/auth/tokens.d.mts +13 -6
- package/dist/auth/tokens.mjs +13 -12
- package/dist/auth.d.mts +2 -2
- package/dist/auth.mjs +2 -2
- package/dist/client/git-http.mjs +1 -1
- package/dist/client/local.mjs +6 -3
- package/dist/client/remote-helper.mjs +3 -8
- package/dist/client/remote.mjs +26 -7
- package/dist/client/run-remote-helper.d.mts +1 -1
- package/dist/client/run-remote-helper.mjs +2 -2
- package/dist/client/slice-push.d.mts +1 -1
- package/dist/contracts/access.d.mts +24 -12
- package/dist/contracts/access.mjs +17 -0
- package/dist/contracts/actors.d.mts +17 -1
- package/dist/contracts/actors.mjs +8 -1
- package/dist/contracts/authorize.d.mts +21 -14
- package/dist/contracts/blobs.d.mts +1 -1
- package/dist/contracts/blobs.mjs +1 -1
- package/dist/contracts/calls-spent.d.mts +6 -4
- package/dist/contracts/calls-spent.mjs +10 -8
- package/dist/contracts/commits.d.mts +2 -2
- package/dist/contracts/commits.mjs +1 -1
- package/dist/contracts/engine.d.mts +1 -1
- package/dist/contracts/events.d.mts +64 -26
- package/dist/contracts/events.mjs +26 -6
- package/dist/contracts/files.d.mts +2 -2
- package/dist/contracts/files.mjs +1 -1
- package/dist/contracts/forks.d.mts +58 -58
- package/dist/contracts/forks.mjs +1 -1
- package/dist/contracts/git-events.d.mts +50 -0
- package/dist/contracts/git-events.mjs +23 -0
- package/dist/contracts/git-hooks.d.mts +37 -0
- package/dist/contracts/git-hooks.mjs +10 -0
- package/dist/contracts/git.d.mts +138 -22
- package/dist/contracts/git.mjs +6 -5
- package/dist/contracts/grants.d.mts +6 -1
- package/dist/contracts/ids.d.mts +16 -0
- package/dist/contracts/ids.mjs +19 -4
- package/dist/contracts/lfs.d.mts +7 -2
- package/dist/contracts/namespaces.d.mts +2 -2
- package/dist/contracts/objects.d.mts +7 -2
- package/dist/contracts/opaque.mjs +9 -0
- package/dist/contracts/operations.d.mts +293 -100
- package/dist/contracts/promises.d.mts +4 -14
- package/dist/contracts/push-uploads.d.mts +5 -2
- package/dist/contracts/push-uploads.mjs +9 -4
- package/dist/contracts/queue.d.mts +233 -54
- package/dist/contracts/queue.mjs +81 -6
- package/dist/contracts/refs.d.mts +30 -8
- package/dist/contracts/refs.mjs +1 -1
- package/dist/contracts/remote.d.mts +42 -21
- package/dist/contracts/remote.mjs +22 -0
- package/dist/contracts/repo-records.d.mts +2 -2
- package/dist/contracts/repos.d.mts +126 -79
- package/dist/contracts/repos.mjs +43 -5
- package/dist/contracts/result.d.mts +50 -31
- package/dist/contracts/result.mjs +48 -16
- package/dist/contracts/rules.d.mts +50 -44
- package/dist/contracts/rules.mjs +5 -1
- package/dist/contracts/server.d.mts +282 -191
- package/dist/contracts/services.d.mts +1 -7
- package/dist/contracts/services.mjs +1 -3
- package/dist/contracts/signin.d.mts +140 -43
- package/dist/contracts/signin.mjs +35 -1
- package/dist/contracts/store.d.mts +1 -1
- package/dist/contracts/sync.d.mts +112 -90
- package/dist/contracts/sync.mjs +34 -7
- package/dist/contracts/tags.d.mts +1 -1
- package/dist/contracts/tags.mjs +1 -1
- package/dist/contracts/tokens.d.mts +232 -57
- package/dist/contracts/tokens.mjs +80 -19
- package/dist/contracts/topics.d.mts +22 -10
- package/dist/contracts/topics.mjs +6 -3
- package/dist/contracts/trees.d.mts +2 -2
- package/dist/contracts/trees.mjs +1 -1
- package/dist/contracts/work.d.mts +3 -3
- package/dist/contracts/work.mjs +2 -2
- package/dist/core/access.d.mts +10 -10
- package/dist/core/access.mjs +47 -8
- package/dist/core/call-names.d.mts +3 -1
- package/dist/core/clock.mjs +1 -1
- package/dist/core/events/deliver.d.mts +13 -0
- package/dist/core/events/deliver.mjs +475 -175
- package/dist/core/events/seen.mjs +17 -3
- package/dist/core/forks.mjs +131 -44
- package/dist/core/hooks/groups.d.mts +27 -0
- package/dist/core/hooks/groups.mjs +74 -0
- package/dist/core/hooks/namespace.d.mts +2 -0
- package/dist/core/hooks/order.d.mts +2 -2
- package/dist/core/hooks/order.mjs +6 -6
- package/dist/core/hooks/public.d.mts +7 -0
- package/dist/core/hooks/public.mjs +5 -0
- package/dist/core/imports.mjs +94 -10
- package/dist/core/index-job.mjs +31 -22
- package/dist/core/merge-parts.d.mts +1 -1
- package/dist/core/merge-parts.mjs +1 -1
- package/dist/core/mirror-rows.mjs +18 -0
- package/dist/core/names.mjs +1 -1
- package/dist/core/namespaces.d.mts +2 -1
- package/dist/core/objects/commit-writes.mjs +5 -5
- package/dist/core/objects/merges.mjs +1 -1
- package/dist/core/objects/objects-layer.mjs +1 -1
- package/dist/core/objects/reading.mjs +52 -7
- package/dist/core/objects/tree-edits.mjs +13 -28
- package/dist/core/objects/trees.mjs +4 -4
- package/dist/core/objects/writing.mjs +3 -3
- package/dist/core/own-writes.mjs +1 -1
- package/dist/core/parts.d.mts +27 -2
- package/dist/core/parts.mjs +5 -3
- package/dist/core/promise.mjs +23 -3
- package/dist/core/purge.d.mts +8 -0
- package/dist/core/purge.mjs +91 -46
- package/dist/core/push-decide.mjs +26 -4
- package/dist/core/push.mjs +104 -86
- package/dist/core/receipts.d.mts +2 -2
- package/dist/core/receipts.mjs +28 -4
- package/dist/core/ref-index-job.mjs +10 -15
- package/dist/core/ref-index.d.mts +1 -0
- package/dist/core/ref-index.mjs +28 -8
- package/dist/core/ref-view.mjs +16 -11
- package/dist/core/refs.mjs +54 -21
- package/dist/core/registered-records.mjs +30 -0
- package/dist/core/registered-rows.d.mts +4 -0
- package/dist/core/registered-rows.mjs +53 -0
- package/dist/core/repack.d.mts +3 -2
- package/dist/core/repack.mjs +70 -120
- package/dist/core/repo-info.mjs +59 -25
- package/dist/core/repos.mjs +22 -16
- package/dist/core/rules/changes.mjs +2 -2
- package/dist/core/rules/check.mjs +7 -6
- package/dist/core/rules/commit-changes.mjs +1 -1
- package/dist/core/rules/context.d.mts +4 -5
- package/dist/core/rules/context.mjs +3 -4
- package/dist/core/rules/fetch.mjs +74 -21
- package/dist/core/saved-caller-views.d.mts +72 -0
- package/dist/core/saved-caller-views.mjs +123 -0
- package/dist/core/saved-callers-public.d.mts +5 -0
- package/dist/core/saved-callers-public.mjs +10 -0
- package/dist/core/saved-callers.mjs +95 -0
- package/dist/core/seam.d.mts +67 -9
- package/dist/core/seam.mjs +11 -3
- package/dist/core/still-takes.mjs +75 -0
- package/dist/core/tokens.mjs +5 -1
- package/dist/core/view.d.mts +2 -1
- package/dist/core/view.mjs +9 -10
- package/dist/core/work.mjs +6 -5
- package/dist/effect.d.mts +2 -2
- package/dist/effect.mjs +2 -2
- package/dist/engine/content.d.mts +2 -2
- package/dist/engine/content.mjs +1 -1
- package/dist/engine/diff.mjs +2 -2
- package/dist/engine/merge-base-walk.d.mts +2 -2
- package/dist/engine/merge-base-walk.mjs +1 -1
- package/dist/engine/merge-renames.mjs +1 -1
- package/dist/engine/reads.d.mts +2 -2
- package/dist/engine/reads.mjs +1 -1
- package/dist/engine/xdiff.d.mts +1 -1
- package/dist/engine/xdiff.mjs +2 -2
- package/dist/event-streams/event-streams.d.mts +6 -2
- package/dist/event-streams/event-streams.mjs +6 -2
- package/dist/event-streams/stream.mjs +5 -2
- package/dist/extend.d.mts +5 -4
- package/dist/extend.mjs +3 -2
- package/dist/http/answers.mjs +4 -3
- package/dist/http/core-parts.mjs +21 -13
- package/dist/http/handler.mjs +3 -3
- package/dist/http/node.d.mts +2 -23
- package/dist/http/parts.d.mts +2 -0
- package/dist/http/push-uploads.d.mts +10 -2
- package/dist/http/push-uploads.mjs +38 -39
- package/dist/http/receive-pack.mjs +8 -6
- package/dist/http/upload-pack.mjs +8 -7
- package/dist/index.d.mts +36 -19
- package/dist/index.mjs +14 -6
- package/dist/lfs/base.d.mts +32 -0
- package/dist/lfs/base.mjs +8 -0
- package/dist/lfs/calls.mjs +22 -12
- package/dist/lfs/layer.d.mts +28 -0
- package/dist/lfs/layer.mjs +65 -0
- package/dist/lfs/locks.mjs +16 -30
- package/dist/lfs/namespace.d.mts +2 -0
- package/dist/lfs/objects.d.mts +26 -6
- package/dist/lfs/objects.mjs +197 -98
- package/dist/lfs/pointers.mjs +8 -6
- package/dist/lfs/public.d.mts +5 -0
- package/dist/lfs/public.mjs +8 -0
- package/dist/lfs/purge.mjs +19 -25
- package/dist/lfs/rows.mjs +22 -10
- package/dist/lfs/service.d.mts +9 -4
- package/dist/lfs/service.mjs +3 -12
- package/dist/lfs/upkeep.mjs +45 -56
- package/dist/lfs/wire.mjs +1 -1
- package/dist/node.d.mts +3 -2
- package/dist/node.mjs +1 -1
- package/dist/protocol/bytes/buffers.d.mts +1 -1
- package/dist/protocol/bytes/buffers.mjs +1 -1
- package/dist/protocol/bytes/deflate.d.mts +1 -1
- package/dist/protocol/bytes/deflate.mjs +1 -1
- package/dist/protocol/bytes/hmac-sha256.mjs +3 -6
- package/dist/protocol/bytes/inflate.d.mts +1 -1
- package/dist/protocol/bytes/inflate.mjs +1 -1
- package/dist/protocol/bytes/sha1.d.mts +1 -1
- package/dist/protocol/bytes/sha1.mjs +2 -2
- package/dist/protocol/diff/read.d.mts +1 -1
- package/dist/protocol/diff/read.mjs +1 -1
- package/dist/protocol/diff/tree-diff.d.mts +1 -1
- package/dist/protocol/diff/tree-diff.mjs +11 -11
- package/dist/protocol/objects/lfs-pointer.mjs +6 -1
- package/dist/protocol/objects/tag.mjs +1 -1
- package/dist/protocol/objects/tree.mjs +1 -1
- package/dist/protocol/packs/graph.mjs +1 -1
- package/dist/protocol/packs/idx.d.mts +1 -1
- package/dist/protocol/packs/idx.mjs +1 -1
- package/dist/protocol/packs/parts.mjs +1 -1
- package/dist/protocol/packs/reader.d.mts +1 -1
- package/dist/protocol/packs/reader.mjs +2 -2
- package/dist/protocol/packs/write-error.d.mts +1 -1
- package/dist/protocol/packs/write-error.mjs +1 -1
- package/dist/protocol/packs/writer.mjs +4 -4
- package/dist/protocol/wire/advertisement.d.mts +5 -11
- package/dist/protocol/wire/advertisement.mjs +17 -13
- package/dist/protocol/wire/fetch.d.mts +1 -1
- package/dist/protocol/wire/fetch.mjs +1 -1
- package/dist/protocol/wire/lines.d.mts +14 -2
- package/dist/protocol/wire/lines.mjs +32 -21
- package/dist/protocol/wire/push-uploads.mjs +4 -2
- package/dist/protocol/wire/receive-pack.d.mts +1 -1
- package/dist/protocol/wire/receive-pack.mjs +1 -1
- package/dist/protocol/wire/report-status.d.mts +1 -1
- package/dist/protocol/wire/report-status.mjs +1 -1
- package/dist/protocol/wire/v2.d.mts +5 -16
- package/dist/protocol/wire/v2.mjs +17 -15
- package/dist/queue/advance.mjs +227 -112
- package/dist/queue/callers.mjs +56 -69
- package/dist/queue/calls.mjs +24 -13
- package/dist/queue/commit.mjs +20 -7
- package/dist/queue/host.d.mts +12 -13
- package/dist/queue/host.mjs +15 -7
- package/dist/queue/lanes.mjs +9 -18
- package/dist/queue/layer.d.mts +6 -4
- package/dist/queue/layer.mjs +17 -11
- package/dist/queue/limits.mjs +53 -11
- package/dist/queue/rows.mjs +19 -15
- package/dist/queue/schedule.mjs +6 -5
- package/dist/queue/search.mjs +8 -13
- package/dist/queue/state.mjs +26 -7
- package/dist/queue/steps.mjs +10 -4
- package/dist/queue/trim.mjs +289 -0
- package/dist/rest/api.d.mts +1 -1
- package/dist/rest/blobs.d.mts +35 -35
- package/dist/rest/caller.d.mts +22 -20
- package/dist/rest/client.mjs +6 -6
- package/dist/rest/commits.d.mts +274 -274
- package/dist/rest/errors.d.mts +10 -10
- package/dist/rest/errors.mjs +1 -1
- package/dist/rest/events.d.mts +13 -11
- package/dist/rest/events.mjs +3 -1
- package/dist/rest/files.d.mts +78 -78
- package/dist/rest/forks.d.mts +170 -170
- package/dist/rest/handler.mjs +17 -8
- package/dist/rest/handlers.mjs +13 -7
- package/dist/rest/layer.d.mts +14 -0
- package/dist/rest/layer.mjs +53 -0
- package/dist/rest/listen.mjs +2 -2
- package/dist/rest/me.d.mts +18 -20
- package/dist/rest/me.mjs +1 -1
- package/dist/rest/merges.d.mts +10 -10
- package/dist/rest/namespace.d.mts +2 -0
- package/dist/rest/queue.d.mts +320 -320
- package/dist/rest/queue.mjs +1 -1
- package/dist/rest/refs.d.mts +207 -207
- package/dist/rest/refs.mjs +1 -1
- package/dist/rest/repos.d.mts +127 -127
- package/dist/rest/tags.d.mts +94 -94
- package/dist/rest/tokens.d.mts +248 -258
- package/dist/rest/tokens.mjs +10 -42
- package/dist/rest/topics.d.mts +154 -154
- package/dist/rest/topics.mjs +1 -1
- package/dist/rest/trees.d.mts +84 -84
- package/dist/rest/wire.d.mts +8 -4
- package/dist/rest/wire.mjs +3 -2
- package/dist/rest/work.d.mts +69 -69
- package/dist/rest/work.mjs +1 -1
- package/dist/server/check-fetch.mjs +9 -0
- package/dist/server/edge-node.d.mts +20 -0
- package/dist/server/edge-node.mjs +20 -0
- package/dist/server/edge.d.mts +10 -0
- package/dist/server/edge.mjs +23 -0
- package/dist/server/extension.mjs +3 -115
- package/dist/server/git-layer.d.mts +34 -6
- package/dist/server/git-layer.mjs +40 -18
- package/dist/server/git-namespace.d.mts +5 -4
- package/dist/server/git-namespace.mjs +10 -5
- package/dist/server/joined.d.mts +83 -0
- package/dist/server/joined.mjs +91 -0
- package/dist/server/registry.d.mts +9 -2
- package/dist/server/registry.mjs +179 -24
- package/dist/server/routes.mjs +2 -2
- package/dist/server/server.d.mts +11 -1
- package/dist/server/server.mjs +331 -201
- package/dist/server/uploads.d.mts +14 -0
- package/dist/server/uploads.mjs +15 -0
- package/dist/signin/context.d.mts +2 -1
- package/dist/signin/context.mjs +32 -37
- package/dist/signin/device.mjs +5 -5
- package/dist/signin/forms.mjs +1 -1
- package/dist/signin/grants.d.mts +2 -3
- package/dist/signin/grants.mjs +5 -5
- package/dist/signin/layer.d.mts +9 -0
- package/dist/signin/layer.mjs +41 -0
- package/dist/signin/namespace.d.mts +2 -0
- package/dist/signin/public.d.mts +6 -0
- package/dist/signin/public.mjs +5 -0
- package/dist/signin/route.mjs +47 -21
- package/dist/signin/web.mjs +3 -3
- package/dist/signin/wire.mjs +1 -1
- package/dist/storage/calls.d.mts +7 -8
- package/dist/storage/calls.mjs +17 -17
- package/dist/storage/clean-up.mjs +71 -34
- package/dist/storage/counted-bucket.mjs +34 -51
- package/dist/storage/fetch.mjs +1 -1
- package/dist/storage/host-bucket.mjs +17 -2
- package/dist/storage/index-build.d.mts +2 -2
- package/dist/storage/index-build.mjs +3 -3
- package/dist/storage/index-fetch.mjs +10 -6
- package/dist/storage/index-graph.mjs +1 -1
- package/dist/storage/index-layers.mjs +1 -1
- package/dist/storage/index-visible.mjs +1 -1
- package/dist/storage/layout.mjs +5 -0
- package/dist/storage/memory-budget.mjs +7 -1
- package/dist/storage/merge-cut.mjs +24 -1
- package/dist/storage/merge-fence.mjs +1 -1
- package/dist/storage/merge-plan.mjs +5 -2
- package/dist/storage/merge-row.mjs +1 -1
- package/dist/storage/merge-stream.mjs +16 -7
- package/dist/storage/merge-write.mjs +1 -1
- package/dist/storage/merge.d.mts +2 -2
- package/dist/storage/merge.mjs +1 -1
- package/dist/storage/object-rows.d.mts +2 -2
- package/dist/storage/object-rows.mjs +3 -3
- package/dist/storage/pack-ranges.d.mts +3 -1
- package/dist/storage/pack-ranges.mjs +168 -69
- package/dist/storage/pack-reads.mjs +4 -4
- package/dist/storage/pack-receive.d.mts +1 -1
- package/dist/storage/pack-receive.mjs +7 -9
- package/dist/storage/packs.d.mts +1 -1
- package/dist/storage/packs.mjs +45 -52
- package/dist/storage/placed-reads.mjs +81 -15
- package/dist/storage/prune-seen.mjs +126 -0
- package/dist/storage/prune-walk.mjs +87 -99
- package/dist/storage/prune.mjs +49 -14
- package/dist/storage/push-uploads.mjs +16 -18
- package/dist/storage/quarantine.d.mts +2 -2
- package/dist/storage/quarantine.mjs +51 -12
- package/dist/storage/ready.d.mts +2 -2
- package/dist/storage/ready.mjs +3 -3
- package/dist/storage/receive-bounds.d.mts +1 -1
- package/dist/storage/receive-files.mjs +1 -1
- package/dist/storage/receive-links.mjs +1 -1
- package/dist/storage/receive-state.d.mts +2 -2
- package/dist/storage/receive-state.mjs +1 -1
- package/dist/storage/receive-steps.mjs +1 -1
- package/dist/storage/repack-contained.mjs +2 -2
- package/dist/storage/repack-job.d.mts +2 -2
- package/dist/storage/repack-job.mjs +11 -17
- package/dist/storage/repack.d.mts +1 -1
- package/dist/storage/repack.mjs +9 -3
- package/dist/storage/rows.d.mts +2 -2
- package/dist/storage/rows.mjs +43 -4
- package/dist/storage/runs.d.mts +2 -2
- package/dist/storage/runs.mjs +15 -6
- package/dist/storage/send-list.mjs +6 -6
- package/dist/storage/single-flight.mjs +2 -2
- package/dist/storage/swap-walk.mjs +1 -1
- package/dist/storage/unpack.mjs +1 -1
- package/dist/store/call-count.d.mts +1 -1
- package/dist/store/call-count.mjs +125 -34
- package/dist/store/catalogue.d.mts +1 -1
- package/dist/store/catalogue.mjs +2 -2
- package/dist/store/crossing.mjs +2 -6
- package/dist/store/cursor-seal.mjs +1 -1
- package/dist/store/errors.d.mts +7 -3
- package/dist/store/errors.mjs +41 -13
- package/dist/store/job-try.mjs +130 -0
- package/dist/store/list-job.mjs +22 -16
- package/dist/store/outbox.d.mts +2 -2
- package/dist/store/outbox.mjs +112 -27
- package/dist/store/promises.d.mts +8 -3
- package/dist/store/promises.mjs +104 -94
- package/dist/store/queue-jobs.mjs +23 -2
- package/dist/store/records.d.mts +2 -2
- package/dist/store/records.mjs +16 -24
- package/dist/store/ref-rows.d.mts +2 -2
- package/dist/store/ref-rows.mjs +6 -6
- package/dist/store/reservations.mjs +35 -8
- package/dist/store/scopes.mjs +6 -14
- package/dist/store/topic-jobs.mjs +8 -8
- package/dist/sync/bound.d.mts +1 -3
- package/dist/sync/bound.mjs +30 -42
- package/dist/sync/bridge.d.mts +6 -0
- package/dist/sync/bridge.mjs +29 -0
- package/dist/sync/github.d.mts +5 -6
- package/dist/sync/github.mjs +37 -42
- package/dist/sync/http.mjs +15 -0
- package/dist/sync/import.mjs +17 -18
- package/dist/sync/layer.d.mts +9 -0
- package/dist/sync/layer.mjs +68 -0
- package/dist/sync/mirror.mjs +138 -59
- package/dist/sync/publish.mjs +15 -13
- package/dist/sync/step.mjs +221 -79
- package/dist/sync/tries.mjs +22 -15
- package/dist/sync.d.mts +3 -6
- package/dist/sync.mjs +3 -6
- package/dist/topics/advance.mjs +205 -90
- package/dist/topics/calls.mjs +8 -8
- package/dist/topics/directory.mjs +35 -12
- package/dist/topics/host.d.mts +5 -8
- package/dist/topics/host.mjs +42 -19
- package/dist/topics/layer.d.mts +381 -0
- package/dist/topics/layer.mjs +62 -0
- package/dist/topics/members.mjs +1 -1
- package/dist/topics/namespace.d.mts +2 -0
- package/dist/topics/public.d.mts +6 -0
- package/dist/topics/public.mjs +13 -0
- package/dist/topics/rows.mjs +12 -3
- package/dist/topics/topic.mjs +11 -10
- package/package.json +8 -13
- package/dist/access.d.mts +0 -2
- package/dist/access.mjs +0 -1
- package/dist/core/hooks/post-receive.mjs +0 -213
- package/dist/core/hooks/pre-receive.d.mts +0 -12
- package/dist/core/hooks/pre-receive.mjs +0 -36
- package/dist/lfs/repo.mjs +0 -42
- package/dist/server/extension.d.mts +0 -21
- package/dist/storage/promise-calls.mjs +0 -29
- package/dist/sync/import.d.mts +0 -10
- package/dist/sync/jobs.d.mts +0 -9
- package/dist/sync/jobs.mjs +0 -75
- package/dist/sync/mirror.d.mts +0 -13
- package/dist/sync/publish.d.mts +0 -6
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import { millis } from "../../contracts/promises.mjs";
|
|
2
|
+
import { keepsEvents } from "../../contracts/events.mjs";
|
|
2
3
|
import { isInternalId } from "../../contracts/ids.mjs";
|
|
4
|
+
import { pushRefLimit } from "../push-decide.mjs";
|
|
3
5
|
import { fail, gitError } from "../../contracts/result.mjs";
|
|
6
|
+
import { isWellFormed, utf8 } from "../../protocol/bytes/text.mjs";
|
|
4
7
|
import { decodeRecord } from "../../store/catalogue.mjs";
|
|
5
8
|
import { settleName } from "../../store/settle.mjs";
|
|
6
9
|
import { decodeRow, storeCall } from "../../store/errors.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
10
|
+
import { Delivered, FailedTry, Follower, appendEvents, cursorId, cursorRead, decodeLeading, decodeOutbox, decodeStamps, deliveryCursorId, eventBytes, eventId, eventLimits, failedKeyOf, failedPrefix, headKey, outboxCollections, outboxReads, repoEnvelope, rowBytes, shownEvent } from "../../store/outbox.mjs";
|
|
11
|
+
import { gitJob } from "../../store/job-try.mjs";
|
|
9
12
|
import { newChangeId, repoScope, scopeRepo, selfKey } from "../../store/scopes.mjs";
|
|
10
|
-
import { defineJob, isInfraError } from "@ref0/infra";
|
|
11
|
-
import * as Schema from "effect/Schema";
|
|
12
13
|
import * as Effect from "effect/Effect";
|
|
13
|
-
import * as
|
|
14
|
+
import * as Schema from "effect/Schema";
|
|
15
|
+
import { CurrentJob, Job, isInfraError, limits } from "@ref0/infra";
|
|
14
16
|
// src/core/events/deliver.ts
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
/** What each delivery's job name starts with: `git.deliver.<name>`. */
|
|
18
|
+
const deliverJobPrefix = "git.deliver.";
|
|
19
|
+
/** `delivery`'s job, `git.deliver.<delivery>`: one a scope, beside each other delivery's. */
|
|
20
|
+
const deliverJobName = (delivery) => `${deliverJobPrefix}${delivery}`;
|
|
21
|
+
/** The delivery a job named `name` runs, or `undefined` for a job no delivery's. */
|
|
22
|
+
const deliveryOf = (name) => name.startsWith(deliverJobPrefix) && name.length > 12 ? name.slice(12) : void 0;
|
|
23
|
+
/** One row per scope and delivery, so its events go one batch at a time, in `seq` order. */
|
|
17
24
|
const deliverJobKey = "deliver";
|
|
18
25
|
const DeliverData = /* @__PURE__ */ Schema.Struct({});
|
|
19
|
-
const deliverJobSchema = /* @__PURE__ */ Schema.toStandardSchemaV1(DeliverData);
|
|
20
26
|
/** How long a delivered event is kept for replay, unless the kept budget trims it first. */
|
|
21
27
|
const keptFor = 864e5;
|
|
22
28
|
/** How long a scope waits before it looks again at a scope that held its name's sequence. */
|
|
@@ -35,8 +41,19 @@ const defaultDeliverRetry = {
|
|
|
35
41
|
maxDelay: "1 hour",
|
|
36
42
|
within: "3 days"
|
|
37
43
|
};
|
|
38
|
-
/**
|
|
39
|
-
|
|
44
|
+
/**
|
|
45
|
+
* `handlers`, as a try calls them. A handler is interrupted at the try's timeout, and its failure,
|
|
46
|
+
* as its defect, sends its run again.
|
|
47
|
+
*/
|
|
48
|
+
const runHandlersOf = (handlers) => handlers.handlers.map(({ types, handle }) => ({
|
|
49
|
+
takes: (type) => types.has(type),
|
|
50
|
+
call: (events, attempt) => Effect.orDie(handle({
|
|
51
|
+
events,
|
|
52
|
+
attempt
|
|
53
|
+
}))
|
|
54
|
+
}));
|
|
55
|
+
/** The handler of `type`'s events, the first that takes it, or `undefined` for none. */
|
|
56
|
+
const handlerOf = (handlers, type) => handlers.find((handler) => handler.takes(type));
|
|
40
57
|
/** A read infra refused because its answer passed 16 MiB. */
|
|
41
58
|
const tooLarge = (error) => error.code === "RESOURCE_EXHAUSTED" && error.context?.reason === "too-large";
|
|
42
59
|
/**
|
|
@@ -51,6 +68,78 @@ const readEvents = (store, scope, reads, limit) => {
|
|
|
51
68
|
})));
|
|
52
69
|
return read(limit).pipe(Effect.catchIf(tooLarge, () => read(largeReadRows)));
|
|
53
70
|
};
|
|
71
|
+
/**
|
|
72
|
+
* Where a delivery stands in a scope it has no cursor row in yet: the retained beginning, just
|
|
73
|
+
* before the oldest event kept, whose earlier events' bytes the head counts as trimmed, since a
|
|
74
|
+
* trim deletes the oldest first. With none kept, past the last. One read, of one event.
|
|
75
|
+
*/
|
|
76
|
+
const retainedStart = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, head) {
|
|
77
|
+
const read = {
|
|
78
|
+
collection: outboxCollections.events,
|
|
79
|
+
limit: 1
|
|
80
|
+
};
|
|
81
|
+
const snapshot = yield* storeCall(() => store.read(scope, [read]));
|
|
82
|
+
const [oldest] = yield* decodeStamps(snapshot.results[0] ?? []);
|
|
83
|
+
return oldest === void 0 ? {
|
|
84
|
+
seq: head.next - 1,
|
|
85
|
+
bytes: head.bytes
|
|
86
|
+
} : {
|
|
87
|
+
seq: oldest.seq - 1,
|
|
88
|
+
bytes: head.trimmed
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
/** A cursor row, read by `cursorRead`, or none: a delivery that hasn't moved in the scope yet. */
|
|
92
|
+
const decodeCursor = (rows) => {
|
|
93
|
+
const [row] = rows ?? [];
|
|
94
|
+
return row === void 0 ? Effect.succeed(void 0) : decodeRow(Delivered, row, "The delivery cursor");
|
|
95
|
+
};
|
|
96
|
+
/** A delivery's cursor in `scope`, from its `cursorRead` rows, or its retained beginning. */
|
|
97
|
+
const cursorOf = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, head, rows) {
|
|
98
|
+
const cursor = yield* decodeCursor(rows);
|
|
99
|
+
if (cursor !== void 0) return cursor;
|
|
100
|
+
return yield* retainedStart(store, scope, head);
|
|
101
|
+
});
|
|
102
|
+
/** Each delivery's cursor, from their `cursorRead`s' results, in the order the reads named them. */
|
|
103
|
+
const decodeCursors = /* @__PURE__ */ Effect.fnUntraced(function* (deliveries, results) {
|
|
104
|
+
const cursors = /* @__PURE__ */ new Map();
|
|
105
|
+
for (const [index, delivery] of deliveries.entries()) cursors.set(delivery, yield* decodeCursor(results[index]));
|
|
106
|
+
return cursors;
|
|
107
|
+
});
|
|
108
|
+
/** The slowest of `places`, or `undefined` when one is missing: a delivery that hasn't moved. */
|
|
109
|
+
const slowest = (places) => {
|
|
110
|
+
let least;
|
|
111
|
+
for (const place of places) {
|
|
112
|
+
if (place === void 0) return void 0;
|
|
113
|
+
if (least === void 0 || place.seq < least.seq) least = place;
|
|
114
|
+
}
|
|
115
|
+
return least;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Moves `delivery`'s cursor to `value`, in a new row, and then the low-water mark to the slowest
|
|
119
|
+
* active delivery, when each has a cursor and the slowest has passed the mark, as `read` showed
|
|
120
|
+
* them. A low-water row that a crash between the two leaves behind only holds more: the next move
|
|
121
|
+
* writes it. Answers the low-water mark after.
|
|
122
|
+
*/
|
|
123
|
+
const moveCursor = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, delivery, value, read) {
|
|
124
|
+
const own = read.cursors.get(delivery);
|
|
125
|
+
const moved = own === void 0 || own.seq < value.seq ? value : own;
|
|
126
|
+
const id = deliveryCursorId(delivery, value.seq);
|
|
127
|
+
if (moved === value) yield* addCursor(store, scope, {
|
|
128
|
+
collection: outboxCollections.cursors,
|
|
129
|
+
id,
|
|
130
|
+
value
|
|
131
|
+
});
|
|
132
|
+
const places = [...read.cursors].map(([name, at]) => name === delivery ? moved : at);
|
|
133
|
+
const floor = slowest(places);
|
|
134
|
+
if (floor === void 0 || floor.seq <= read.delivered.seq) return read.delivered;
|
|
135
|
+
const mark = {
|
|
136
|
+
collection: outboxCollections.delivered,
|
|
137
|
+
id: cursorId(floor.seq),
|
|
138
|
+
value: floor
|
|
139
|
+
};
|
|
140
|
+
yield* addCursor(store, scope, mark);
|
|
141
|
+
return floor;
|
|
142
|
+
});
|
|
54
143
|
const again = (at) => ({
|
|
55
144
|
kind: "settle",
|
|
56
145
|
outcome: at === void 0 ? { kind: "more" } : {
|
|
@@ -63,22 +152,28 @@ const settle = (outcome) => ({
|
|
|
63
152
|
outcome
|
|
64
153
|
});
|
|
65
154
|
/**
|
|
66
|
-
* Which of the scopes that held this scope's names' sequences before still owe theirs
|
|
67
|
-
* hasn't
|
|
68
|
-
* until a retry delivers them or a discard skips them, so a
|
|
69
|
-
*
|
|
155
|
+
* Which of the scopes that held this scope's names' sequences before still owe theirs to this
|
|
156
|
+
* try's delivery: each whose cursor for it hasn't reached where this one goes on. One whose
|
|
157
|
+
* delivery failed still owes them, until a retry delivers them or a discard skips them, so a
|
|
158
|
+
* name's `seq` only goes up, for each delivery. Drops from `after` only those every delivery is
|
|
159
|
+
* past, by the earlier scope's low-water mark, and answers the first `seq` here they hold for this
|
|
160
|
+
* delivery, or `undefined` when none does.
|
|
70
161
|
*/
|
|
71
162
|
const followed = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, scope, version, head) {
|
|
72
163
|
const { after } = head;
|
|
73
164
|
if (after === void 0) return void 0;
|
|
74
165
|
const owing = [];
|
|
166
|
+
const kept = [];
|
|
75
167
|
const waiter = scopeRepo(scope);
|
|
76
168
|
for (const follows of after) {
|
|
77
169
|
const before = repoScope(follows.internalId);
|
|
78
|
-
const
|
|
170
|
+
const reads = [...outboxReads, cursorRead(parts.delivery)];
|
|
171
|
+
const snapshot = yield* storeCall(() => parts.store.read(before, reads));
|
|
79
172
|
const outbox = yield* decodeOutbox(snapshot.results);
|
|
173
|
+
const cursor = yield* cursorOf(parts.store, before, outbox.head, snapshot.results[2]);
|
|
80
174
|
const owed = Math.min(follows.seq, outbox.head.next - 1);
|
|
81
|
-
if (
|
|
175
|
+
if (cursor.seq < owed) owing.push(follows);
|
|
176
|
+
if (cursor.seq < owed || outbox.delivered.seq < owed) kept.push(follows);
|
|
82
177
|
if (owing.at(-1) !== follows || waiter === void 0) continue;
|
|
83
178
|
const row = {
|
|
84
179
|
collection: outboxCollections.followers,
|
|
@@ -87,12 +182,12 @@ const followed = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, scop
|
|
|
87
182
|
};
|
|
88
183
|
yield* addNew(parts.store, before, row);
|
|
89
184
|
}
|
|
90
|
-
if (
|
|
185
|
+
if (kept.length < after.length) {
|
|
91
186
|
const left = {
|
|
92
187
|
...head,
|
|
93
|
-
after:
|
|
188
|
+
after: kept
|
|
94
189
|
};
|
|
95
|
-
if (
|
|
190
|
+
if (kept.length === 0) delete left.after;
|
|
96
191
|
const change = {
|
|
97
192
|
id: newChangeId(),
|
|
98
193
|
expect: version,
|
|
@@ -111,9 +206,10 @@ const followersRead = {
|
|
|
111
206
|
limit: 20
|
|
112
207
|
};
|
|
113
208
|
/**
|
|
114
|
-
* Makes
|
|
115
|
-
* `seq` the
|
|
116
|
-
* version: one that loses leaves them for the next send, which wakes
|
|
209
|
+
* Makes each delivery's job due now in each scope whose `followers` row, `snapshot`'s last result, has a
|
|
210
|
+
* `seq` the low-water mark at `delivered` has passed, so every delivery has, then deletes their
|
|
211
|
+
* rows in one commit at its version: one that loses leaves them for the next send, which wakes
|
|
212
|
+
* them again. A waiter a slower delivery still holds looks again after `followWait`.
|
|
117
213
|
*/
|
|
118
214
|
const wakeFollowers = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, scope, snapshot, delivered) {
|
|
119
215
|
const woken = [];
|
|
@@ -121,7 +217,7 @@ const wakeFollowers = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store,
|
|
|
121
217
|
const { id } = row;
|
|
122
218
|
const { seq } = yield* decodeRow(Follower, row, `The follower '${id}'`);
|
|
123
219
|
if (seq > delivered.seq) continue;
|
|
124
|
-
if (isInternalId(id)) yield* storeCall(() => parts.store.add(repoScope(id), { jobs: [parts.wake()] }));
|
|
220
|
+
if (isInternalId(id)) yield* storeCall(() => parts.store.add(repoScope(id), { jobs: [...parts.wake()] }));
|
|
125
221
|
woken.push({
|
|
126
222
|
collection: row.collection,
|
|
127
223
|
id
|
|
@@ -136,13 +232,47 @@ const wakeFollowers = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store,
|
|
|
136
232
|
yield* storeCall(() => store.commit(scope, change));
|
|
137
233
|
});
|
|
138
234
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
|
|
143
|
-
|
|
235
|
+
* Moves the low-water mark up to the slowest active cursor, and wakes the followers it passes, for
|
|
236
|
+
* a drained try whose own cursor is past the mark: a try that stopped between `moveCursor`'s two
|
|
237
|
+
* writes left it behind, and no send is left to move it.
|
|
238
|
+
*/
|
|
239
|
+
const settleMark = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, scope) {
|
|
240
|
+
const reads = [
|
|
241
|
+
...outboxReads,
|
|
242
|
+
...parts.deliveries.map(cursorRead),
|
|
243
|
+
followersRead
|
|
244
|
+
];
|
|
245
|
+
const snapshot = yield* storeCall(() => store.read(scope, reads));
|
|
246
|
+
const { delivered } = yield* decodeOutbox(snapshot.results);
|
|
247
|
+
const cursors = yield* decodeCursors(parts.deliveries, snapshot.results.slice(2));
|
|
248
|
+
const own = cursors.get(parts.delivery);
|
|
249
|
+
if (own === void 0) return;
|
|
250
|
+
const mark = yield* moveCursor(store, scope, parts.delivery, own, {
|
|
251
|
+
delivered,
|
|
252
|
+
cursors
|
|
253
|
+
});
|
|
254
|
+
yield* wakeFollowers(parts, store, scope, snapshot, mark);
|
|
255
|
+
});
|
|
256
|
+
/**
|
|
257
|
+
* Deletes what every active delivery has passed and is old: each event behind the slowest cursor
|
|
258
|
+
* older than `keptFor`, and the oldest past the kept budget whatever their age, with the low-water
|
|
259
|
+
* and cursor rows behind each newest, and a removed delivery's cursor and `failed` rows, at most
|
|
260
|
+
* `trimBatch` of each. A delivery with no cursor yet holds every event. Answers the bytes of events
|
|
261
|
+
* it deleted, and `at`: now when `delivery` has events left to send or there's more to trim; when
|
|
262
|
+
* the oldest event left is due to be trimmed; or `undefined` when none is left, or a slower
|
|
263
|
+
* delivery holds it, whose own tries trim once they pass it. `lost` says a write since its read
|
|
264
|
+
* beat its commit, so it trimmed nothing and should run again.
|
|
144
265
|
*/
|
|
145
|
-
const trim = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, now) {
|
|
266
|
+
const trim = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, scope, now) {
|
|
267
|
+
const { delivery, deliveries } = parts;
|
|
268
|
+
const sweep = [{
|
|
269
|
+
collection: outboxCollections.cursors,
|
|
270
|
+
limit: 1001
|
|
271
|
+
}, {
|
|
272
|
+
collection: outboxCollections.outbox,
|
|
273
|
+
prefix: failedPrefix,
|
|
274
|
+
limit: 1001
|
|
275
|
+
}];
|
|
146
276
|
const reads = (limit) => [
|
|
147
277
|
{
|
|
148
278
|
collection: headKey.collection,
|
|
@@ -155,26 +285,39 @@ const trim = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, now) {
|
|
|
155
285
|
{
|
|
156
286
|
collection: outboxCollections.events,
|
|
157
287
|
limit
|
|
158
|
-
}
|
|
288
|
+
},
|
|
289
|
+
...deliveries.map(cursorRead),
|
|
290
|
+
...sweep
|
|
159
291
|
];
|
|
160
292
|
const { snapshot, limit } = yield* readEvents(store, scope, reads, trimBatch);
|
|
161
|
-
const [headRows = [],
|
|
162
|
-
const
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const
|
|
293
|
+
const [headRows = [], markRows = [], eventRows = []] = snapshot.results;
|
|
294
|
+
const newest = snapshot.results.slice(3, 3 + deliveries.length);
|
|
295
|
+
const [cursorRows = [], failedRows = []] = snapshot.results.slice(3 + deliveries.length);
|
|
296
|
+
const { head } = yield* decodeOutbox([headRows, markRows]);
|
|
297
|
+
const events = yield* decodeStamps(eventRows);
|
|
298
|
+
const cursors = yield* decodeCursors(deliveries, newest);
|
|
299
|
+
const floor = slowest([...cursors.values()]);
|
|
300
|
+
const own = cursors.get(delivery);
|
|
301
|
+
const keep = new Set(newest.flatMap((rows) => rows.slice(0, 1).map((row) => row.id)));
|
|
302
|
+
const failing = new Set(deliveries.map((name) => failedKeyOf(name).id));
|
|
303
|
+
const gone = [
|
|
304
|
+
...markRows.slice(1),
|
|
305
|
+
...cursorRows.filter((row) => !keep.has(row.id)),
|
|
306
|
+
...failedRows.filter((row) => !failing.has(row.id))
|
|
307
|
+
].map(({ collection, id }) => ({
|
|
167
308
|
collection,
|
|
168
309
|
id
|
|
169
310
|
}));
|
|
311
|
+
let kept = floor === void 0 ? 0 : floor.bytes - head.trimmed;
|
|
312
|
+
let trimmed = 0;
|
|
170
313
|
let left;
|
|
171
314
|
for (const event of events) {
|
|
172
315
|
const old = event.at + 864e5 <= now || kept > eventLimits.kept;
|
|
173
|
-
if (event.seq >
|
|
316
|
+
if (floor === void 0 || event.seq > floor.seq || !old) {
|
|
174
317
|
left = event;
|
|
175
318
|
break;
|
|
176
319
|
}
|
|
177
|
-
const bytes =
|
|
320
|
+
const bytes = event.bytes;
|
|
178
321
|
kept -= bytes;
|
|
179
322
|
trimmed += bytes;
|
|
180
323
|
gone.push({
|
|
@@ -204,11 +347,21 @@ const trim = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, now) {
|
|
|
204
347
|
lost: true
|
|
205
348
|
};
|
|
206
349
|
}
|
|
207
|
-
if (left !== void 0)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
350
|
+
if (left !== void 0) {
|
|
351
|
+
if (own === void 0 || left.seq > own.seq) return {
|
|
352
|
+
trimmed,
|
|
353
|
+
at: now
|
|
354
|
+
};
|
|
355
|
+
if (floor === void 0 || left.seq > floor.seq) return {
|
|
356
|
+
trimmed,
|
|
357
|
+
at: void 0
|
|
358
|
+
};
|
|
359
|
+
return {
|
|
360
|
+
trimmed,
|
|
361
|
+
at: left.at + keptFor
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
const more = events.length === limit || markRows.length > trimBatch || cursorRows.length > trimBatch || failedRows.length > trimBatch;
|
|
212
365
|
return {
|
|
213
366
|
trimmed,
|
|
214
367
|
at: more ? now : void 0
|
|
@@ -228,13 +381,19 @@ const trimsFirst = (head, delivered) => delivered.bytes - head.trimmed > eventLi
|
|
|
228
381
|
/** How many times a try reads its scope while each read settles a name first. */
|
|
229
382
|
const settleReads = 2;
|
|
230
383
|
/**
|
|
231
|
-
* Reads the scope's outbox once its name is settled: a create's or a
|
|
232
|
-
* it, reads again and goes on, so it sends in the same try (#1506).
|
|
233
|
-
* of `settleReads` reads found a name to settle, a write racing the
|
|
384
|
+
* Reads the scope's outbox, with `delivery`'s cursor, once its name is settled: a create's or a
|
|
385
|
+
* rename's first try settles it, reads again and goes on, so it sends in the same try (#1506).
|
|
386
|
+
* Answers `undefined` when each of `settleReads` reads found a name to settle, a write racing the
|
|
387
|
+
* settle, for the next try.
|
|
234
388
|
*/
|
|
235
|
-
const readSettled = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope) {
|
|
389
|
+
const readSettled = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, delivery) {
|
|
236
390
|
for (let reads = 0; reads < settleReads; reads += 1) {
|
|
237
|
-
const
|
|
391
|
+
const all = [
|
|
392
|
+
selfKey,
|
|
393
|
+
...outboxReads,
|
|
394
|
+
cursorRead(delivery)
|
|
395
|
+
];
|
|
396
|
+
const snapshot = yield* storeCall(() => store.read(scope, all));
|
|
238
397
|
const record = yield* decodeRecord(snapshot.results[0]?.[0]);
|
|
239
398
|
const { head, delivered } = yield* decodeOutbox(snapshot.results.slice(1));
|
|
240
399
|
const read = {
|
|
@@ -242,10 +401,12 @@ const readSettled = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope) {
|
|
|
242
401
|
head,
|
|
243
402
|
record
|
|
244
403
|
};
|
|
245
|
-
if (
|
|
404
|
+
if (yield* settleName(store, scope, read)) continue;
|
|
405
|
+
return {
|
|
246
406
|
snapshot,
|
|
247
407
|
head,
|
|
248
|
-
delivered
|
|
408
|
+
delivered,
|
|
409
|
+
cursor: yield* cursorOf(store, scope, head, snapshot.results[3])
|
|
249
410
|
};
|
|
250
411
|
}
|
|
251
412
|
});
|
|
@@ -255,49 +416,115 @@ const readSettled = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope) {
|
|
|
255
416
|
* Then it reads the next batch past the cursor. Drained, it trims past the kept budget and
|
|
256
417
|
* past `keptFor`, and settles at the oldest event's trim, or done when none is left.
|
|
257
418
|
*/
|
|
258
|
-
const prepare = /* @__PURE__ */ Effect.fnUntraced(function* (parts, job, store) {
|
|
419
|
+
const prepare = /* @__PURE__ */ Effect.fnUntraced(function* (parts, handlers, job, store) {
|
|
259
420
|
const { scope } = job;
|
|
260
|
-
const settled = yield* readSettled(store, scope);
|
|
421
|
+
const settled = yield* readSettled(store, scope, parts.delivery);
|
|
261
422
|
if (settled === void 0) return again();
|
|
262
|
-
const { snapshot, head, delivered } = settled;
|
|
423
|
+
const { snapshot, head, delivered, cursor } = settled;
|
|
263
424
|
if (trimsFirst(head, delivered)) {
|
|
264
|
-
const { trimmed, lost } = yield* trim(store, scope, yield* parts.now);
|
|
425
|
+
const { trimmed, lost } = yield* trim(parts, store, scope, yield* parts.now);
|
|
265
426
|
if (trimmed > 0 || lost === true) return again();
|
|
266
427
|
}
|
|
267
428
|
const held = yield* followed(parts, store, scope, snapshot.version, head);
|
|
268
429
|
const waited = again((yield* parts.now) + followWait);
|
|
269
|
-
if (held !== void 0 && held <=
|
|
270
|
-
const after = eventId(
|
|
430
|
+
if (held !== void 0 && held <= cursor.seq + 1) return waited;
|
|
431
|
+
const after = eventId(cursor.seq);
|
|
271
432
|
const reads = (limit) => [{
|
|
272
433
|
collection: outboxCollections.events,
|
|
273
434
|
after,
|
|
274
435
|
limit
|
|
275
436
|
}];
|
|
276
437
|
const { snapshot: batch, limit } = yield* readEvents(store, scope, reads, 101);
|
|
277
|
-
const fetched = yield*
|
|
438
|
+
const { events: fetched, stop } = yield* decodeLeading(batch.results[0] ?? []);
|
|
439
|
+
if (fetched.length === 0 && stop !== void 0 && stop.seq < head.next) return {
|
|
440
|
+
kind: "stop",
|
|
441
|
+
seq: stop.seq,
|
|
442
|
+
error: stop.error
|
|
443
|
+
};
|
|
278
444
|
const bound = Math.min(head.next, held ?? head.next);
|
|
279
445
|
const events = fetched.filter((event) => event.seq < bound);
|
|
280
446
|
if (events.length > 0) {
|
|
281
447
|
const sent = events.slice(0, limit - 1);
|
|
448
|
+
const { run, handler } = runOf(handlers, sent);
|
|
449
|
+
const more = fetched.length >= limit || sent.length < events.length || stop !== void 0;
|
|
450
|
+
const whole = more && run.length === sent.length ? yield* pushEnd(store, scope, run, bound) : [];
|
|
451
|
+
const last = !more && run.length === sent.length;
|
|
282
452
|
return {
|
|
283
453
|
kind: "send",
|
|
284
|
-
cursor
|
|
285
|
-
events:
|
|
286
|
-
|
|
454
|
+
cursor,
|
|
455
|
+
events: [...run, ...whole],
|
|
456
|
+
handler,
|
|
457
|
+
last
|
|
287
458
|
};
|
|
288
459
|
}
|
|
289
460
|
if (held !== void 0) return waited;
|
|
290
461
|
if (fetched.length > 0) return again();
|
|
291
|
-
|
|
462
|
+
if (cursor.seq > delivered.seq) yield* settleMark(parts, store, scope);
|
|
463
|
+
const { at } = yield* trim(parts, store, scope, yield* parts.now);
|
|
292
464
|
return settle(at === void 0 ? void 0 : {
|
|
293
465
|
kind: "more",
|
|
294
466
|
at
|
|
295
467
|
});
|
|
296
468
|
});
|
|
297
469
|
/**
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
470
|
+
* The run `sent` starts with: the types no handler takes before the first one a handler takes,
|
|
471
|
+
* which move the cursor alone, so a handler's run starts at its first event, the one a discard of
|
|
472
|
+
* its failure skips; else its events up to the first another handler takes, unhandled types among
|
|
473
|
+
* them, with its handler; or every event when none takes one.
|
|
474
|
+
*/
|
|
475
|
+
const runOf = (handlers, sent) => {
|
|
476
|
+
let handler;
|
|
477
|
+
let end = sent.length;
|
|
478
|
+
for (const [index, event] of sent.entries()) {
|
|
479
|
+
const own = handlerOf(handlers, event.type);
|
|
480
|
+
if (own === void 0) continue;
|
|
481
|
+
if (handler === void 0 && index > 0) {
|
|
482
|
+
end = index;
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
if (handler === void 0) handler = own;
|
|
486
|
+
else if (own !== handler) {
|
|
487
|
+
end = index;
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return {
|
|
492
|
+
run: sent.slice(0, end),
|
|
493
|
+
handler
|
|
494
|
+
};
|
|
495
|
+
};
|
|
496
|
+
/**
|
|
497
|
+
* The rest of the push `run` ends in: its `ref.updated` events past the run's last, below `bound`,
|
|
498
|
+
* so a push is never split. A push moves at most `pushRefLimit` refs, so the read ends by then. A
|
|
499
|
+
* row it can't read ends the push there, unread, as `decodeLeading` stops: the push before it is
|
|
500
|
+
* sent, and the next try starts at the row, stops at it and notes its `seq` for a discard.
|
|
501
|
+
*/
|
|
502
|
+
const pushEnd = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, run, bound) {
|
|
503
|
+
const tail = run.at(-1);
|
|
504
|
+
if (tail?.type !== "ref.updated") return [];
|
|
505
|
+
const id = tail.push.id;
|
|
506
|
+
const rest = [];
|
|
507
|
+
let after = tail.seq;
|
|
508
|
+
while (rest.length < pushRefLimit) {
|
|
509
|
+
const reads = (limit) => [{
|
|
510
|
+
collection: outboxCollections.events,
|
|
511
|
+
after: eventId(after),
|
|
512
|
+
limit
|
|
513
|
+
}];
|
|
514
|
+
const { snapshot, limit } = yield* readEvents(store, scope, reads, 100);
|
|
515
|
+
const { events: page, stop } = yield* decodeLeading(snapshot.results[0] ?? []);
|
|
516
|
+
const ends = page.findIndex((event) => event.seq >= bound || event.type !== "ref.updated" || event.push.id !== id);
|
|
517
|
+
rest.push(...ends === -1 ? page : page.slice(0, ends));
|
|
518
|
+
const next = page.at(-1);
|
|
519
|
+
if (ends !== -1 || stop !== void 0 || next === void 0 || page.length < limit) break;
|
|
520
|
+
after = next.seq;
|
|
521
|
+
}
|
|
522
|
+
return rest;
|
|
523
|
+
});
|
|
524
|
+
/**
|
|
525
|
+
* A try's last part, once the host took the batch: the delivery's cursor moves past it, in a new
|
|
526
|
+
* row the try's claim fences, so a stale try moves nothing, and the low-water mark with it when
|
|
527
|
+
* it was the slowest. A skip a discard recorded at the same `seq` already moved it. A batch that sent the head's last event trims and settles as a drained
|
|
301
528
|
* `prepare` would, when `sentLast` holds. Otherwise one that sent the last event it read trims
|
|
302
529
|
* past the kept budget, up to `trimBatch`, and each try after trims on. Steady traffic whose batches outweigh the smaller
|
|
303
530
|
* events a trim removes can hold kept past the budget while it lasts, under `drainCeiling`. Past
|
|
@@ -308,35 +535,43 @@ const advance = /* @__PURE__ */ Effect.fnUntraced(function* (parts, job, store,
|
|
|
308
535
|
const last = batch.events.at(-1);
|
|
309
536
|
const again = { kind: "more" };
|
|
310
537
|
if (last === void 0) return again;
|
|
311
|
-
const
|
|
538
|
+
const { deliveries } = parts;
|
|
539
|
+
const reads = [
|
|
540
|
+
...outboxReads,
|
|
541
|
+
...deliveries.map(cursorRead),
|
|
542
|
+
followersRead
|
|
543
|
+
];
|
|
544
|
+
const snapshot = yield* storeCall(() => store.read(scope, reads));
|
|
312
545
|
const outbox = yield* decodeOutbox(snapshot.results);
|
|
546
|
+
const cursors = yield* decodeCursors(deliveries, snapshot.results.slice(2));
|
|
547
|
+
const own = cursors.get(parts.delivery);
|
|
313
548
|
const bytes = batch.events.reduce((sum, event) => sum + eventBytes(event), batch.cursor.bytes);
|
|
314
549
|
const value = {
|
|
315
550
|
seq: last.seq,
|
|
316
551
|
bytes
|
|
317
552
|
};
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
value
|
|
553
|
+
const read = {
|
|
554
|
+
delivered: outbox.delivered,
|
|
555
|
+
cursors
|
|
322
556
|
};
|
|
323
|
-
|
|
324
|
-
yield* wakeFollowers(parts, store, scope, snapshot,
|
|
325
|
-
if (sentLast(outbox, last,
|
|
326
|
-
const { at } = yield* trim(store, scope, yield* parts.now);
|
|
557
|
+
const mark = yield* moveCursor(store, scope, parts.delivery, value, read);
|
|
558
|
+
yield* wakeFollowers(parts, store, scope, snapshot, mark);
|
|
559
|
+
if (sentLast(outbox, own, last, mark)) {
|
|
560
|
+
const { at } = yield* trim(parts, store, scope, yield* parts.now);
|
|
327
561
|
return at === void 0 ? void 0 : {
|
|
328
562
|
kind: "more",
|
|
329
563
|
at
|
|
330
564
|
};
|
|
331
565
|
}
|
|
332
|
-
if (batch.last && bytes - outbox.head.trimmed > eventLimits.kept) yield* trim(store, scope, yield* parts.now);
|
|
566
|
+
if (batch.last && mark.bytes - outbox.head.trimmed > eventLimits.kept) yield* trim(parts, store, scope, yield* parts.now);
|
|
333
567
|
return again;
|
|
334
568
|
});
|
|
335
569
|
/**
|
|
336
570
|
* Whether the try that sent `last` leaves its scope so the next try's `prepare` would only trim
|
|
337
|
-
* and settle, as `outbox
|
|
338
|
-
*
|
|
339
|
-
* the next try
|
|
571
|
+
* and settle, as `outbox` and the delivery's cursor `own`, read before it moved and the low-water
|
|
572
|
+
* mark moved to `mark`, show. Then the try trims and settles itself, with the same answer, and
|
|
573
|
+
* saves the next try (#1506). Any doubt is `false`, and the next try runs. Each part is a step
|
|
574
|
+
* `prepare` would take first, or one that finds more:
|
|
340
575
|
* - the cursor moves to the head's last event, so a read past it finds no event to send;
|
|
341
576
|
* - no name waits to be settled, which `settleName` would write first;
|
|
342
577
|
* - no scope it follows, which `followed` would read, and which may hold it;
|
|
@@ -344,7 +579,7 @@ const advance = /* @__PURE__ */ Effect.fnUntraced(function* (parts, job, store,
|
|
|
344
579
|
* A write since the read adds events and saves the job while this try holds it, so the queue runs
|
|
345
580
|
* it again by the earlier of the save and the settle's `at`, as it does for a drained `prepare`.
|
|
346
581
|
*/
|
|
347
|
-
const sentLast = (outbox, last,
|
|
582
|
+
const sentLast = (outbox, own, last, mark) => (own === void 0 || own.seq < last.seq) && outbox.head.next === last.seq + 1 && outbox.head.unconfirmed === void 0 && outbox.head.after === void 0 && !trimsFirst(outbox.head, mark);
|
|
348
583
|
/** Adds a row, unless one is there by its key: then that one stays. */
|
|
349
584
|
const addNew = (store, scope, row) => storeCall(() => store.add(scope, { put: [row] })).pipe(Effect.catchIf((error) => error.code === "ALREADY_EXISTS", () => Effect.void));
|
|
350
585
|
/** Adds a cursor row: one already at its `seq`, a discard's skip, moved the cursor there first. */
|
|
@@ -354,63 +589,70 @@ const addCursor = (store, scope, row) => addNew(store, scope, row);
|
|
|
354
589
|
* once the row is deleted and added again.
|
|
355
590
|
*/
|
|
356
591
|
const newerThan = (note, job) => note.claim > job.claim;
|
|
357
|
-
/** Drops the
|
|
592
|
+
/** Drops the note when it's `job`'s try's or an older one's, whose `onFailure` has run. */
|
|
358
593
|
const dropNote = (sending, job) => {
|
|
359
594
|
const note = sending.get(job.scope);
|
|
360
595
|
if (note !== void 0 && !newerThan(note, job)) sending.delete(job.scope);
|
|
361
596
|
};
|
|
362
597
|
/**
|
|
363
|
-
*
|
|
364
|
-
* throw or a timeout sends the same
|
|
365
|
-
* the
|
|
366
|
-
*
|
|
598
|
+
* A delivery's try, in one scope: the next run past its cursor, up to 100 events and never part of
|
|
599
|
+
* a push, to its handler. A throw, a failure or a timeout sends the same run again, so later runs
|
|
600
|
+
* wait behind one that fails; once the handler took it, the cursor moves past it. A run of types
|
|
601
|
+
* no handler takes moves the cursor with no call. When none is left to send, the try trims and
|
|
602
|
+
* sleeps until the oldest event kept is due to go. `sending` notes the run while a handler has it.
|
|
367
603
|
*/
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
seq
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
604
|
+
const deliverTry = (parts, sending) => {
|
|
605
|
+
const handlers = runHandlersOf(parts);
|
|
606
|
+
return Effect.fnUntraced(function* () {
|
|
607
|
+
const job = yield* CurrentJob.current;
|
|
608
|
+
const store = yield* CurrentJob.store;
|
|
609
|
+
dropNote(sending, job);
|
|
610
|
+
const prepared = yield* prepare(parts, handlers, job, store);
|
|
611
|
+
if (prepared.kind === "settle") return prepared.outcome;
|
|
612
|
+
const seq = prepared.kind === "stop" ? prepared.seq : prepared.events[0]?.seq;
|
|
613
|
+
dropNote(sending, job);
|
|
614
|
+
if (seq !== void 0 && !sending.has(job.scope)) sending.set(job.scope, {
|
|
615
|
+
claim: job.claim,
|
|
616
|
+
seq
|
|
617
|
+
});
|
|
618
|
+
if (prepared.kind === "stop") return yield* Effect.fail(prepared.error);
|
|
619
|
+
const { handler } = prepared;
|
|
620
|
+
const events = prepared.events.filter((event) => handler?.takes(event.type)).map(shownEvent);
|
|
621
|
+
if (handler !== void 0) yield* handler.call(events, job.attempt);
|
|
622
|
+
dropNote(sending, job);
|
|
623
|
+
return yield* advance(parts, job, store, prepared);
|
|
383
624
|
});
|
|
384
|
-
dropNote(sending, job);
|
|
385
|
-
return runJobTry(advance(parts, job, context.store, prepared));
|
|
386
625
|
};
|
|
387
626
|
/**
|
|
388
|
-
*
|
|
389
|
-
* or none. A claim out of tries runs no try, so its `onFailure` finds a note of an older
|
|
390
|
-
* none, and names no event.
|
|
627
|
+
* `delivery`'s `failed` row for `job`'s last try: the batch `sending` noted for that try, by its
|
|
628
|
+
* `claim`, or none. A claim out of tries runs no try, so its `onFailure` finds a note of an older
|
|
629
|
+
* try, or none, and names no event.
|
|
391
630
|
*/
|
|
392
|
-
const failedTry = (sending, job) => {
|
|
631
|
+
const failedTry = (sending, delivery, job) => {
|
|
393
632
|
const noted = sending.get(job.scope);
|
|
394
633
|
dropNote(sending, job);
|
|
395
|
-
|
|
634
|
+
const value = noted?.claim === job.claim ? {
|
|
396
635
|
claim: noted.claim,
|
|
397
636
|
seq: noted.seq
|
|
398
637
|
} : { claim: job.claim };
|
|
638
|
+
return {
|
|
639
|
+
...failedKeyOf(delivery),
|
|
640
|
+
value
|
|
641
|
+
};
|
|
399
642
|
};
|
|
400
643
|
/**
|
|
401
644
|
* Writes `repo.work.failed` when one of a repo's jobs fails its last try, behind the events it
|
|
402
|
-
* held. It passes the events budget. A failed
|
|
403
|
-
* which would run the job it reports again
|
|
404
|
-
*
|
|
645
|
+
* held. It passes the events budget. A failed delivery's job saves every delivery's job but its
|
|
646
|
+
* own, which would run the job it reports again: the queue keeps any other failed job failed, so
|
|
647
|
+
* each stays as its own tries left it. It passes `tried`, which names the event its last try sent,
|
|
648
|
+
* for the `failed` row a discard skips by, in the same commit. It writes through the
|
|
405
649
|
* try's `context.store`, fenced by its claim, so a failure whose lease has ended writes nothing.
|
|
650
|
+
* A log with no delivery keeps no events, so it writes none.
|
|
406
651
|
*/
|
|
407
652
|
const workFailed = (log, now, tried) => {
|
|
408
653
|
const write = Effect.fnUntraced(function* (job, failure, store) {
|
|
409
|
-
if (scopeRepo(job.scope) === void 0) return;
|
|
410
|
-
const failed = tried === void 0 ? [] : [
|
|
411
|
-
...failedKey,
|
|
412
|
-
value: tried(job)
|
|
413
|
-
}];
|
|
654
|
+
if (scopeRepo(job.scope) === void 0 || !keepsEvents(log)) return;
|
|
655
|
+
const failed = tried === void 0 ? [] : [tried(job)];
|
|
414
656
|
for (let attempt = 0; attempt < failedTries; attempt += 1) {
|
|
415
657
|
const snapshot = yield* storeCall(() => store.read(job.scope, [selfKey, ...outboxReads]));
|
|
416
658
|
const record = yield* decodeRecord(snapshot.results[0]?.[0]);
|
|
@@ -437,7 +679,7 @@ const workFailed = (log, now, tried) => {
|
|
|
437
679
|
exempt: true
|
|
438
680
|
};
|
|
439
681
|
const appended = yield* appendEvents(log, outbox, [event], options);
|
|
440
|
-
const jobs =
|
|
682
|
+
const jobs = appended.jobs.filter((saved) => !sameJob(saved, job));
|
|
441
683
|
const change = {
|
|
442
684
|
id: newChangeId(),
|
|
443
685
|
expect: snapshot.version,
|
|
@@ -451,26 +693,29 @@ const workFailed = (log, now, tried) => {
|
|
|
451
693
|
}))).ok) return;
|
|
452
694
|
}
|
|
453
695
|
});
|
|
454
|
-
|
|
455
|
-
return handler;
|
|
696
|
+
return (_data, failure) => Effect.flatMap(Effect.all([CurrentJob.current, CurrentJob.store]), ([job, store]) => write(job, failure, store));
|
|
456
697
|
};
|
|
457
|
-
/** Whether `
|
|
458
|
-
const
|
|
698
|
+
/** Whether `a` and `b` are one job of a scope: its name and its key. */
|
|
699
|
+
const sameJob = (a, b) => a.name === b.name && a.key === b.key;
|
|
700
|
+
/** Whether `job` is a scope's job of a delivery, `git.deliver.<name>`. */
|
|
701
|
+
const isDeliverJob = (job) => deliveryOf(job.name) !== void 0 && job.key === "deliver";
|
|
459
702
|
/**
|
|
460
|
-
* A discard's event that has gone since it read the cursor: delivery passed it, by a retry, and
|
|
461
|
-
* trim deleted it, so there is nothing to skip. A trim deletes only
|
|
462
|
-
* that the cursor hasn't passed is `DATA_LOSS`.
|
|
703
|
+
* A discard's event that has gone since it read the cursor: `delivery` passed it, by a retry, and
|
|
704
|
+
* a trim deleted it, so there is nothing to skip. A trim deletes only events every delivery has
|
|
705
|
+
* passed, so one gone that the cursor hasn't passed is `DATA_LOSS`.
|
|
463
706
|
*/
|
|
464
|
-
const passed = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, seq) {
|
|
465
|
-
const snapshot = yield* storeCall(() => store.read(scope, [...outboxReads]));
|
|
466
|
-
const {
|
|
467
|
-
if (
|
|
707
|
+
const passed = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, delivery, seq) {
|
|
708
|
+
const snapshot = yield* storeCall(() => store.read(scope, [...outboxReads, cursorRead(delivery)]));
|
|
709
|
+
const { head } = yield* decodeOutbox(snapshot.results);
|
|
710
|
+
if ((yield* cursorOf(store, scope, head, snapshot.results[2])).seq < seq) return yield* fail("DATA_LOSS", `The event ${seq} has gone`);
|
|
468
711
|
});
|
|
469
712
|
/** A retry that found the job no longer failed: a discard sent at once, or a retry, ran first. */
|
|
470
713
|
const notFailed = (error) => error.code === "FAILED_PRECONDITION" && isInfraError(error.cause) && error.cause.reason === "not-failed" || error.code === "NOT_FOUND";
|
|
471
714
|
/**
|
|
472
|
-
* A discard of
|
|
473
|
-
*
|
|
715
|
+
* A discard of `target`, a delivery's failed job, of the active `deliveries`: a skip of its
|
|
716
|
+
* delivery's cursor past the event its last try sent, with the low-water mark when it was the
|
|
717
|
+
* slowest, then that job due again for the rest. Every other delivery's job, failed or not, and
|
|
718
|
+
* its cursor, stay as they are. The queue makes a failed job due only by its own `retry`, so the two are
|
|
474
719
|
* separate writes. The skip is the cursor row past the cursor, added only when the `failed` row
|
|
475
720
|
* `workFailed` wrote names the try the job lists, by its `claim`, and that event: a try can fail
|
|
476
721
|
* before it sends one, and a row from an older failure names an older claim, even one in the same
|
|
@@ -478,84 +723,139 @@ const notFailed = (error) => error.code === "FAILED_PRECONDITION" && isInfraErro
|
|
|
478
723
|
* discard sent again finds the cursor past that event, or the job no longer failed, so it skips
|
|
479
724
|
* once. `verification/Discards.tla` checks it.
|
|
480
725
|
*/
|
|
481
|
-
const skipFailed = /* @__PURE__ */ Effect.fnUntraced(function* (store, jobs, scope) {
|
|
482
|
-
const
|
|
726
|
+
const skipFailed = /* @__PURE__ */ Effect.fnUntraced(function* (store, jobs, scope, target, deliveries) {
|
|
727
|
+
const delivery = deliveryOf(target.name);
|
|
728
|
+
if (delivery === void 0 || !deliveries.includes(delivery)) return;
|
|
729
|
+
const request = {
|
|
730
|
+
state: "failed",
|
|
731
|
+
name: target.name
|
|
732
|
+
};
|
|
733
|
+
const failed = (yield* storeCall(() => jobs.list(scope, request))).items.find((item) => sameJob(item, target));
|
|
483
734
|
if (failed === void 0) return;
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
735
|
+
const failedRow = failedKeyOf(delivery);
|
|
736
|
+
const reads = [
|
|
737
|
+
...outboxReads,
|
|
738
|
+
{
|
|
739
|
+
collection: failedRow.collection,
|
|
740
|
+
id: failedRow.id
|
|
741
|
+
},
|
|
742
|
+
...deliveries.map(cursorRead)
|
|
743
|
+
];
|
|
488
744
|
const snapshot = yield* storeCall(() => store.read(scope, reads));
|
|
489
|
-
const { delivered } = yield* decodeOutbox(snapshot.results);
|
|
745
|
+
const { head, delivered } = yield* decodeOutbox(snapshot.results);
|
|
490
746
|
const [row] = snapshot.results[2] ?? [];
|
|
491
747
|
const tried = row === void 0 ? void 0 : yield* decodeRow(FailedTry, row, "The failed try");
|
|
492
|
-
const
|
|
748
|
+
const cursors = yield* decodeCursors(deliveries, snapshot.results.slice(3));
|
|
749
|
+
const cursor = cursors.get(delivery) ?? (yield* retainedStart(store, scope, head));
|
|
750
|
+
const seq = cursor.seq + 1;
|
|
493
751
|
if (tried?.seq === seq && tried.claim === failed.claim) {
|
|
494
752
|
const read = {
|
|
495
753
|
collection: outboxCollections.events,
|
|
496
754
|
id: eventId(seq)
|
|
497
755
|
};
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
if (event === void 0) yield* passed(store, scope, seq);
|
|
756
|
+
const [event] = (yield* storeCall(() => store.read(scope, [read]))).results[0] ?? [];
|
|
757
|
+
if (event === void 0) yield* passed(store, scope, delivery, seq);
|
|
501
758
|
else {
|
|
502
759
|
const value = {
|
|
503
760
|
seq,
|
|
504
|
-
bytes:
|
|
505
|
-
};
|
|
506
|
-
const cursor = {
|
|
507
|
-
collection: outboxCollections.delivered,
|
|
508
|
-
id: cursorId(seq),
|
|
509
|
-
value
|
|
761
|
+
bytes: cursor.bytes + rowBytes(event)
|
|
510
762
|
};
|
|
511
|
-
yield*
|
|
763
|
+
yield* moveCursor(store, scope, delivery, value, {
|
|
764
|
+
delivered,
|
|
765
|
+
cursors
|
|
766
|
+
});
|
|
512
767
|
}
|
|
513
768
|
}
|
|
514
769
|
const job = {
|
|
515
|
-
name:
|
|
516
|
-
key:
|
|
770
|
+
name: failed.name,
|
|
771
|
+
key: failed.key
|
|
517
772
|
};
|
|
518
773
|
yield* storeCall(() => jobs.retry(scope, job)).pipe(Effect.catchIf(notFailed, () => Effect.void));
|
|
519
774
|
});
|
|
520
|
-
/** The longest a
|
|
775
|
+
/** The longest a delivery's `timeout` may be: a Git job's longest try (Q188). */
|
|
521
776
|
const longestDelivery = 78e4;
|
|
522
777
|
/**
|
|
523
|
-
* Throws an `INVALID_ARGUMENT` `GitError` for
|
|
778
|
+
* Throws an `INVALID_ARGUMENT` `GitError` for a delivery's `timeout` past a Git job's longest try,
|
|
524
779
|
* as `createGitServer` checks its options before its runtime is built.
|
|
525
780
|
*/
|
|
526
781
|
const checkDeliveryTimeout = ({ timeout }) => {
|
|
527
782
|
if (timeout === void 0 || millis(timeout) <= longestDelivery) return;
|
|
528
|
-
const message = `
|
|
783
|
+
const message = `A delivery's timeout is at most '13 minutes', the longest a Git job may run, not '${String(timeout)}'`;
|
|
529
784
|
throw gitError("INVALID_ARGUMENT", message);
|
|
530
785
|
};
|
|
531
786
|
/**
|
|
532
|
-
*
|
|
533
|
-
*
|
|
787
|
+
* Throws an `INVALID_ARGUMENT` `GitError` unless there are at most `deliveryLimit` deliveries, each
|
|
788
|
+
* named, with no name twice, each job name within a job name's 256 bytes as UTF-8 and holding no
|
|
789
|
+
* U+0000 or lone surrogate, and each timeout within `checkDeliveryTimeout`'s. A store that writes a
|
|
790
|
+
* lone surrogate as U+FFFD would give two such names one cursor.
|
|
534
791
|
*/
|
|
535
|
-
const
|
|
536
|
-
const
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
792
|
+
const checkDeliveries = (deliveries) => {
|
|
793
|
+
const names = new Set(deliveries.map((delivery) => delivery.name));
|
|
794
|
+
if (deliveries.length > 16) {
|
|
795
|
+
const message = `A server runs at most 16 deliveries, not ${deliveries.length}`;
|
|
796
|
+
throw gitError("INVALID_ARGUMENT", message);
|
|
797
|
+
}
|
|
798
|
+
if (names.size < deliveries.length) throw gitError("INVALID_ARGUMENT", "Each delivery has a name of its own");
|
|
799
|
+
for (const delivery of deliveries) {
|
|
800
|
+
const name = deliverJobName(delivery.name);
|
|
801
|
+
if (delivery.name === "" || name.includes("\0") || !isWellFormed(name) || utf8(name).length > limits.nameBytes) {
|
|
802
|
+
const message = `A delivery's name is set, holds no U+0000 or lone surrogate, and keeps '${deliverJobPrefix}<name>' within ${limits.nameBytes} bytes as UTF-8`;
|
|
803
|
+
throw gitError("INVALID_ARGUMENT", message);
|
|
804
|
+
}
|
|
805
|
+
checkDeliveryTimeout(delivery);
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
/**
|
|
809
|
+
* The log over `parts`' store and clock, whose `fill` makes a job for each delivery,
|
|
810
|
+
* `git.deliver.<name>`, over its handlers: tried again as its `retry` says, or for three days at
|
|
811
|
+
* most an hour apart, within its own `timeout`, with its own cursor. Its last failure writes
|
|
812
|
+
* `repo.work.failed`, which waits behind it, and makes each other delivery's job due. The
|
|
813
|
+
* deliveries are checked before any job is made. It takes every type, since every server serves
|
|
814
|
+
* feeds and a feed shows each (#1966, #2124).
|
|
815
|
+
*/
|
|
816
|
+
const deliveryLog = (parts) => {
|
|
817
|
+
const names = [];
|
|
818
|
+
let definitions = [];
|
|
819
|
+
const log = {
|
|
820
|
+
deliveries: names,
|
|
821
|
+
deliverJobs: () => definitions.map((definition) => definition.job({
|
|
822
|
+
key: deliverJobKey,
|
|
823
|
+
data: {}
|
|
824
|
+
})),
|
|
825
|
+
fill: (deliveries) => {
|
|
826
|
+
if (names.length > 0) throw new Error("A server's deliveries are filled once");
|
|
827
|
+
checkDeliveries(deliveries);
|
|
828
|
+
names.push(...deliveries.map((delivery) => delivery.name));
|
|
829
|
+
definitions = deliveries.map((delivery) => deliveryJob(parts, log, delivery));
|
|
830
|
+
return definitions;
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
return log;
|
|
834
|
+
};
|
|
835
|
+
/** `delivery`'s job over `log`, `git.deliver.<name>`, as `deliveryLog`'s `fill` makes it. */
|
|
836
|
+
const deliveryJob = (parts, log, delivery) => {
|
|
540
837
|
const sending = /* @__PURE__ */ new Map();
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
retry:
|
|
545
|
-
handler: deliverHandler({
|
|
546
|
-
...parts,
|
|
547
|
-
handler: parts.delivery.handler,
|
|
548
|
-
wake: log.deliverJob
|
|
549
|
-
}, sending),
|
|
550
|
-
onFailure: workFailed(log, parts.now, (job) => failedTry(sending, job))
|
|
838
|
+
const { timeout } = delivery;
|
|
839
|
+
const policy = {
|
|
840
|
+
payload: DeliverData,
|
|
841
|
+
retry: delivery.retry ?? defaultDeliverRetry
|
|
551
842
|
};
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
843
|
+
const DeliverJob = Job.make(deliverJobName(delivery.name), timeout === void 0 ? policy : {
|
|
844
|
+
...policy,
|
|
845
|
+
timeout: millis(timeout)
|
|
846
|
+
});
|
|
847
|
+
const base = {
|
|
848
|
+
...parts,
|
|
849
|
+
delivery: delivery.name,
|
|
850
|
+
deliveries: log.deliveries,
|
|
851
|
+
wake: log.deliverJobs
|
|
559
852
|
};
|
|
853
|
+
const handler = deliverTry({
|
|
854
|
+
...base,
|
|
855
|
+
...delivery
|
|
856
|
+
}, sending);
|
|
857
|
+
const tried = (job) => failedTry(sending, delivery.name, job);
|
|
858
|
+
const onFailure = workFailed(log, parts.now, tried);
|
|
859
|
+
return gitJob(DeliverJob, handler, { onFailure });
|
|
560
860
|
};
|
|
561
|
-
export {
|
|
861
|
+
export { DeliverData, checkDeliveries, checkDeliveryTimeout, defaultDeliverRetry, deliverJobKey, deliverJobName, deliverTry, deliveryLog, drainCeiling, isDeliverJob, keptFor, notFailed, skipFailed, workFailed };
|