@ref0/git 0.12.0 → 0.20.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/private-refs.mjs +3 -3
- package/dist/auth/access-jwt.mjs +2 -2
- package/dist/auth/auth.d.mts +2 -2
- package/dist/auth/auth.mjs +3 -6
- package/dist/auth/authorize.mjs +4 -20
- package/dist/auth/fences.d.mts +1 -2
- package/dist/auth/fences.mjs +3 -3
- package/dist/auth/grants.mjs +4 -4
- package/dist/auth/helpers.mjs +3 -11
- package/dist/auth/host-function.mjs +18 -1
- package/dist/auth/host-services.mjs +11 -0
- package/dist/auth/identify.d.mts +1 -1
- package/dist/auth/identify.mjs +3 -3
- package/dist/auth/policy.d.mts +27 -7
- package/dist/auth/policy.mjs +8 -4
- package/dist/auth/token-cleanup.mjs +67 -0
- package/dist/auth/token-rows.mjs +1 -1
- package/dist/auth/token-text.mjs +9 -1
- package/dist/auth/tokens-base.d.mts +35 -0
- package/dist/auth/tokens-base.mjs +13 -0
- package/dist/auth/tokens-layer.d.mts +2 -28
- package/dist/auth/tokens-layer.mjs +6 -12
- package/dist/auth/tokens-public.d.mts +3 -3
- package/dist/auth/tokens.d.mts +7 -17
- package/dist/auth/tokens.mjs +9 -87
- package/dist/auth.d.mts +1 -4
- package/dist/auth.mjs +1 -3
- package/dist/client/answer.mjs +21 -42
- package/dist/client/client.d.mts +2 -4
- package/dist/client/git-http.mjs +35 -11
- package/dist/client/local.mjs +14 -13
- package/dist/client/push-upload.mjs +39 -12
- package/dist/client/remote.mjs +95 -31
- package/dist/client/run-remote-helper.d.mts +1 -0
- package/dist/client/run-remote-helper.mjs +58 -24
- package/dist/client/slice-push.d.mts +1 -1
- package/dist/client/transport.mjs +105 -46
- package/dist/contracts/access.d.mts +8 -8
- package/dist/contracts/actors.d.mts +2 -34
- package/dist/contracts/blobs.d.mts +57 -10
- package/dist/contracts/blobs.mjs +16 -2
- package/dist/contracts/call-allowance.d.mts +13 -0
- package/dist/contracts/call-allowance.mjs +44 -0
- package/dist/contracts/calls-spent.mjs +8 -3
- package/dist/contracts/client.d.mts +23 -19
- package/dist/contracts/commits.d.mts +34 -26
- package/dist/contracts/commits.mjs +9 -1
- package/dist/contracts/engine.d.mts +6 -1
- package/dist/contracts/engine.mjs +10 -1
- package/dist/contracts/files.d.mts +12 -12
- package/dist/contracts/forks.d.mts +27 -17
- package/dist/contracts/git-events.d.mts +29 -1
- package/dist/contracts/git-hooks.d.mts +1 -1
- package/dist/contracts/git.d.mts +39 -7
- package/dist/contracts/git.mjs +3 -2
- package/dist/contracts/grants.d.mts +24 -4
- package/dist/contracts/handlers.d.mts +1 -1
- package/dist/contracts/lfs.d.mts +28 -9
- package/dist/contracts/merges.d.mts +3 -2
- package/dist/contracts/objects.d.mts +103 -35
- package/dist/contracts/operations.d.mts +3 -0
- package/dist/contracts/operations.mjs +12 -2
- package/dist/contracts/push-uploads.d.mts +44 -5
- package/dist/contracts/push-uploads.mjs +7 -3
- package/dist/contracts/queue.d.mts +40 -12
- package/dist/contracts/queue.mjs +3 -4
- package/dist/contracts/refs.d.mts +50 -25
- package/dist/contracts/remote.d.mts +6 -7
- package/dist/contracts/remote.mjs +5 -4
- package/dist/contracts/repo-records.d.mts +1 -0
- package/dist/contracts/repos.d.mts +106 -127
- package/dist/contracts/repos.mjs +33 -4
- package/dist/contracts/result.d.mts +49 -25
- package/dist/contracts/result.mjs +52 -11
- package/dist/contracts/rules.d.mts +22 -22
- package/dist/contracts/server.d.mts +37 -111
- package/dist/contracts/services.d.mts +1 -1
- package/dist/contracts/signin.d.mts +1 -1
- package/dist/contracts/store.d.mts +6 -5
- package/dist/contracts/sync.d.mts +90 -26
- package/dist/contracts/sync.mjs +45 -11
- package/dist/contracts/tags.d.mts +10 -10
- package/dist/contracts/time.d.mts +3 -0
- package/dist/contracts/{promises.mjs → time.mjs} +1 -1
- package/dist/contracts/tokens.d.mts +15 -22
- package/dist/contracts/tokens.mjs +3 -3
- package/dist/contracts/topics.d.mts +1 -6
- package/dist/contracts/trees.d.mts +12 -12
- package/dist/contracts/work.d.mts +87 -12
- package/dist/contracts/work.mjs +8 -1
- package/dist/core/access.d.mts +1 -2
- package/dist/core/access.mjs +46 -13
- package/dist/core/ancestry.d.mts +10 -0
- package/dist/core/ancestry.mjs +6 -6
- package/dist/core/asked.mjs +43 -5
- package/dist/core/call-names.mjs +7 -1
- package/dist/core/call-services.mjs +13 -4
- package/dist/core/events/deliver.d.mts +1 -2
- package/dist/core/events/deliver.mjs +48 -33
- package/dist/core/events/retired.mjs +119 -0
- package/dist/core/forks.mjs +931 -435
- package/dist/core/hooks/groups.mjs +1 -1
- package/dist/core/imports.mjs +159 -15
- package/dist/core/index-job.mjs +128 -37
- package/dist/core/index-lost.d.mts +1 -2
- package/dist/core/index-lost.mjs +2 -2
- package/dist/core/job-view.mjs +8 -9
- package/dist/core/loose-tally.mjs +1 -1
- package/dist/core/mirror-rows.mjs +19 -4
- package/dist/core/objects/blobs.mjs +129 -3
- package/dist/core/objects/commits.mjs +16 -6
- package/dist/core/objects/lines.mjs +2 -2
- package/dist/core/objects/merges.mjs +4 -1
- package/dist/core/objects/objects-layer.d.mts +1 -1
- package/dist/core/objects/objects-layer.mjs +3 -3
- package/dist/core/objects/reading.mjs +24 -13
- package/dist/core/objects/tags.mjs +4 -1
- package/dist/core/objects/trees.mjs +2 -2
- package/dist/core/objects/writing.mjs +2 -2
- package/dist/core/own-writes.mjs +1 -1
- package/dist/core/parts.d.mts +10 -6
- package/dist/core/parts.mjs +3 -11
- package/dist/core/promise.mjs +9 -12
- package/dist/core/purge.mjs +316 -42
- package/dist/core/push-decide.mjs +3 -1
- package/dist/core/push-files.d.mts +12 -0
- package/dist/core/push-files.mjs +225 -0
- package/dist/core/push-repo.d.mts +8 -0
- package/dist/core/push-repo.mjs +56 -0
- package/dist/core/push.d.mts +17 -0
- package/dist/core/push.mjs +153 -70
- package/dist/core/receipts.mjs +34 -13
- package/dist/core/ref-index-job.mjs +4 -4
- package/dist/core/ref-view.mjs +61 -7
- package/dist/core/refs.mjs +18 -13
- package/dist/core/registered-rows.mjs +2 -2
- package/dist/core/repack.mjs +46 -28
- package/dist/core/repo-info.mjs +19 -12
- package/dist/core/repos.mjs +50 -22
- package/dist/core/rules/commit-changes.d.mts +0 -1
- package/dist/core/saved-caller-views.d.mts +7 -2
- package/dist/core/saved-caller-views.mjs +2 -2
- package/dist/core/saved-callers.d.mts +19 -2
- package/dist/core/seam.d.mts +16 -26
- package/dist/core/seam.mjs +7 -28
- package/dist/core/tokens.mjs +1 -1
- package/dist/core/view.d.mts +6 -0
- package/dist/core/view.mjs +51 -26
- package/dist/core/work.mjs +105 -35
- package/dist/effect.d.mts +5 -12
- package/dist/effect.mjs +3 -10
- package/dist/engine/failures.mjs +2 -1
- package/dist/engine/reads.mjs +17 -10
- package/dist/engine/walk.mjs +4 -4
- package/dist/event-streams/event-streams.d.mts +1 -1
- package/dist/event-streams/event-streams.mjs +1 -1
- package/dist/event-streams/stream.d.mts +3 -3
- package/dist/event-streams/stream.mjs +38 -15
- package/dist/extend.d.mts +4 -5
- package/dist/extend.mjs +3 -2
- package/dist/http/answers.mjs +12 -7
- package/dist/http/core-parts.mjs +129 -64
- package/dist/http/handler.mjs +36 -9
- package/dist/http/node.d.mts +14 -1
- package/dist/http/node.mjs +61 -31
- package/dist/http/parts.d.mts +2 -0
- package/dist/http/push-upload-job.mjs +507 -0
- package/dist/http/push-uploads.d.mts +1 -0
- package/dist/http/push-uploads.mjs +142 -69
- package/dist/http/upload-pack.mjs +10 -9
- package/dist/index.d.mts +27 -28
- package/dist/index.mjs +5 -8
- package/dist/lfs/answer.mjs +37 -0
- package/dist/lfs/base.d.mts +9 -3
- package/dist/lfs/base.mjs +27 -2
- package/dist/lfs/copy.d.mts +60 -0
- package/dist/lfs/copy.mjs +109 -0
- package/dist/lfs/layer.d.mts +15 -1
- package/dist/lfs/layer.mjs +28 -13
- package/dist/lfs/locks.mjs +2 -2
- package/dist/lfs/objects.d.mts +7 -0
- package/dist/lfs/objects.mjs +152 -55
- package/dist/lfs/pointers.mjs +2 -2
- package/dist/lfs/rows.d.mts +13 -0
- package/dist/lfs/rows.mjs +42 -8
- package/dist/lfs/service.d.mts +1 -7
- package/dist/lfs/service.mjs +1 -9
- package/dist/lfs/upkeep.mjs +48 -14
- package/dist/lfs/upload-most.mjs +5 -5
- package/dist/lfs/wire.mjs +6 -31
- package/dist/merges/merges.mjs +2 -2
- package/dist/node.d.mts +3 -3
- package/dist/protocol/bytes/buffers.mjs +13 -5
- package/dist/protocol/bytes/reader.mjs +6 -1
- package/dist/protocol/bytes/sha256-hasher.d.mts +15 -0
- package/dist/protocol/bytes/sha256.d.mts +32 -0
- package/dist/protocol/bytes/sha256.mjs +105 -49
- package/dist/protocol/bytes/streams.mjs +27 -1
- package/dist/protocol/diff/read.d.mts +4 -3
- package/dist/protocol/diff/read.mjs +8 -3
- package/dist/protocol/objects/lfs-pointer.d.mts +14 -2
- package/dist/protocol/objects/lfs-pointer.mjs +1 -3
- package/dist/protocol/objects/links-raw.mjs +24 -10
- package/dist/protocol/objects/tag.d.mts +1 -1
- package/dist/protocol/objects/tree.mjs +23 -6
- package/dist/protocol/packs/delta.d.mts +6 -3
- package/dist/protocol/packs/delta.mjs +96 -32
- package/dist/protocol/packs/idx.d.mts +2 -1
- package/dist/protocol/packs/idx.mjs +22 -3
- package/dist/protocol/packs/parts.d.mts +4 -1
- package/dist/protocol/packs/parts.mjs +10 -7
- package/dist/protocol/packs/reader.d.mts +5 -0
- package/dist/protocol/packs/reader.mjs +3 -2
- package/dist/protocol/packs/writer.mjs +26 -8
- package/dist/protocol/wire/advertisement.mjs +9 -4
- package/dist/protocol/wire/lines.d.mts +4 -2
- package/dist/protocol/wire/lines.mjs +11 -5
- package/dist/protocol/wire/push-uploads.mjs +13 -1
- package/dist/protocol/wire/v2.mjs +2 -2
- package/dist/protocol.d.mts +3 -1
- package/dist/protocol.mjs +3 -1
- package/dist/queue/advance.mjs +22 -25
- package/dist/queue/base.d.mts +55 -0
- package/dist/queue/base.mjs +44 -0
- package/dist/queue/calls.mjs +51 -54
- package/dist/queue/commit.mjs +1 -1
- package/dist/queue/host.d.mts +2 -22
- package/dist/queue/host.mjs +2 -13
- package/dist/queue/layer.d.mts +2 -1
- package/dist/queue/layer.mjs +11 -4
- package/dist/queue/limits.mjs +2 -0
- package/dist/queue/push-option.mjs +9 -24
- package/dist/queue/schedule.mjs +1 -1
- package/dist/queue/state.mjs +2 -10
- package/dist/queue/trim.mjs +6 -4
- package/dist/rest/blobs.mjs +29 -5
- package/dist/rest/caller.d.mts +4 -4231
- package/dist/rest/caller.mjs +5 -1
- package/dist/rest/client.d.mts +15 -5
- package/dist/rest/client.mjs +23 -2
- package/dist/rest/events.mjs +1 -2
- package/dist/rest/handler.mjs +4 -57
- package/dist/rest/handlers.mjs +68 -9
- package/dist/rest/layer.d.mts +2 -2
- package/dist/rest/layer.mjs +7 -13
- package/dist/rest/me.d.mts +3 -428
- package/dist/rest/paths.mjs +1 -0
- package/dist/rest/work.mjs +8 -0
- package/dist/server/check-fetch.mjs +3 -3
- package/dist/server/edge-node.d.mts +14 -15
- package/dist/server/edge-node.mjs +12 -12
- package/dist/server/edge.d.mts +21 -7
- package/dist/server/edge.mjs +32 -11
- package/dist/server/extension.mjs +1 -1
- package/dist/server/git-layer.d.mts +6 -11
- package/dist/server/git-layer.mjs +29 -23
- package/dist/server/git-namespace.d.mts +5 -4
- package/dist/server/git-namespace.mjs +3 -2
- package/dist/server/joined.d.mts +21 -40
- package/dist/server/joined.mjs +11 -62
- package/dist/server/lifecycle.mjs +65 -69
- package/dist/server/registry.mjs +28 -3
- package/dist/server/server.mjs +245 -465
- package/dist/signin/context.d.mts +1 -2
- package/dist/signin/layer.d.mts +1 -1
- package/dist/signin/layer.mjs +1 -1
- package/dist/storage/allotted.mjs +18 -3
- package/dist/storage/batch-upkeep.mjs +274 -0
- package/dist/{core/purge.d.mts → storage/batches.d.mts} +4 -4
- package/dist/storage/batches.mjs +344 -0
- package/dist/storage/budget.mjs +2 -2
- package/dist/storage/calls.d.mts +1 -2
- package/dist/storage/calls.mjs +144 -158
- package/dist/storage/chunks.d.mts +9 -0
- package/dist/storage/chunks.mjs +297 -0
- package/dist/storage/clean-up.mjs +85 -19
- package/dist/storage/counted-bucket.mjs +4 -4
- package/dist/storage/fetch.d.mts +1 -0
- package/dist/storage/fetch.mjs +298 -216
- package/dist/storage/file-limits.mjs +24 -0
- package/dist/storage/host-bucket.mjs +1 -2
- package/dist/storage/id-mix.mjs +19 -5
- package/dist/storage/index-bitmaps.mjs +9 -2
- package/dist/storage/index-build.d.mts +1 -1
- package/dist/storage/index-build.mjs +185 -84
- package/dist/storage/index-fetch.mjs +128 -74
- package/dist/storage/index-files.d.mts +3 -0
- package/dist/storage/index-files.mjs +10 -5
- package/dist/storage/index-graph.mjs +72 -22
- package/dist/storage/index-reach.mjs +33 -5
- package/dist/storage/index-remap.mjs +208 -65
- package/dist/storage/index-shallow.mjs +5 -3
- package/dist/storage/index-whole.mjs +127 -0
- package/dist/storage/largest-files.mjs +48 -0
- package/dist/storage/layout.mjs +23 -0
- package/dist/storage/lfs-pointers.mjs +10 -1
- package/dist/storage/loose.d.mts +7 -4
- package/dist/storage/loose.mjs +214 -67
- package/dist/storage/memory-budget.mjs +44 -8
- package/dist/storage/merge-plan.mjs +3 -2
- package/dist/storage/merge-row.mjs +7 -1
- package/dist/storage/merge-stream.mjs +164 -25
- package/dist/storage/merge-walk.mjs +8 -4
- package/dist/storage/merge-write.mjs +1 -1
- package/dist/storage/merge.d.mts +1 -1
- package/dist/storage/merge.mjs +1 -1
- package/dist/storage/object-rows.d.mts +1 -0
- package/dist/storage/object-rows.mjs +385 -65
- package/dist/storage/oid-table.mjs +171 -0
- package/dist/storage/pack-order.mjs +8 -4
- package/dist/storage/pack-ranges.d.mts +1 -2
- package/dist/storage/pack-ranges.mjs +4 -5
- package/dist/storage/pack-reads.d.mts +2 -1
- package/dist/storage/pack-reads.mjs +165 -49
- package/dist/storage/pack-receive.d.mts +1 -1
- package/dist/storage/pack-receive.mjs +85 -27
- package/dist/storage/packs.d.mts +1 -1
- package/dist/storage/packs.mjs +172 -86
- package/dist/storage/placed-reads.mjs +1 -1
- package/dist/storage/plan-columns.d.mts +4 -0
- package/dist/storage/plan-columns.mjs +238 -0
- package/dist/storage/prune-keep.mjs +299 -37
- package/dist/storage/prune-walk.mjs +240 -62
- package/dist/storage/prune.mjs +749 -213
- package/dist/storage/push-allotment.mjs +91 -12
- package/dist/storage/push-uploads.mjs +40 -16
- package/dist/storage/pushed-commits.mjs +4 -2
- package/dist/storage/quarantine.d.mts +1 -1
- package/dist/storage/quarantine.mjs +9 -9
- package/dist/storage/range-cache.mjs +125 -8
- package/dist/storage/ready.d.mts +1 -1
- package/dist/storage/ready.mjs +55 -25
- package/dist/storage/receive-bounds.mjs +51 -15
- package/dist/storage/receive-state.mjs +8 -0
- package/dist/storage/receive-steps.mjs +71 -18
- package/dist/storage/repack-backlog.mjs +6 -3
- package/dist/storage/repack.d.mts +2 -2
- package/dist/storage/repack.mjs +1 -8
- package/dist/storage/rows.d.mts +1 -1
- package/dist/storage/rows.mjs +13 -2
- package/dist/storage/runs.mjs +195 -43
- package/dist/storage/send-list.d.mts +1 -0
- package/dist/storage/send-list.mjs +54 -10
- package/dist/storage/shallow.d.mts +1 -0
- package/dist/storage/shallow.mjs +26 -4
- package/dist/storage/single-flight.mjs +13 -7
- package/dist/storage/stream-whole.mjs +132 -28
- package/dist/storage/unpack.mjs +371 -79
- package/dist/storage/visible.mjs +31 -3
- package/dist/storage/walk.mjs +194 -39
- package/dist/storage/wants.mjs +5 -5
- package/dist/store/bodies.mjs +38 -0
- package/dist/store/call-count.d.mts +8 -12
- package/dist/store/call-count.mjs +34 -46
- package/dist/store/catalogue.d.mts +2 -2
- package/dist/store/catalogue.mjs +146 -35
- package/dist/store/crossing.mjs +1 -3
- package/dist/store/cursor-seal-namespace.d.mts +2 -0
- package/dist/store/cursor-seal-public.d.mts +5 -0
- package/dist/store/cursor-seal-public.mjs +5 -0
- package/dist/store/cursor-seal.d.mts +16 -3
- package/dist/store/cursor-seal.mjs +40 -18
- package/dist/store/door.mjs +183 -0
- package/dist/store/errors.d.mts +3 -4
- package/dist/store/errors.mjs +24 -34
- package/dist/store/git-store.mjs +25 -7
- package/dist/store/job-try.mjs +9 -32
- package/dist/store/list-job.mjs +44 -8
- package/dist/store/records.d.mts +5 -0
- package/dist/store/records.mjs +12 -6
- package/dist/store/repo-record.d.mts +10 -9
- package/dist/store/repo-record.mjs +123 -28
- package/dist/store/reservations.mjs +1 -1
- package/dist/store/scopes.mjs +21 -2
- package/dist/store/settle.mjs +4 -4
- package/dist/sync/bound.d.mts +2 -0
- package/dist/sync/bound.mjs +11 -2
- package/dist/sync/github.d.mts +6 -1
- package/dist/sync/github.mjs +56 -44
- package/dist/sync/http.mjs +36 -1
- package/dist/sync/import.mjs +32 -18
- package/dist/sync/layer.mjs +6 -2
- package/dist/sync/lfs-batch.mjs +118 -0
- package/dist/sync/lfs-copy.mjs +262 -0
- package/dist/sync/mirror.mjs +227 -151
- package/dist/sync/said.mjs +16 -37
- package/dist/sync/smart-http.mjs +4 -2
- package/dist/sync/step.mjs +58 -30
- package/dist/sync/tries.mjs +52 -21
- package/dist/sync.d.mts +2 -2
- package/dist/topics/advance.mjs +10 -11
- package/dist/topics/base.d.mts +15 -0
- package/dist/topics/base.mjs +8 -0
- package/dist/topics/host.mjs +2 -20
- package/dist/topics/layer.d.mts +4 -9
- package/dist/topics/layer.mjs +3 -4
- package/dist/topics/members.mjs +4 -4
- package/dist/topics/public.d.mts +2 -1
- package/dist/topics/topic.mjs +2 -2
- package/package.json +5 -9
- package/dist/auth/bridge.mjs +0 -30
- package/dist/auth/helpers.d.mts +0 -17
- package/dist/contracts/promises.d.mts +0 -39
- package/dist/core/call-names.d.mts +0 -3
- package/dist/core/clock.mjs +0 -18
- package/dist/core/registered-rows.d.mts +0 -5
- package/dist/core/repack.d.mts +0 -11
- package/dist/http/handler.d.mts +0 -2
- package/dist/lfs/calls.mjs +0 -26
- package/dist/rest/api.d.mts +0 -23
- package/dist/rest/blobs.d.mts +0 -825
- package/dist/rest/commits.d.mts +0 -3510
- package/dist/rest/errors.d.mts +0 -2104
- package/dist/rest/events.d.mts +0 -423
- package/dist/rest/files.d.mts +0 -1330
- package/dist/rest/forks.d.mts +0 -2136
- package/dist/rest/handler.d.mts +0 -21
- package/dist/rest/handlers.d.mts +0 -8
- package/dist/rest/merges.d.mts +0 -473
- package/dist/rest/queue.d.mts +0 -5861
- package/dist/rest/refs.d.mts +0 -2959
- package/dist/rest/repos.d.mts +0 -2539
- package/dist/rest/tags.d.mts +0 -1304
- package/dist/rest/tokens.d.mts +0 -2590
- package/dist/rest/topics.d.mts +0 -2204
- package/dist/rest/trees.d.mts +0 -1693
- package/dist/rest/work.d.mts +0 -1248
- package/dist/rest.d.mts +0 -2
- package/dist/rest.mjs +0 -1
- package/dist/server/lifecycle.d.mts +0 -2
- package/dist/server/registry.d.mts +0 -16
- package/dist/server/server.d.mts +0 -36
- package/dist/storage/repack-job.d.mts +0 -3
- package/dist/store/promises.d.mts +0 -11
- package/dist/store/promises.mjs +0 -327
- package/dist/topics/host.d.mts +0 -7
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
import { Sha1 } from "../protocol/bytes/sha1.mjs";
|
|
1
2
|
import { noRepoRoots } from "../protocol/objects/commit.mjs";
|
|
2
3
|
import { checkChurn, decodeRecord, entryOf, project } from "./catalogue.mjs";
|
|
3
4
|
import { afterCommit } from "./call-count.mjs";
|
|
4
5
|
import { fail } from "../contracts/result.mjs";
|
|
5
|
-
import { afterWrites, decodeRow, storeCall } from "./errors.mjs";
|
|
6
|
+
import { afterWrites, decodeRow, storeCall, storeCommit } from "./errors.mjs";
|
|
6
7
|
import { listJobRow } from "./list-job.mjs";
|
|
7
|
-
import { LooseTally, RepoRootsRow, StatsTime } from "./records.mjs";
|
|
8
|
-
import { looseKey, maintainedKey, newChangeId, pushedKey, repoScope, selfKey } from "./scopes.mjs";
|
|
9
|
-
import * as Clock
|
|
8
|
+
import { LooseTally, RepoRootsRow, StatsTime, repoRootsMost } from "./records.mjs";
|
|
9
|
+
import { looseKey, maintainedKey, newChangeId, pushedKey, reachedKey, repoRootsKey, repoScope, selfKey } from "./scopes.mjs";
|
|
10
|
+
import * as Clock from "effect/Clock";
|
|
10
11
|
import * as Effect from "effect/Effect";
|
|
11
12
|
import * as Schema from "effect/Schema";
|
|
12
13
|
import { jobLeaseMargin } from "@ref0/infra";
|
|
13
14
|
import * as Context from "effect/Context";
|
|
15
|
+
import * as Hex from "effect/encoding/Hex";
|
|
14
16
|
// src/store/repo-record.ts
|
|
15
17
|
/** A repo's record and its scope's rows, read at one version: `results[0]` is `self`. */
|
|
16
18
|
const readRecord = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, reads = [], counts = []) {
|
|
17
19
|
const scope = repoScope(internalId);
|
|
18
|
-
const snapshot = yield* storeCall(
|
|
20
|
+
const snapshot = yield* storeCall(store.read(scope, [selfKey, ...reads], [...counts]));
|
|
19
21
|
return {
|
|
20
22
|
record: yield* decodeRecord(snapshot.results[0]?.[0]),
|
|
21
23
|
snapshot
|
|
@@ -27,27 +29,109 @@ const rootsOf = (rows) => {
|
|
|
27
29
|
if (row === void 0) return Effect.succeed(noRepoRoots);
|
|
28
30
|
return Effect.map(decodeRow(RepoRootsRow, row, "The repo's roots"), ({ roots }) => new Set(roots));
|
|
29
31
|
};
|
|
32
|
+
/** `held` once `moves` lands, as `rootsMoved` writes it: `shallow` added, then `unshallow` taken away. */
|
|
33
|
+
const movedRoots = (held, moves) => {
|
|
34
|
+
const after = new Set(held);
|
|
35
|
+
for (const oid of moves.shallow) after.add(oid);
|
|
36
|
+
for (const oid of moves.unshallow) after.delete(oid);
|
|
37
|
+
return after;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The write of a repo's roots once `moves` lands on `held`, the roots its commit reads: those of
|
|
41
|
+
* `shallow` added, and those of `unshallow` taken away, each once, in order. `undefined` when they
|
|
42
|
+
* don't change. It is the roots' one writer (#2202, and #2198's import), and it does three things
|
|
43
|
+
* on a change: its row, or the row's delete once none is left; the reached mark's delete, so a
|
|
44
|
+
* whole clone never streams past a root that moved; and `indexed`, the repo's `git.index` rows,
|
|
45
|
+
* which queue a build over the new roots: an index keeps `rootsDigest` of the roots it's over, so
|
|
46
|
+
* one over others answers no read and is built again whole (#2462). Prune keys its saved work on
|
|
47
|
+
* them too: its walks keep `rootsKeyOf` of the roots they walked under, and its classes' reads
|
|
48
|
+
* digest takes them, so a pass whose roots moved walks and reads again under the new ones (#2485).
|
|
49
|
+
* Past `repoRootsMost` it's refused, so a fetch lands nothing. An answer that moves the roots
|
|
50
|
+
* lands only on the roots it was made against, `sent`: once another fetch moved them, its lines
|
|
51
|
+
* no longer say where the history stops, and it's refused `changed-while-checked`, landing
|
|
52
|
+
* nothing, for the fetch to ask again.
|
|
53
|
+
*/
|
|
54
|
+
const rootsMoved = (held, moves, indexed) => {
|
|
55
|
+
const moving = moves.shallow.length > 0 || moves.unshallow.length > 0;
|
|
56
|
+
const asked = new Set(moves.sent);
|
|
57
|
+
const moved = asked.size !== held.size || [...asked].some((oid) => !held.has(oid));
|
|
58
|
+
if (moving && moved) return fail("FAILED_PRECONDITION", "The repo's roots moved since this fetch sent them", {
|
|
59
|
+
hint: "Fetch again",
|
|
60
|
+
context: { reason: "changed-while-checked" }
|
|
61
|
+
});
|
|
62
|
+
const after = movedRoots(held, moves);
|
|
63
|
+
if (after.size === held.size && [...after].every((oid) => held.has(oid))) return Effect.succeed(void 0);
|
|
64
|
+
if (after.size > 1e4) return fail("RESOURCE_EXHAUSTED", `A repo holds at most ${repoRootsMost} shallow commits`, {
|
|
65
|
+
hint: "Fetch with a smaller depth, or from fewer branches",
|
|
66
|
+
context: {
|
|
67
|
+
reason: "too-large",
|
|
68
|
+
most: repoRootsMost
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
const roots = [...after].sort();
|
|
72
|
+
const value = { roots };
|
|
73
|
+
const put = roots.length === 0 ? [] : [{
|
|
74
|
+
...repoRootsKey,
|
|
75
|
+
value
|
|
76
|
+
}];
|
|
77
|
+
const gone = roots.length === 0 ? [repoRootsKey] : [];
|
|
78
|
+
return Effect.succeed({
|
|
79
|
+
roots,
|
|
80
|
+
put,
|
|
81
|
+
delete: [...gone, reachedKey],
|
|
82
|
+
jobs: indexed
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* The repo's roots as one digest: their IDs sorted, each once, hashed. What was built over the
|
|
87
|
+
* roots, such as the ready shallow pack, keeps it, so a change of roots is seen as one.
|
|
88
|
+
*/
|
|
89
|
+
const rootsDigest = (roots) => {
|
|
90
|
+
const sha = new Sha1();
|
|
91
|
+
sha.update(new TextEncoder().encode([...new Set(roots)].sort().join("\n")));
|
|
92
|
+
return Hex.encode(sha.digest());
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* How long a repo's delete may commit after the time it stamps, from which its purge's guard
|
|
96
|
+
* counts: half of `jobLeaseMargin`. The delete's commit sends it past that time as its `by`, and
|
|
97
|
+
* the margin's other half covers how far the store's clock may run from Git's, which a held write
|
|
98
|
+
* meets twice, at the delete's commit and at its own: a quarter of the margin each way (#2331).
|
|
99
|
+
*/
|
|
100
|
+
const deleteCommitWithin = jobLeaseMargin / 2;
|
|
30
101
|
/**
|
|
31
|
-
* When a write to a repo's scope must
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
102
|
+
* When a write to a repo's scope must land by, after a read at `heldAt` found the repo's record
|
|
103
|
+
* live: `heldAt` plus `fetchLimits.milliseconds`, less `jobLeaseMargin`. The repo was live at that
|
|
104
|
+
* read, so its delete committed later, and its purge drops its scopes no sooner than `fetchLimits`
|
|
105
|
+
* past the delete's stamp, the record's `changedAt`, which the delete commits within
|
|
106
|
+
* `deleteCommitWithin` of (#1911). The write sends it as its `by`, which the store checks on its
|
|
107
|
+
* own clock as the write lands, so one that stalls in the store lands nothing past it, however
|
|
108
|
+
* long the stall (#2331). The margin covers the delete's commit and the store's clock, as
|
|
109
|
+
* `deleteCommitWithin` splits it, and `HeldWrite.tla` checks that no held write lands after the drop.
|
|
37
110
|
*/
|
|
38
111
|
const heldUntil = (heldAt, fetchLimits) => heldAt + fetchLimits.milliseconds - jobLeaseMargin;
|
|
39
|
-
/** Whether a write may still
|
|
40
|
-
const inTime = (by) => Effect.map(Clock
|
|
112
|
+
/** Whether a write may still send its store call, by `heldUntil`'s `by`, at the clock's now. */
|
|
113
|
+
const inTime = (by) => Effect.map(Clock.currentTimeMillis, (now) => now < by);
|
|
41
114
|
/**
|
|
42
|
-
* When the writes in scope must
|
|
115
|
+
* When the writes in scope must land by, as `heldUntil` answered for the caller's own read of the
|
|
43
116
|
* repo's record: a push sets it around its receive, so the pack's quarantine row, an add at no
|
|
44
117
|
* version, is refused once the push waited past it, at its authorize or its memory's admission,
|
|
45
|
-
* as long as the repo's purge may take (#1911). `undefined` outside one,
|
|
46
|
-
* own packs, which the purge waits for.
|
|
118
|
+
* or in the store, as long as the repo's purge may take (#1911, #2331). `undefined` outside one,
|
|
119
|
+
* as for `git.repack`'s own packs, which the purge waits for.
|
|
47
120
|
*/
|
|
48
121
|
const HeldBy = Context.Reference("@ref0/git/HeldBy", { defaultValue: () => void 0 });
|
|
49
|
-
/**
|
|
50
|
-
|
|
122
|
+
/**
|
|
123
|
+
* `addition` with the sooner of `HeldBy` and its own `by` as its `by`, the value it sends, so the
|
|
124
|
+
* store refuses it as it lands past either: fails `UNAVAILABLE` already once the clock is at or
|
|
125
|
+
* past it, so a write that waited reads again. A staged batch's add carries its `removeAt`, which
|
|
126
|
+
* its sweep's end counts on.
|
|
127
|
+
*/
|
|
128
|
+
const heldAddition = (what, addition) => Effect.flatMap(HeldBy, (held) => {
|
|
129
|
+
const by = held === void 0 ? addition.by : Math.min(held, addition.by ?? Number.POSITIVE_INFINITY);
|
|
130
|
+
return by === void 0 ? Effect.succeed(addition) : Effect.flatMap(inTime(by), (on) => on ? Effect.succeed({
|
|
131
|
+
...addition,
|
|
132
|
+
by
|
|
133
|
+
}) : fail("UNAVAILABLE", `${what} came late: read the repo again`, { hint: "Push again" }));
|
|
134
|
+
});
|
|
51
135
|
/**
|
|
52
136
|
* A write to a repo's scope refused because the repo is gone: no record, or one deleted, so its
|
|
53
137
|
* purge may drop the scope, or has, and the write would make it again (#1911).
|
|
@@ -55,26 +139,33 @@ const heldInTime = (what) => Effect.flatMap(HeldBy, (by) => by === void 0 ? Effe
|
|
|
55
139
|
var RepoGone = class extends Schema.TaggedError()("RepoGone", { repo: Schema.String }) {};
|
|
56
140
|
/** `store` as `heldAdd` calls it, each call a `storeCall`. */
|
|
57
141
|
const heldStore = (store) => ({
|
|
58
|
-
read: (scope, reads) => storeCall(
|
|
59
|
-
add: (scope, addition) => storeCall(
|
|
142
|
+
read: (scope, reads) => storeCall(store.read(scope, reads)),
|
|
143
|
+
add: (scope, addition) => storeCall(store.add(scope, addition))
|
|
60
144
|
});
|
|
61
145
|
/**
|
|
62
146
|
* `addition` to `repo`'s scope, an add at no version, only while the repo is live: it reads the
|
|
63
147
|
* record first and fails `RepoGone` when there's none or it's deleted, so a late write, a wake or
|
|
64
148
|
* a job after the delete never makes a purged scope again, nor on Turso its database. One whose
|
|
65
|
-
* read stalled past `heldUntil` is `UNAVAILABLE`, for a try that reads again
|
|
149
|
+
* read stalled past `heldUntil` is `UNAVAILABLE`, for a try that reads again, and so is one whose
|
|
150
|
+
* add the store found past it as it landed, `heldUntil` being the add's `by`. A wake, a job, an
|
|
66
151
|
* upload or a sync's cover made apart from the repo's own read goes through here, and a push's
|
|
67
|
-
* quarantine is held to its first read by `HeldBy`. The adds that don't are a fork create's
|
|
68
|
-
*
|
|
152
|
+
* quarantine is held to its first read by `HeldBy`. The adds that don't are a fork create's
|
|
153
|
+
* staging, after its opener commits its record aside, by the `removeAt` its purge waits out, and a
|
|
154
|
+
* try's rows in its own scope, which its claim fences. A create's cover rows are commits at its
|
|
155
|
+
* version.
|
|
69
156
|
*/
|
|
70
157
|
const heldAdd = /* @__PURE__ */ Effect.fnUntraced(function* (store, repo, fetchLimits, addition) {
|
|
71
158
|
const scope = repoScope(repo);
|
|
72
|
-
const heldAt = yield* Clock
|
|
159
|
+
const heldAt = yield* Clock.currentTimeMillis;
|
|
73
160
|
const snapshot = yield* store.read(scope, [selfKey]);
|
|
74
161
|
const record = yield* decodeRecord(snapshot.results[0]?.[0]);
|
|
75
162
|
if (record === void 0 || record.deleted === true) return yield* new RepoGone({ repo });
|
|
76
|
-
|
|
77
|
-
yield*
|
|
163
|
+
const by = heldUntil(heldAt, fetchLimits);
|
|
164
|
+
if (!(yield* inTime(by))) return yield* fail("UNAVAILABLE", `The add to repo ${repo} came late: read it again`);
|
|
165
|
+
yield* store.add(scope, {
|
|
166
|
+
...addition,
|
|
167
|
+
by
|
|
168
|
+
});
|
|
78
169
|
});
|
|
79
170
|
/**
|
|
80
171
|
* The first of a repo write's two commits: its record, in its own scope, with `git.list` saved
|
|
@@ -91,7 +182,11 @@ const commitRecord = (store, internalId, write) => {
|
|
|
91
182
|
delete: [...write.delete ?? []],
|
|
92
183
|
jobs: [listJobRow(), ...write.jobs ?? []]
|
|
93
184
|
};
|
|
94
|
-
|
|
185
|
+
const sent = write.by === void 0 ? change : {
|
|
186
|
+
...change,
|
|
187
|
+
by: write.by
|
|
188
|
+
};
|
|
189
|
+
return storeCommit(store.commit(repoScope(internalId), sent));
|
|
95
190
|
};
|
|
96
191
|
/**
|
|
97
192
|
* A repo write's two commits: its record, then its projection into `git/repos`. Answers
|
|
@@ -177,4 +272,4 @@ const repoStats = (record, refs, packs, times, readyBytes) => {
|
|
|
177
272
|
if (times.maintained !== void 0) stats.maintainedAt = times.maintained;
|
|
178
273
|
return stats;
|
|
179
274
|
};
|
|
180
|
-
export { HeldBy, RepoGone, commitRecord, decodeStats, heldAdd,
|
|
275
|
+
export { HeldBy, RepoGone, commitRecord, decodeStats, deleteCommitWithin, heldAdd, heldAddition, heldStore, heldUntil, inTime, looseRows, movedRoots, readRecord, repoStats, rootsDigest, rootsMoved, rootsOf, seenTimes, timeRow, writeRecord };
|
|
@@ -76,7 +76,7 @@ const reservationOf = (rows) => {
|
|
|
76
76
|
* nothing.
|
|
77
77
|
*/
|
|
78
78
|
const liveState = /* @__PURE__ */ Effect.fnUntraced(function* (store, reservation) {
|
|
79
|
-
const [row] = (yield* storeCall(
|
|
79
|
+
const [row] = (yield* storeCall(store.read(topicScope(reservation.topic), [topicKey]))).results[0] ?? [];
|
|
80
80
|
if (row === void 0) return void 0;
|
|
81
81
|
const life = yield* decodeRow(TopicLife, row, `Topic ${reservation.topic}`);
|
|
82
82
|
return ended.has(life.state) ? void 0 : life.state;
|
package/dist/store/scopes.mjs
CHANGED
|
@@ -43,6 +43,17 @@ const collections = {
|
|
|
43
43
|
publicCreated: "public-created",
|
|
44
44
|
/** In `git/repos`: the server's own keys, by use: `cursor`, which seals every list's cursor. */
|
|
45
45
|
keys: "keys",
|
|
46
|
+
/**
|
|
47
|
+
* In `git/repos`: a row for each delivery the host has retired, by its name, which each start
|
|
48
|
+
* writes from `events.retired`, so a deleted repo's purge may end that delivery's job.
|
|
49
|
+
*/
|
|
50
|
+
retired: "retired-deliveries",
|
|
51
|
+
/**
|
|
52
|
+
* In `git/repos`: `head`, the stamp of the start that last wrote the `retired` rows, `gen`, how
|
|
53
|
+
* many starts' writes have landed, and `start`, its ID, so a start's write behind a later
|
|
54
|
+
* start's landing is refused.
|
|
55
|
+
*/
|
|
56
|
+
retiredStamp: "retired-stamp",
|
|
46
57
|
/** In a repo's scope: its own record, `self`, and its roots, `roots`. */
|
|
47
58
|
repo: "repo",
|
|
48
59
|
/** In a repo's scope: each ref's `RefRow`, by its full name. */
|
|
@@ -80,6 +91,13 @@ const collections = {
|
|
|
80
91
|
* pushed or upkeep ends it.
|
|
81
92
|
*/
|
|
82
93
|
pushUploads: "push-uploads",
|
|
94
|
+
/**
|
|
95
|
+
* In a repo's scope: each receiving push upload's steps, by its handle: who completed it, as
|
|
96
|
+
* `SavedCaller` keeps them, and once its first try staged it, its pack's ID.
|
|
97
|
+
*/
|
|
98
|
+
pushUploadSteps: "push-upload-steps",
|
|
99
|
+
/** In a repo's scope: each ended push upload's answer, by its handle, for its report. */
|
|
100
|
+
pushUploadAnswers: "push-upload-answers",
|
|
83
101
|
/** In a topic's scope: its own row, `self`, with its state. */
|
|
84
102
|
topic: "topic",
|
|
85
103
|
/** In `git/topics`: each key's topic, claimed by the first `topics.add` that names the key. */
|
|
@@ -123,8 +141,9 @@ const selfKey = {
|
|
|
123
141
|
id: "self"
|
|
124
142
|
};
|
|
125
143
|
/**
|
|
126
|
-
* A repo's roots, its `RepoRootsRow`, read with every open whose reads walk parents. Only
|
|
127
|
-
*
|
|
144
|
+
* A repo's roots, its `RepoRootsRow`, read with every open whose reads walk parents. Only
|
|
145
|
+
* `rootsMoved` writes it, for a client's fetch or an import, in the commit that lands what the
|
|
146
|
+
* answer sent; a repo with no row has none.
|
|
128
147
|
*/
|
|
129
148
|
const repoRootsKey = {
|
|
130
149
|
collection: collections.repo,
|
package/dist/store/settle.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { storeCall } from "./errors.mjs";
|
|
1
|
+
import { storeCall, storeCommit } from "./errors.mjs";
|
|
2
2
|
import { entryOf, project } from "./catalogue.mjs";
|
|
3
3
|
import { dropUnconfirmed, headKey } from "./outbox.mjs";
|
|
4
4
|
import { takenBack } from "./records.mjs";
|
|
@@ -30,11 +30,11 @@ const settleName = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, re
|
|
|
30
30
|
...headKey,
|
|
31
31
|
value: confirmed
|
|
32
32
|
}];
|
|
33
|
-
yield* storeCall(
|
|
33
|
+
yield* storeCall(store.commit(scope, {
|
|
34
34
|
id: newChangeId(),
|
|
35
35
|
expect: version,
|
|
36
36
|
put
|
|
37
|
-
}));
|
|
37
|
+
}), { resend: true });
|
|
38
38
|
return true;
|
|
39
39
|
}
|
|
40
40
|
if (back !== void 0) {
|
|
@@ -55,7 +55,7 @@ const settleName = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, re
|
|
|
55
55
|
expect: version,
|
|
56
56
|
...dropUnconfirmed(head)
|
|
57
57
|
};
|
|
58
|
-
yield*
|
|
58
|
+
yield* storeCommit(store.commit(scope, change));
|
|
59
59
|
return true;
|
|
60
60
|
});
|
|
61
61
|
/** Whether a name's entry is still this repo's own, and live: the name a lost rename left. */
|
package/dist/sync/bound.d.mts
CHANGED
|
@@ -2,6 +2,8 @@ import "../contracts/authorize.mjs";
|
|
|
2
2
|
import "../contracts/actors.mjs";
|
|
3
3
|
import "../contracts/sync.mjs";
|
|
4
4
|
import "../core/parts.mjs";
|
|
5
|
+
import "../lfs/copy.mjs";
|
|
6
|
+
import "effect/Effect";
|
|
5
7
|
import "effect/http/HttpClient";
|
|
6
8
|
import { Job } from "@ref0/infra";
|
|
7
9
|
import "effect/Context";
|
package/dist/sync/bound.mjs
CHANGED
|
@@ -29,13 +29,22 @@ const importLimits = {
|
|
|
29
29
|
rootsMost
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
|
+
* The most bytes of Git LFS objects one try of an import copies: the copy's step takes a batch's
|
|
33
|
+
* objects until the next would pass it, and an object past it alone, so a try's downloads end
|
|
34
|
+
* well within `importTryTimeout`, and one object, at most LFS's `largestObject`, always fits.
|
|
35
|
+
*/
|
|
36
|
+
const lfsCopyBytes = 2 * 1024 ** 3;
|
|
37
|
+
/**
|
|
32
38
|
* The most mirrors a repo holds, and the most bytes one mirror's row takes, the row whole as UTF-8
|
|
33
39
|
* JSON, measured as its largest state, paused `diverged`, so a pause never takes it past.
|
|
34
40
|
* `mirrors` reads every row in one store call, beside the repo's record, at most 1 MiB, so 1,000
|
|
35
41
|
* rows of 4 KiB, 4 MiB, keep its read and its answer within one answer's 16 MiB `answerBytes`. The
|
|
36
42
|
* longest ref, 768 bytes of `"`, takes 1,536 escaped, and its saver's actor ID, which `authorize`
|
|
37
43
|
* holds to `maxActorIdLength`, 256 bytes, takes 512 so, which leaves its destination about 1,880
|
|
38
|
-
* bytes.
|
|
44
|
+
* bytes. `mirrors` bounds a destination's job too, one a destination: a push saves at most
|
|
45
|
+
* that many, and each try reads every row in one call, asks each distinct saver among them again
|
|
46
|
+
* once, makes one `provider.remote` call, reads the advertisement once, and twice when an update is
|
|
47
|
+
* refused, and sends one push of at most that many refs.
|
|
39
48
|
*/
|
|
40
49
|
const mirrorLimits = {
|
|
41
50
|
mirrors: 1e3,
|
|
@@ -48,4 +57,4 @@ const mirrorLimits = {
|
|
|
48
57
|
const asSync = decidingWith(hostAuthorize);
|
|
49
58
|
/** The build's internal binding, including the definitions test worlds hand to their queue. */
|
|
50
59
|
var SyncState = class extends (/* @__PURE__ */ Context.Service()("@ref0/git/SyncState")) {};
|
|
51
|
-
export { SyncState, asSync, importLimits, mirrorLimits };
|
|
60
|
+
export { SyncState, asSync, importLimits, lfsCopyBytes, mirrorLimits };
|
package/dist/sync/github.d.mts
CHANGED
|
@@ -7,5 +7,10 @@ import * as HttpClient from "effect/http/HttpClient";
|
|
|
7
7
|
* refused before more of it is read.
|
|
8
8
|
*/
|
|
9
9
|
export declare const webhookBodyBytes: number;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* A GitHub App provider over the host's HTTP client, captured at construction: each call it makes
|
|
12
|
+
* runs in the fiber that yields it, a try's, so the token's mint and each read sent again while
|
|
13
|
+
* GitHub's Git doesn't know the token are charged to the try's budget, and the first send of a
|
|
14
|
+
* request is the one `httpOf` charges, as it charges every transport's.
|
|
15
|
+
*/
|
|
11
16
|
export declare const github: (options: SyncGitHubOptions) => Effect.Effect<SyncProvider, GitError, HttpClient.HttpClient>;
|
package/dist/sync/github.mjs
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CallBudget } from "../store/call-count.mjs";
|
|
2
2
|
import { responseToWeb } from "./http.mjs";
|
|
3
|
-
import { fail, gitError } from "../contracts/result.mjs";
|
|
3
|
+
import { fail, gitError, gitErrorFrom } from "../contracts/result.mjs";
|
|
4
4
|
import { sameHash } from "../auth/token-text.mjs";
|
|
5
5
|
import { ProviderRefused, saidOf } from "./said.mjs";
|
|
6
6
|
import { hmacSha256 } from "../protocol/bytes/hmac-sha256.mjs";
|
|
7
|
-
import * as Clock
|
|
7
|
+
import * as Clock from "effect/Clock";
|
|
8
8
|
import * as Effect from "effect/Effect";
|
|
9
9
|
import * as HttpClient from "effect/http/HttpClient";
|
|
10
10
|
import * as Option from "effect/Option";
|
|
11
11
|
import * as Schema from "effect/Schema";
|
|
12
12
|
import * as Result from "effect/Result";
|
|
13
|
-
import * as Context from "effect/Context";
|
|
14
13
|
import * as Hex from "effect/encoding/Hex";
|
|
15
14
|
import * as Base64 from "effect/encoding/Base64";
|
|
16
15
|
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
@@ -48,13 +47,18 @@ const tokenPermissions = (access) => ({
|
|
|
48
47
|
metadata: "read"
|
|
49
48
|
});
|
|
50
49
|
const ownerAndName = /^[\w.-]+\/[\w.-]+$/;
|
|
50
|
+
/** The mint's body: a token for `name` alone, with `access`'s permissions. */
|
|
51
|
+
const tokenRequest = (name, access) => JSON.stringify({
|
|
52
|
+
repositories: [name],
|
|
53
|
+
permissions: tokenPermissions(access)
|
|
54
|
+
});
|
|
51
55
|
/**
|
|
52
56
|
* The fields of GitHub's JSON refusal kept: its `message` alone. `documentation_url` links a page
|
|
53
57
|
* of the docs, which says nothing of this failure, and is a URL, where userinfo could ride.
|
|
54
58
|
*/
|
|
55
59
|
const githubKept = ["message"];
|
|
56
60
|
/** A failure of the provider's own: its message names the call and the status, never a token. */
|
|
57
|
-
const failed = (call, status) =>
|
|
61
|
+
const failed = (call, status) => gitError("UNAVAILABLE", status === void 0 ? `GitHub didn't answer to ${call}` : `GitHub answered ${status} to ${call}`, { hint: "The job tries again" });
|
|
58
62
|
/** The DER length of `size` bytes. */
|
|
59
63
|
const derLength = (size) => {
|
|
60
64
|
if (size < 128) return [size];
|
|
@@ -174,23 +178,28 @@ const signedBody = async (request, mac) => {
|
|
|
174
178
|
reader.releaseLock();
|
|
175
179
|
}
|
|
176
180
|
};
|
|
177
|
-
/**
|
|
181
|
+
/**
|
|
182
|
+
* A GitHub App provider over the host's HTTP client, captured at construction: each call it makes
|
|
183
|
+
* runs in the fiber that yields it, a try's, so the token's mint and each read sent again while
|
|
184
|
+
* GitHub's Git doesn't know the token are charged to the try's budget, and the first send of a
|
|
185
|
+
* request is the one `httpOf` charges, as it charges every transport's.
|
|
186
|
+
*/
|
|
178
187
|
const github = /* @__PURE__ */ Effect.fnUntraced(function* (options) {
|
|
179
188
|
if (options.app.webhookSecret === "") return yield* fail("INVALID_ARGUMENT", "app.webhookSecret is empty, and anyone could sign a webhook with it: leave it out, or set GitHub's");
|
|
180
189
|
const client = yield* HttpClient.HttpClient;
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
const
|
|
184
|
-
const fetch = (request) => run(client.execute(HttpClientRequest.fromWeb(request)).pipe(Effect.flatMap(responseToWeb)), request.signal);
|
|
190
|
+
const sender = (http) => (request) => http.execute(HttpClientRequest.fromWeb(request)).pipe(Effect.flatMap(responseToWeb), Effect.mapError(() => failed("send a request")));
|
|
191
|
+
const send = sender(client);
|
|
192
|
+
const sendCharged = sender(CallBudget.charged(client));
|
|
185
193
|
const { app } = options;
|
|
186
194
|
const api = (options.apiUrl ?? "https://api.github.com").replace(/\/$/, "");
|
|
187
195
|
const git = (options.gitUrl ?? "https://github.com").replace(/\/$/, "");
|
|
188
|
-
const signer =
|
|
189
|
-
|
|
196
|
+
const signer = Effect.tryPromise({
|
|
197
|
+
try: () => crypto.subtle.importKey("pkcs8", keyBytes(app.privateKey), rsaSigning, false, ["sign"]),
|
|
198
|
+
catch: () => gitError("INVALID_ARGUMENT", "The GitHub App's private key isn't an RSA key Web Crypto takes")
|
|
190
199
|
});
|
|
191
200
|
/** The App's own JWT, signed with its key, for a minute short of 10. */
|
|
192
|
-
const jwt =
|
|
193
|
-
const now = Math.floor(
|
|
201
|
+
const jwt = Effect.gen(function* () {
|
|
202
|
+
const now = Math.floor((yield* Clock.currentTimeMillis) / 1e3);
|
|
194
203
|
const unsigned = `${encodeJson({
|
|
195
204
|
alg: "RS256",
|
|
196
205
|
typ: "JWT"
|
|
@@ -199,57 +208,60 @@ const github = /* @__PURE__ */ Effect.fnUntraced(function* (options) {
|
|
|
199
208
|
exp: now + jwtSeconds,
|
|
200
209
|
iss: app.appId
|
|
201
210
|
})}`;
|
|
202
|
-
const key =
|
|
203
|
-
const signature =
|
|
211
|
+
const key = yield* signer;
|
|
212
|
+
const signature = yield* Effect.tryPromise({
|
|
213
|
+
try: () => crypto.subtle.sign("RSASSA-PKCS1-v1_5", key, encoder.encode(unsigned)),
|
|
214
|
+
catch: () => failed("sign the App's JWT")
|
|
215
|
+
});
|
|
204
216
|
return `${unsigned}.${Base64Url.encode(new Uint8Array(signature))}`;
|
|
205
|
-
};
|
|
217
|
+
});
|
|
206
218
|
/** A token for the installation, limited to `name`, one of its account's repos, and its Git. */
|
|
207
|
-
const tokenFor =
|
|
219
|
+
const tokenFor = Effect.fnUntraced(function* (name, access) {
|
|
208
220
|
const call = "mint a repo's installation token";
|
|
209
221
|
const init = {
|
|
210
222
|
method: "POST",
|
|
211
223
|
headers: {
|
|
212
224
|
accept: "application/vnd.github+json",
|
|
213
|
-
authorization: `Bearer ${
|
|
225
|
+
authorization: `Bearer ${yield* jwt}`,
|
|
214
226
|
"content-type": "application/json",
|
|
215
227
|
"user-agent": "ref0-git",
|
|
216
228
|
"x-github-api-version": "2022-11-28"
|
|
217
229
|
},
|
|
218
|
-
body:
|
|
219
|
-
repositories: [name],
|
|
220
|
-
permissions: tokenPermissions(access)
|
|
221
|
-
})
|
|
230
|
+
body: tokenRequest(name, access)
|
|
222
231
|
};
|
|
223
|
-
if (signal !== void 0) init.signal = signal;
|
|
224
232
|
const url = `${api}/app/installations/${encodeURIComponent(app.installationId)}/access_tokens`;
|
|
225
233
|
const request = new Request(url, init);
|
|
226
|
-
const response =
|
|
227
|
-
throw failed(call);
|
|
228
|
-
});
|
|
234
|
+
const response = yield* sendCharged(request).pipe(Effect.mapError(() => failed(call)));
|
|
229
235
|
if (response.status !== 201) {
|
|
230
|
-
const said =
|
|
231
|
-
|
|
236
|
+
const said = yield* saidOf(request, response, githubKept);
|
|
237
|
+
const refused = failed(call, response.status);
|
|
238
|
+
return yield* Effect.fail(gitErrorFrom(refused, { cause: new ProviderRefused(refused.message, said) }));
|
|
232
239
|
}
|
|
233
|
-
const
|
|
234
|
-
|
|
240
|
+
const body = yield* Effect.promise(() => response.json().catch(() => void 0));
|
|
241
|
+
const answer = decodeToken(body);
|
|
242
|
+
if (Option.isNone(answer)) return yield* Effect.fail(failed(call, response.status));
|
|
235
243
|
return answer.value.token;
|
|
236
|
-
};
|
|
237
|
-
/**
|
|
238
|
-
|
|
239
|
-
|
|
244
|
+
});
|
|
245
|
+
/**
|
|
246
|
+
* `send`, a read sent again while GitHub's Git doesn't know the new token yet: each send after
|
|
247
|
+
* the first charged here, as `httpOf` charged the first.
|
|
248
|
+
*/
|
|
249
|
+
const transport = Effect.fnUntraced(function* (request) {
|
|
250
|
+
if (request.method !== "GET") return yield* send(request);
|
|
251
|
+
let response = yield* send(request.clone());
|
|
240
252
|
for (const wait of propagationWaits) {
|
|
241
|
-
const response = await fetch(request.clone());
|
|
242
253
|
if (response.status !== 401) return response;
|
|
243
|
-
|
|
244
|
-
|
|
254
|
+
yield* Effect.promise(async () => response.body?.cancel());
|
|
255
|
+
yield* Effect.sleep(wait);
|
|
256
|
+
response = yield* sendCharged(request.clone());
|
|
245
257
|
}
|
|
246
|
-
return
|
|
247
|
-
};
|
|
248
|
-
const remote =
|
|
258
|
+
return response;
|
|
259
|
+
});
|
|
260
|
+
const remote = Effect.fnUntraced(function* (repo, access) {
|
|
249
261
|
const parts = repo.split("/");
|
|
250
|
-
if (!ownerAndName.test(repo) || parts.some((part) => /^\.+$/.test(part)))
|
|
262
|
+
if (!ownerAndName.test(repo) || parts.some((part) => /^\.+$/.test(part))) return yield* fail("INVALID_ARGUMENT", `'${repo}' isn't a GitHub repo's owner/name`);
|
|
251
263
|
const [, name = ""] = parts;
|
|
252
|
-
const token =
|
|
264
|
+
const token = yield* tokenFor(name, access);
|
|
253
265
|
return {
|
|
254
266
|
url: `${git}/${repo}.git`,
|
|
255
267
|
credentials: {
|
|
@@ -258,7 +270,7 @@ const github = /* @__PURE__ */ Effect.fnUntraced(function* (options) {
|
|
|
258
270
|
},
|
|
259
271
|
transport
|
|
260
272
|
};
|
|
261
|
-
};
|
|
273
|
+
});
|
|
262
274
|
const provider = {
|
|
263
275
|
name: githubName,
|
|
264
276
|
remote
|
package/dist/sync/http.mjs
CHANGED
|
@@ -12,4 +12,39 @@ const responseToWeb = (response) => Effect.suspend(() => {
|
|
|
12
12
|
headers: response.headers
|
|
13
13
|
}));
|
|
14
14
|
});
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* `body`, cut once `signal` aborts: it errors with the signal's reason, and its source is
|
|
17
|
+
* cancelled, so no read of it waits past the try that sent it (#2397). A Web body outlives the
|
|
18
|
+
* fiber that took its response, since Effect's request drops a Web request's signal and its client
|
|
19
|
+
* hands the fetch's body over whole, so an interrupt never reaches a read that waits on it. The
|
|
20
|
+
* response is left as it came, its `redirected` and `url` with it, for the callers that read them.
|
|
21
|
+
*/
|
|
22
|
+
const bodyUntil = (body, signal) => {
|
|
23
|
+
const reader = body.getReader();
|
|
24
|
+
let stop = () => {};
|
|
25
|
+
return new ReadableStream({
|
|
26
|
+
start: (controller) => {
|
|
27
|
+
stop = () => {
|
|
28
|
+
controller.error(signal.reason);
|
|
29
|
+
reader.cancel(signal.reason).catch(() => void 0);
|
|
30
|
+
};
|
|
31
|
+
if (signal.aborted) stop();
|
|
32
|
+
else signal.addEventListener("abort", stop, { once: true });
|
|
33
|
+
},
|
|
34
|
+
pull: async (controller) => {
|
|
35
|
+
const piece = await reader.read().catch((cause) => {
|
|
36
|
+
signal.removeEventListener("abort", stop);
|
|
37
|
+
throw cause;
|
|
38
|
+
});
|
|
39
|
+
if (signal.aborted) return;
|
|
40
|
+
if (!piece.done) return controller.enqueue(piece.value);
|
|
41
|
+
signal.removeEventListener("abort", stop);
|
|
42
|
+
controller.close();
|
|
43
|
+
},
|
|
44
|
+
cancel: (reason) => {
|
|
45
|
+
signal.removeEventListener("abort", stop);
|
|
46
|
+
return reader.cancel(reason);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
export { bodyUntil, responseToWeb };
|