@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
package/dist/sync/import.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { fail, gitError } from "../contracts/result.mjs";
|
|
2
|
+
import { ImportDepth, importDepthMost } from "../contracts/sync.mjs";
|
|
2
3
|
import { openRepo } from "../core/access.mjs";
|
|
3
4
|
import { CoreParts, QueueParts } from "../core/parts.mjs";
|
|
4
5
|
import { creatingRefView } from "../core/ref-view.mjs";
|
|
5
6
|
import { createWith, repoCalls } from "../core/repos.mjs";
|
|
6
7
|
import { hostRecordOf } from "../store/catalogue.mjs";
|
|
7
8
|
import { importJobName } from "../store/records.mjs";
|
|
8
|
-
import { afterWrites, storeCall } from "../store/errors.mjs";
|
|
9
|
+
import { afterWrites, storeCall, storeCommit } from "../store/errors.mjs";
|
|
9
10
|
import { newChangeId, repoScope } from "../store/scopes.mjs";
|
|
10
11
|
import { unknownProvider } from "./tries.mjs";
|
|
11
12
|
import { heldError } from "../core/receipts.mjs";
|
|
@@ -31,6 +32,7 @@ const importJobKey = "import";
|
|
|
31
32
|
const phases = /* @__PURE__ */ new Set([
|
|
32
33
|
"fetch",
|
|
33
34
|
"receive",
|
|
35
|
+
"lfs",
|
|
34
36
|
"publish"
|
|
35
37
|
]);
|
|
36
38
|
const isPhase = (phase) => phases.has(phase);
|
|
@@ -39,26 +41,35 @@ const cancelled = (repo) => fail("FAILED_PRECONDITION", `The import of '${repo}'
|
|
|
39
41
|
context: { reason: "import-cancelled" }
|
|
40
42
|
});
|
|
41
43
|
const noImport = (repo) => fail("NOT_FOUND", `'${repo}' has no import running`);
|
|
44
|
+
const isImportDepth = /* @__PURE__ */ Schema.is(ImportDepth);
|
|
45
|
+
/** Whether `depth` is one `ImportDepth` takes, as a plain answer: no narrowing of `depth`. */
|
|
46
|
+
const isDepth = (depth) => isImportDepth(depth);
|
|
47
|
+
/** `depth` refused unless it's what an import takes, `ImportDepth`: before anything is written. */
|
|
48
|
+
const checkedDepth = (depth) => depth === void 0 || isDepth(depth) ? Effect.void : fail("INVALID_ARGUMENT", `An import's depth is a whole number from 1 to ${importDepthMost}, not ${depth}`, { hint: "Leave depth out to import the whole history" });
|
|
42
49
|
/** The import's record as its create writes it: nothing listed or copied yet. */
|
|
43
|
-
const startRow = (bound, input, by) =>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
const startRow = (bound, input, by) => {
|
|
51
|
+
const row = {
|
|
52
|
+
source: {
|
|
53
|
+
provider: input.source.provider,
|
|
54
|
+
repo: input.source.repo
|
|
55
|
+
},
|
|
56
|
+
by,
|
|
57
|
+
state: "running",
|
|
58
|
+
roots: [],
|
|
59
|
+
deepest: 0,
|
|
60
|
+
step: bound.limits.firstStep,
|
|
61
|
+
copied: false,
|
|
62
|
+
objects: 0,
|
|
63
|
+
bytes: 0
|
|
64
|
+
};
|
|
65
|
+
if (input.depth !== void 0) row.depth = input.depth;
|
|
66
|
+
return row;
|
|
67
|
+
};
|
|
57
68
|
const encodeSample = /* @__PURE__ */ Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown));
|
|
58
69
|
/** The latest sample the import's running try reported, as `onProgress` takes it, if it's new. */
|
|
59
70
|
const progressOf = /* @__PURE__ */ Effect.fnUntraced(function* (internalId) {
|
|
60
71
|
const { jobs } = yield* QueueParts;
|
|
61
|
-
const sample = (yield* storeCall(
|
|
72
|
+
const sample = (yield* storeCall(jobs.list(repoScope(internalId), { state: "running" }))).items.find((job) => job.name === importJobName)?.progress;
|
|
62
73
|
if (sample === void 0 || !isPhase(sample.phase)) return void 0;
|
|
63
74
|
return {
|
|
64
75
|
seen: yield* encodeSample(sample).pipe(Effect.orElseSucceed(() => void 0)),
|
|
@@ -110,10 +121,12 @@ const importWith = /* @__PURE__ */ Effect.fnUntraced(function* (bound, input) {
|
|
|
110
121
|
if (!bound.providers.has(source.provider)) return yield* Effect.fail(unknownProvider(source.provider));
|
|
111
122
|
const { actor } = input;
|
|
112
123
|
if (actor.anonymous === true) return yield* fail("UNAUTHENTICATED", "An import needs an actor: each step asks again as it");
|
|
124
|
+
yield* checkedDepth(input.depth);
|
|
113
125
|
const data = { source: {
|
|
114
126
|
provider: source.provider,
|
|
115
127
|
repo: source.repo
|
|
116
128
|
} };
|
|
129
|
+
if (input.depth !== void 0) data.depth = input.depth;
|
|
117
130
|
const caller = { actor };
|
|
118
131
|
const by = yield* savedCallerOf(actor.id, caller);
|
|
119
132
|
const create = {
|
|
@@ -125,7 +138,8 @@ const importWith = /* @__PURE__ */ Effect.fnUntraced(function* (bound, input) {
|
|
|
125
138
|
input: [
|
|
126
139
|
"import",
|
|
127
140
|
source.provider,
|
|
128
|
-
source.repo
|
|
141
|
+
source.repo,
|
|
142
|
+
...input.depth === void 0 ? [] : [input.depth]
|
|
129
143
|
],
|
|
130
144
|
put: [importRow(startRow(bound, input, by))],
|
|
131
145
|
jobs: [bound.importJob.encodedJob({
|
|
@@ -149,7 +163,7 @@ const cancelWith = /* @__PURE__ */ Effect.fnUntraced(function* (_bound, input) {
|
|
|
149
163
|
const read = yield* readImport(store, internalId, opened);
|
|
150
164
|
if (read.row?.state !== "running") return yield* noImport(input.repo);
|
|
151
165
|
if (read.cancelled) return;
|
|
152
|
-
yield*
|
|
166
|
+
yield* storeCommit(store.commit(repoScope(internalId), {
|
|
153
167
|
id: newChangeId(),
|
|
154
168
|
expect: read.version,
|
|
155
169
|
put: [{
|
package/dist/sync/layer.mjs
CHANGED
|
@@ -2,18 +2,20 @@ import { register } from "../contracts/git.mjs";
|
|
|
2
2
|
import { fail } from "../contracts/result.mjs";
|
|
3
3
|
import { ImportJobData, MirrorJobData, Sync } from "../contracts/sync.mjs";
|
|
4
4
|
import { SyncBase } from "../core/parts.mjs";
|
|
5
|
+
import { LfsBase } from "../lfs/base.mjs";
|
|
5
6
|
import { withAudienceMemo } from "../core/ref-view.mjs";
|
|
6
7
|
import { CallBudget } from "../store/call-count.mjs";
|
|
7
8
|
import { importJobName, mirrorJobName } from "../store/records.mjs";
|
|
8
9
|
import { importTryTimeout } from "../storage/receive-bounds.mjs";
|
|
9
10
|
import { SyncState, importLimits } from "./bound.mjs";
|
|
10
11
|
import { cancelWith, importWith } from "./import.mjs";
|
|
11
|
-
import { mirrorTry, mirrorWith, mirrorsWith, removeMirrorWith } from "./mirror.mjs";
|
|
12
|
+
import { mirrorFailed, mirrorTry, mirrorWith, mirrorsWith, removeMirrorWith } from "./mirror.mjs";
|
|
12
13
|
import { publishWith } from "./publish.mjs";
|
|
13
14
|
import { importFailed, importTry } from "./step.mjs";
|
|
14
15
|
import { syncRetry } from "./tries.mjs";
|
|
15
16
|
import * as Effect from "effect/Effect";
|
|
16
17
|
import * as HttpClient from "effect/http/HttpClient";
|
|
18
|
+
import * as Option from "effect/Option";
|
|
17
19
|
import { Job } from "@ref0/infra";
|
|
18
20
|
import * as Context from "effect/Context";
|
|
19
21
|
import * as Layer from "effect/Layer";
|
|
@@ -36,10 +38,12 @@ const layerWith = (options, limits) => Layer.effectContext(Effect.gen(function*
|
|
|
36
38
|
providers.set(provider.name, provider);
|
|
37
39
|
}
|
|
38
40
|
const base = yield* SyncBase;
|
|
41
|
+
const lfsBase = yield* Effect.serviceOption(LfsBase);
|
|
39
42
|
const registration = yield* register({ name: "sync" });
|
|
40
43
|
const http = CallBudget.charged(yield* HttpClient.HttpClient);
|
|
41
44
|
const bound = {
|
|
42
45
|
needs: Context.add(base.needs, HttpClient.HttpClient, http),
|
|
46
|
+
lfs: Option.isSome(lfsBase) ? lfsBase.value.copy : Effect.undefined,
|
|
43
47
|
providers,
|
|
44
48
|
caller: { actor: { anonymous: true } },
|
|
45
49
|
limits: {
|
|
@@ -50,7 +54,7 @@ const layerWith = (options, limits) => Layer.effectContext(Effect.gen(function*
|
|
|
50
54
|
mirrorJob: Mirror
|
|
51
55
|
};
|
|
52
56
|
yield* registration.addJob(Import, () => importTry(bound), { onFailure: (_data, failure) => importFailed(bound, failure) });
|
|
53
|
-
yield* registration.addJob(Mirror, (data) => mirrorTry(bound, data));
|
|
57
|
+
yield* registration.addJob(Mirror, (data) => mirrorTry(bound, data), { onFailure: (data) => mirrorFailed(bound, data) });
|
|
54
58
|
const run = (effect) => base.through(withAudienceMemo(Effect.provide(effect, bound.needs)));
|
|
55
59
|
return Context.make(SyncState, bound).pipe(Context.add(Sync, {
|
|
56
60
|
import: (input) => run(importWith(bound, input)),
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { credentialHeader } from "../client/transport.mjs";
|
|
2
|
+
import { gitError } from "../contracts/result.mjs";
|
|
3
|
+
import { lfsType } from "../lfs/answer.mjs";
|
|
4
|
+
import { BatchRequest, LfsObjectAnswer } from "../lfs/wire.mjs";
|
|
5
|
+
import { boundedBytes, dropBody } from "../protocol/bytes/reader.mjs";
|
|
6
|
+
import { decodeJson } from "../protocol/wire/json.mjs";
|
|
7
|
+
import { readBody } from "../store/errors.mjs";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Schema from "effect/Schema";
|
|
10
|
+
import * as Result from "effect/Result";
|
|
11
|
+
/**
|
|
12
|
+
* The most bytes a batch's answer is read to: one of `lfsBatchMost` objects, each a link and the
|
|
13
|
+
* headers it's sent with, takes tens of KiB.
|
|
14
|
+
*/
|
|
15
|
+
const answerBytes = 1048576;
|
|
16
|
+
const BatchAnswer = /* @__PURE__ */ Schema.Struct({ objects: Schema.Array(LfsObjectAnswer) });
|
|
17
|
+
const batchJson = /* @__PURE__ */ Schema.encodeSync(Schema.fromJsonString(BatchRequest));
|
|
18
|
+
/** The statuses an object's error says it's gone with: none held, or deleted. */
|
|
19
|
+
const goneCodes = /* @__PURE__ */ new Set([404, 410]);
|
|
20
|
+
/** The source's LFS API for its Git `url`, as git-lfs finds it: `<repo>.git/info/lfs`. */
|
|
21
|
+
const lfsEndpoint = (url) => {
|
|
22
|
+
const trimmed = url.replace(/\/+$/, "");
|
|
23
|
+
return `${trimmed.endsWith(".git") ? trimmed : `${trimmed}.git`}/info/lfs`;
|
|
24
|
+
};
|
|
25
|
+
const unreadable = (why) => gitError("UNAVAILABLE", `The source's LFS batch answer is unreadable: ${why}`, { hint: "The job tries again" });
|
|
26
|
+
/**
|
|
27
|
+
* The offers an answer's `text` makes for `wanted`, each oid once, in their order: refused unless
|
|
28
|
+
* it's LFS's JSON, answers each of them once at its size and names nothing else, and links each
|
|
29
|
+
* download by `https:` or the remote's own scheme, `remoteProtocol`.
|
|
30
|
+
*/
|
|
31
|
+
const offersOf = (wanted, text, remoteProtocol) => {
|
|
32
|
+
const decoded = decodeJson(BatchAnswer)(text);
|
|
33
|
+
if (Result.isFailure(decoded)) return Result.fail(unreadable("it isn't the JSON LFS sends"));
|
|
34
|
+
const answers = /* @__PURE__ */ new Map();
|
|
35
|
+
for (const answer of decoded.success.objects) {
|
|
36
|
+
if (answers.has(answer.oid)) return Result.fail(unreadable(`it names ${answer.oid} twice`));
|
|
37
|
+
answers.set(answer.oid, answer);
|
|
38
|
+
}
|
|
39
|
+
if (answers.size !== wanted.length) return Result.fail(unreadable("it names other objects than were asked for"));
|
|
40
|
+
const offers = [];
|
|
41
|
+
for (const { oid, size } of wanted) {
|
|
42
|
+
const answer = answers.get(oid);
|
|
43
|
+
if (answer === void 0 || answer.size !== size) return Result.fail(unreadable(`it doesn't answer ${oid} at ${size} bytes`));
|
|
44
|
+
const download = answer.actions?.download;
|
|
45
|
+
if (answer.error !== void 0 || download === void 0) {
|
|
46
|
+
const gone = answer.error !== void 0 && goneCodes.has(answer.error.code);
|
|
47
|
+
offers.push({
|
|
48
|
+
kind: "missing",
|
|
49
|
+
oid,
|
|
50
|
+
size,
|
|
51
|
+
reason: gone ? "not-found" : "refused"
|
|
52
|
+
});
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const protocol = URL.canParse(download.href) ? new URL(download.href).protocol : "";
|
|
56
|
+
if (protocol !== "https:" && protocol !== remoteProtocol) return Result.fail(unreadable(`its link for ${oid} isn't https`));
|
|
57
|
+
offers.push({
|
|
58
|
+
kind: "download",
|
|
59
|
+
oid,
|
|
60
|
+
size,
|
|
61
|
+
href: download.href,
|
|
62
|
+
header: download.header ?? {}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return Result.succeed(offers);
|
|
66
|
+
};
|
|
67
|
+
/** A request the source's API didn't answer, kept without its cause, which may hold its link. */
|
|
68
|
+
const unanswered = /* @__PURE__ */ gitError("UNAVAILABLE", "The source's LFS API didn't answer", { hint: "The job tries again" });
|
|
69
|
+
/** The source's batch refusing, by its status alone: its body may echo the credential. */
|
|
70
|
+
const batchRefused = (status) => gitError("UNAVAILABLE", `The source's LFS batch answered ${status}`, { hint: "The job tries again" });
|
|
71
|
+
/** A response's body let go, its cancel's failure no reason to fail what's already decided. */
|
|
72
|
+
const letGo = (response) => dropBody(response.body);
|
|
73
|
+
/**
|
|
74
|
+
* The source's offers for `wanted`, at most `lfsBatchMost` objects, asked of `remote` with its
|
|
75
|
+
* credentials through `send`. A source answering 404 or 501 serves no LFS API: `no-lfs`. Any other
|
|
76
|
+
* refusal, an answer unread or one past `answerBytes`, fails, so the job tries again.
|
|
77
|
+
*/
|
|
78
|
+
const lfsDownloads = /* @__PURE__ */ Effect.fnUntraced(function* (send, remote, wanted, signal) {
|
|
79
|
+
if (wanted.length > 100) return yield* Effect.die(/* @__PURE__ */ new RangeError(`A batch asks at most 100 objects`));
|
|
80
|
+
const headers = new Headers({
|
|
81
|
+
accept: lfsType,
|
|
82
|
+
"content-type": lfsType
|
|
83
|
+
});
|
|
84
|
+
const credential = yield* credentialHeader(remote.credentials);
|
|
85
|
+
if (credential !== void 0) headers.set("authorization", credential);
|
|
86
|
+
const body = batchJson({
|
|
87
|
+
operation: "download",
|
|
88
|
+
transfers: ["basic"],
|
|
89
|
+
objects: wanted.map(({ oid, size }) => ({
|
|
90
|
+
oid,
|
|
91
|
+
size
|
|
92
|
+
})),
|
|
93
|
+
hash_algo: "sha256"
|
|
94
|
+
});
|
|
95
|
+
const request = new Request(`${lfsEndpoint(remote.url)}/objects/batch`, {
|
|
96
|
+
method: "POST",
|
|
97
|
+
headers,
|
|
98
|
+
body,
|
|
99
|
+
signal
|
|
100
|
+
});
|
|
101
|
+
const response = yield* Effect.mapError(send(request), () => unanswered);
|
|
102
|
+
if (response.status === 404 || response.status === 501) {
|
|
103
|
+
yield* letGo(response);
|
|
104
|
+
return { kind: "no-lfs" };
|
|
105
|
+
}
|
|
106
|
+
if (response.status !== 200 || response.body === null) {
|
|
107
|
+
yield* letGo(response);
|
|
108
|
+
return yield* Effect.fail(batchRefused(response.status));
|
|
109
|
+
}
|
|
110
|
+
const bytes = yield* boundedBytes(response.body, answerBytes, (reader) => readBody(() => reader.read(), () => Effect.fail(unanswered)));
|
|
111
|
+
if (bytes === void 0) return yield* Effect.fail(unreadable(`it's past ${answerBytes} bytes`));
|
|
112
|
+
const protocol = URL.canParse(remote.url) ? new URL(remote.url).protocol : "https:";
|
|
113
|
+
return {
|
|
114
|
+
kind: "offers",
|
|
115
|
+
offers: yield* Effect.fromResult(offersOf(wanted, new TextDecoder().decode(bytes), protocol))
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
export { letGo, lfsDownloads, lfsEndpoint, offersOf };
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { gitError } from "../contracts/result.mjs";
|
|
2
|
+
import { importLfsPagesMost, importRow, lfsMissedHeld, lfsPageKey, lfsPageRow, missedCounted, noImportLfs, readLfsPage } from "../core/imports.mjs";
|
|
3
|
+
import { CoreParts } from "../core/parts.mjs";
|
|
4
|
+
import { largestObject } from "../lfs/rows.mjs";
|
|
5
|
+
import { lfsOidAt, lfsSizeAt, pointersOfRecord, pointersRecords } from "../storage/lfs-pointers.mjs";
|
|
6
|
+
import { storeCommit } from "../store/errors.mjs";
|
|
7
|
+
import { newChangeId, repoScope } from "../store/scopes.mjs";
|
|
8
|
+
import { lfsCopyBytes } from "./bound.mjs";
|
|
9
|
+
import { letGo, lfsDownloads } from "./lfs-batch.mjs";
|
|
10
|
+
import { bodyUntil } from "./http.mjs";
|
|
11
|
+
import { remoteOf, senderOf } from "./tries.mjs";
|
|
12
|
+
import * as Effect from "effect/Effect";
|
|
13
|
+
import * as Result from "effect/Result";
|
|
14
|
+
import * as Stream from "effect/Stream";
|
|
15
|
+
// src/sync/lfs-copy.ts
|
|
16
|
+
/**
|
|
17
|
+
* `row` with the pointers a segment's receive `found` kept as pages beside it, `put` in the commit
|
|
18
|
+
* that lands the segment, when `copying`: on a server without LFS, `row` as it was. Past
|
|
19
|
+
* `importLfsPagesMost` pages, the pointers are counted missing, unnamed.
|
|
20
|
+
*/
|
|
21
|
+
const withLfsPages = (row, found, copying) => {
|
|
22
|
+
const none = [];
|
|
23
|
+
if (!copying) return {
|
|
24
|
+
row,
|
|
25
|
+
put: none
|
|
26
|
+
};
|
|
27
|
+
const lfs = row.lfs ?? noImportLfs;
|
|
28
|
+
const records = found === void 0 ? [] : pointersRecords(found);
|
|
29
|
+
const kept = records.slice(0, Math.max(0, importLfsPagesMost - lfs.pages));
|
|
30
|
+
const dropped = records.slice(kept.length).reduce((sum, record) => sum + record.byteLength / 57, 0);
|
|
31
|
+
const put = kept.map((record, at) => lfsPageRow(lfs.pages + at, record));
|
|
32
|
+
return {
|
|
33
|
+
row: {
|
|
34
|
+
...row,
|
|
35
|
+
lfs: {
|
|
36
|
+
...lfs,
|
|
37
|
+
pages: lfs.pages + kept.length,
|
|
38
|
+
missing: lfs.missing + dropped
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
put
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* What one step asks for: the distinct objects of `pointers` from entry `from`, up to
|
|
46
|
+
* `lfsBatchMost` of them, or until the next would take the step past `lfsCopyBytes`, an object
|
|
47
|
+
* past it alone; and `end`, the entry after the last taken. An object past `largestObject` is
|
|
48
|
+
* never downloaded, so it takes none of the bytes.
|
|
49
|
+
*/
|
|
50
|
+
const takenFrom = (pointers, from) => {
|
|
51
|
+
const wanted = [];
|
|
52
|
+
const seen = /* @__PURE__ */ new Set();
|
|
53
|
+
let bytes = 0;
|
|
54
|
+
let end = from;
|
|
55
|
+
for (; end < pointers.count; end += 1) {
|
|
56
|
+
const oid = lfsOidAt(pointers, end);
|
|
57
|
+
if (seen.has(oid)) continue;
|
|
58
|
+
const size = lfsSizeAt(pointers, end);
|
|
59
|
+
const taking = size > largestObject ? 0 : size;
|
|
60
|
+
if (wanted.length === 100) break;
|
|
61
|
+
if (wanted.length > 0 && bytes + taking > lfsCopyBytes) break;
|
|
62
|
+
seen.add(oid);
|
|
63
|
+
wanted.push({
|
|
64
|
+
oid,
|
|
65
|
+
size
|
|
66
|
+
});
|
|
67
|
+
bytes += taking;
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
wanted,
|
|
71
|
+
end
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const pageUnreadable = (page) => gitError("DATA_LOSS", `The import's page ${page} of LFS pointers isn't a page of pointers`);
|
|
75
|
+
const copyRaced = () => gitError("UNAVAILABLE", "Another write moved the import while its LFS copy ran", { hint: "The job tries again" });
|
|
76
|
+
const downloadUnanswered = /* @__PURE__ */ gitError("UNAVAILABLE", "The source's LFS download didn't answer", { hint: "The job tries again" });
|
|
77
|
+
/** A download refused, by its status alone: an expired link's 401 or 403, or the store's 5xx. */
|
|
78
|
+
const downloadRefused = (status) => gitError("UNAVAILABLE", `The source's LFS download answered ${status}`, { hint: "The job tries again, with fresh links" });
|
|
79
|
+
/** The copy's progress, which a claim taken again refuses: the sample's dropped, as `report`'s. */
|
|
80
|
+
const reported = (context, lfs) => context.progress({
|
|
81
|
+
phase: "lfs",
|
|
82
|
+
measures: [{
|
|
83
|
+
unit: "objects",
|
|
84
|
+
completed: lfs.copied
|
|
85
|
+
}, {
|
|
86
|
+
unit: "bytes",
|
|
87
|
+
completed: lfs.bytes
|
|
88
|
+
}]
|
|
89
|
+
});
|
|
90
|
+
/**
|
|
91
|
+
* One offer's bytes, piped from its link to `staging`'s key as they come: `landed`, `not-found`
|
|
92
|
+
* for a link that answers 404 or 410, or `other-bytes` for bytes the bucket refused as not the
|
|
93
|
+
* oid's or not its size. Any other refusal fails, so the job tries again with fresh links.
|
|
94
|
+
*/
|
|
95
|
+
const downloaded = /* @__PURE__ */ Effect.fnUntraced(function* (send, offer, staging, copy, signal) {
|
|
96
|
+
const request = new Request(offer.href, {
|
|
97
|
+
headers: offer.header,
|
|
98
|
+
signal
|
|
99
|
+
});
|
|
100
|
+
const response = yield* Effect.mapError(send(request), () => downloadUnanswered);
|
|
101
|
+
const { body } = response;
|
|
102
|
+
if (response.status === 404 || response.status === 410) {
|
|
103
|
+
yield* letGo(response);
|
|
104
|
+
return "not-found";
|
|
105
|
+
}
|
|
106
|
+
if (response.status !== 200 || body === null) {
|
|
107
|
+
yield* letGo(response);
|
|
108
|
+
return yield* Effect.fail(downloadRefused(response.status));
|
|
109
|
+
}
|
|
110
|
+
const bytes = Stream.fromReadableStream({
|
|
111
|
+
evaluate: () => bodyUntil(body, signal),
|
|
112
|
+
onError: () => downloadUnanswered
|
|
113
|
+
});
|
|
114
|
+
const put = yield* Effect.result(copy.put(staging, bytes, offer.size, offer.oid));
|
|
115
|
+
if (Result.isSuccess(put)) return "landed";
|
|
116
|
+
if (put.failure.code === "INVALID_ARGUMENT") return "other-bytes";
|
|
117
|
+
return yield* Effect.fail(put.failure);
|
|
118
|
+
});
|
|
119
|
+
/**
|
|
120
|
+
* The copy's commit at `version`: each object in `landed` listed and its staging row dropped,
|
|
121
|
+
* each in `missed` the record doesn't name yet counted, and named, as `missedCounted` says, and
|
|
122
|
+
* the cursor moved to `cursor`, the page's row deleted once it's past. Without a cursor, the
|
|
123
|
+
* landed objects alone, as a step that failed partway keeps them, so its next try skips them.
|
|
124
|
+
*/
|
|
125
|
+
const committed = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, copy, version, row, lfs, landed, missed, cursor) {
|
|
126
|
+
const { store } = yield* CoreParts;
|
|
127
|
+
const writes = copy.listing(landed);
|
|
128
|
+
const held = yield* lfsMissedHeld(store, attempt.internalId, missed.map(({ oid }) => oid));
|
|
129
|
+
const counted = missedCounted(lfs, missed, held);
|
|
130
|
+
const passed = cursor !== void 0 && cursor.end >= cursor.count;
|
|
131
|
+
const moved = cursor === void 0 ? {} : passed ? {
|
|
132
|
+
page: lfs.page + 1,
|
|
133
|
+
entry: 0
|
|
134
|
+
} : {
|
|
135
|
+
page: lfs.page,
|
|
136
|
+
entry: cursor.end
|
|
137
|
+
};
|
|
138
|
+
const next = {
|
|
139
|
+
...lfs,
|
|
140
|
+
...moved,
|
|
141
|
+
copied: lfs.copied + landed.length,
|
|
142
|
+
bytes: lfs.bytes + landed.reduce((sum, { size }) => sum + size, 0),
|
|
143
|
+
missing: counted.missing,
|
|
144
|
+
named: counted.named
|
|
145
|
+
};
|
|
146
|
+
if (!(yield* storeCommit(store.commit(repoScope(attempt.internalId), {
|
|
147
|
+
id: newChangeId(),
|
|
148
|
+
expect: version,
|
|
149
|
+
put: [
|
|
150
|
+
importRow({
|
|
151
|
+
...row,
|
|
152
|
+
lfs: next
|
|
153
|
+
}),
|
|
154
|
+
...writes.put,
|
|
155
|
+
...counted.put
|
|
156
|
+
],
|
|
157
|
+
delete: [...writes.delete, ...passed ? [lfsPageKey(lfs.page)] : []]
|
|
158
|
+
}))).ok) return yield* Effect.fail(copyRaced());
|
|
159
|
+
return next;
|
|
160
|
+
});
|
|
161
|
+
/**
|
|
162
|
+
* Each distinct object of `pointers` from `from` but those `listed`, missing as a source with no
|
|
163
|
+
* LFS API leaves it: `too-large` for one LFS keeps none of anyway.
|
|
164
|
+
*/
|
|
165
|
+
const restMissing = (pointers, from, listed) => {
|
|
166
|
+
const missed = /* @__PURE__ */ new Map();
|
|
167
|
+
for (let at = from; at < pointers.count; at += 1) {
|
|
168
|
+
const oid = lfsOidAt(pointers, at);
|
|
169
|
+
if (!listed.has(oid) && !missed.has(oid)) {
|
|
170
|
+
const size = lfsSizeAt(pointers, at);
|
|
171
|
+
missed.set(oid, {
|
|
172
|
+
oid,
|
|
173
|
+
size,
|
|
174
|
+
reason: size > largestObject ? "too-large" : "no-lfs"
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return [...missed.values()];
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* One step of the copy, at the import's record as read at `version`: the objects `takenFrom` the
|
|
182
|
+
* cursor's page that the repo doesn't list, asked of the source in one batch, each download piped
|
|
183
|
+
* to its object's staging key, one at a time, then one commit. An object whose bytes an earlier
|
|
184
|
+
* try put at its key, and didn't list, is listed with no download. A source with no LFS API gives
|
|
185
|
+
* none, so the rest of the page is missing with them. A download that fails keeps what landed
|
|
186
|
+
* before it and fails the try, whose next asks a fresh batch from the cursor. Upkeep's commit that
|
|
187
|
+
* ends a stage moves the version, so a step that staged before it fails `copyRaced`, and its next
|
|
188
|
+
* try stages again.
|
|
189
|
+
*/
|
|
190
|
+
const copyLfs = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, version, row, lfs, copy) {
|
|
191
|
+
const { bound, internalId, context } = attempt;
|
|
192
|
+
const { store } = yield* CoreParts;
|
|
193
|
+
const pointers = pointersOfRecord(yield* readLfsPage(store, internalId, lfs.page));
|
|
194
|
+
if (pointers === void 0) return yield* Effect.fail(pageUnreadable(lfs.page));
|
|
195
|
+
yield* reported(context, lfs);
|
|
196
|
+
const { wanted, end } = takenFrom(pointers, lfs.entry);
|
|
197
|
+
const listed = yield* copy.listed(internalId, wanted.map(({ oid }) => oid));
|
|
198
|
+
const unlisted = wanted.filter(({ oid }) => !listed.has(oid));
|
|
199
|
+
const tooLarge = unlisted.flatMap(({ oid, size }) => size > largestObject ? [{
|
|
200
|
+
oid,
|
|
201
|
+
size,
|
|
202
|
+
reason: "too-large"
|
|
203
|
+
}] : []);
|
|
204
|
+
const asked = unlisted.filter(({ size }) => size <= largestObject);
|
|
205
|
+
if (asked.length === 0) return yield* committed(attempt, copy, version, row, lfs, [], tooLarge, {
|
|
206
|
+
end,
|
|
207
|
+
count: pointers.count
|
|
208
|
+
});
|
|
209
|
+
const remote = yield* remoteOf(bound, row.source, context.signal, "read");
|
|
210
|
+
const send = yield* senderOf(remote);
|
|
211
|
+
const batch = yield* lfsDownloads(send, remote, asked, context.signal);
|
|
212
|
+
if (batch.kind === "no-lfs") {
|
|
213
|
+
const missed = restMissing(pointers, lfs.entry, listed);
|
|
214
|
+
return yield* committed(attempt, copy, version, row, lfs, [], missed, {
|
|
215
|
+
end: pointers.count,
|
|
216
|
+
count: pointers.count
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
const missed = [...tooLarge];
|
|
220
|
+
const downloads = [];
|
|
221
|
+
for (const offer of batch.offers) if (offer.kind === "download") downloads.push(offer);
|
|
222
|
+
else missed.push({
|
|
223
|
+
oid: offer.oid,
|
|
224
|
+
size: offer.size,
|
|
225
|
+
reason: offer.reason
|
|
226
|
+
});
|
|
227
|
+
const staged = yield* copy.stage(internalId, downloads);
|
|
228
|
+
const landed = [];
|
|
229
|
+
for (const [index, offer] of downloads.entries()) {
|
|
230
|
+
const staging = staged[index];
|
|
231
|
+
if (staging === void 0) break;
|
|
232
|
+
if (staging.landed) {
|
|
233
|
+
landed.push({
|
|
234
|
+
oid: offer.oid,
|
|
235
|
+
size: offer.size,
|
|
236
|
+
staging
|
|
237
|
+
});
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const outcome = yield* Effect.result(downloaded(send, offer, staging, copy, context.signal));
|
|
241
|
+
if (Result.isFailure(outcome)) {
|
|
242
|
+
if (landed.length > 0) yield* committed(attempt, copy, version, row, lfs, landed, []);
|
|
243
|
+
return yield* Effect.fail(outcome.failure);
|
|
244
|
+
}
|
|
245
|
+
const { oid, size } = offer;
|
|
246
|
+
if (outcome.success === "landed") landed.push({
|
|
247
|
+
oid,
|
|
248
|
+
size,
|
|
249
|
+
staging
|
|
250
|
+
});
|
|
251
|
+
else missed.push({
|
|
252
|
+
oid,
|
|
253
|
+
size,
|
|
254
|
+
reason: outcome.success
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
return yield* committed(attempt, copy, version, row, lfs, landed, missed, {
|
|
258
|
+
end,
|
|
259
|
+
count: pointers.count
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
export { copyLfs, takenFrom, withLfsPages };
|