@ref0/git 0.0.0 → 0.3.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/LICENSE +202 -0
- package/dist/access/private-refs.d.mts +27 -0
- package/dist/access/private-refs.mjs +173 -0
- package/dist/access.d.mts +2 -0
- package/dist/access.mjs +1 -0
- package/dist/auth/access-jwt.d.mts +21 -0
- package/dist/auth/access-jwt.mjs +102 -0
- package/dist/auth/acting.mjs +15 -0
- package/dist/auth/authorize.d.mts +5 -0
- package/dist/auth/authorize.mjs +292 -0
- package/dist/auth/credentials.mjs +57 -0
- package/dist/auth/fences.d.mts +5 -0
- package/dist/auth/fences.mjs +65 -0
- package/dist/auth/grants.mjs +61 -0
- package/dist/auth/helpers.d.mts +17 -0
- package/dist/auth/helpers.mjs +25 -0
- package/dist/auth/host-function.d.mts +4 -0
- package/dist/auth/host-function.mjs +69 -0
- package/dist/auth/identify.d.mts +6 -0
- package/dist/auth/identify.mjs +97 -0
- package/dist/auth/token-rows.mjs +100 -0
- package/dist/auth/token-text.mjs +66 -0
- package/dist/auth/tokens.d.mts +10 -0
- package/dist/auth/tokens.mjs +347 -0
- package/dist/auth.d.mts +7 -0
- package/dist/auth.mjs +6 -0
- package/dist/client/answer.mjs +141 -0
- package/dist/client/client.d.mts +23 -0
- package/dist/client/client.mjs +50 -0
- package/dist/client/git-http.mjs +201 -0
- package/dist/client/helper-node.mjs +19 -0
- package/dist/client/local.mjs +170 -0
- package/dist/client/negotiate.mjs +170 -0
- package/dist/client/push-upload.mjs +53 -0
- package/dist/client/remote-helper.mjs +129 -0
- package/dist/client/remote.mjs +398 -0
- package/dist/client/run-remote-helper.d.mts +35 -0
- package/dist/client/run-remote-helper.mjs +259 -0
- package/dist/client/scrub.d.mts +18 -0
- package/dist/client/scrub.mjs +38 -0
- package/dist/client/transport.d.mts +2 -0
- package/dist/client/transport.mjs +211 -0
- package/dist/contracts/access.d.mts +87 -0
- package/dist/contracts/actors.d.mts +144 -0
- package/dist/contracts/blobs.d.mts +38 -0
- package/dist/contracts/calls-spent.d.mts +11 -0
- package/dist/contracts/calls-spent.mjs +151 -0
- package/dist/contracts/client.d.mts +90 -0
- package/dist/contracts/commits.d.mts +126 -0
- package/dist/contracts/engine.d.mts +134 -0
- package/dist/contracts/events.d.mts +276 -0
- package/dist/contracts/files.d.mts +75 -0
- package/dist/contracts/forks.d.mts +78 -0
- package/dist/contracts/grants.d.mts +60 -0
- package/dist/contracts/handlers.d.mts +11 -0
- package/dist/contracts/ids.d.mts +15 -0
- package/dist/contracts/ids.mjs +15 -0
- package/dist/contracts/lfs.d.mts +27 -0
- package/dist/contracts/merges.d.mts +33 -0
- package/dist/contracts/objects.d.mts +645 -0
- package/dist/contracts/objects.mjs +54 -0
- package/dist/contracts/operations.d.mts +133 -0
- package/dist/contracts/promises.d.mts +38 -0
- package/dist/contracts/promises.mjs +13 -0
- package/dist/contracts/push-uploads.d.mts +44 -0
- package/dist/contracts/queue.d.mts +402 -0
- package/dist/contracts/refs.d.mts +95 -0
- package/dist/contracts/remote.d.mts +50 -0
- package/dist/contracts/repos.d.mts +153 -0
- package/dist/contracts/result.d.mts +133 -0
- package/dist/contracts/result.mjs +34 -0
- package/dist/contracts/rules.d.mts +159 -0
- package/dist/contracts/server.d.mts +272 -0
- package/dist/contracts/services.d.mts +36 -0
- package/dist/contracts/services.mjs +13 -0
- package/dist/contracts/signin.d.mts +126 -0
- package/dist/contracts/store.d.mts +41 -0
- package/dist/contracts/sync.d.mts +210 -0
- package/dist/contracts/sync.mjs +8 -0
- package/dist/contracts/tags.d.mts +50 -0
- package/dist/contracts/tags.mjs +6 -0
- package/dist/contracts/tokens.d.mts +87 -0
- package/dist/contracts/tokens.mjs +15 -0
- package/dist/contracts/topics.d.mts +180 -0
- package/dist/contracts/trees.d.mts +84 -0
- package/dist/contracts/work.d.mts +31 -0
- package/dist/core/access.d.mts +22 -0
- package/dist/core/access.mjs +262 -0
- package/dist/core/ancestry.mjs +235 -0
- package/dist/core/call-names.d.mts +1 -0
- package/dist/core/call-names.mjs +93 -0
- package/dist/core/clock.mjs +18 -0
- package/dist/core/events/deliver.mjs +475 -0
- package/dist/core/events/stream.d.mts +19 -0
- package/dist/core/events/stream.mjs +297 -0
- package/dist/core/forks.mjs +1027 -0
- package/dist/core/hooks/post-receive.mjs +212 -0
- package/dist/core/hooks/pre-receive.d.mts +5 -0
- package/dist/core/hooks/pre-receive.mjs +34 -0
- package/dist/core/index-job.mjs +198 -0
- package/dist/core/names.mjs +30 -0
- package/dist/core/objects/blobs.mjs +60 -0
- package/dist/core/objects/commit-writes.mjs +185 -0
- package/dist/core/objects/commits.mjs +172 -0
- package/dist/core/objects/files.mjs +211 -0
- package/dist/core/objects/lines.mjs +42 -0
- package/dist/core/objects/merges.mjs +83 -0
- package/dist/core/objects/peel.mjs +166 -0
- package/dist/core/objects/reading.mjs +284 -0
- package/dist/core/objects/tags.mjs +96 -0
- package/dist/core/objects/tree-edits.mjs +266 -0
- package/dist/core/objects/trees.mjs +229 -0
- package/dist/core/objects/writing.mjs +266 -0
- package/dist/core/own-writes.mjs +94 -0
- package/dist/core/promise.mjs +64 -0
- package/dist/core/publish.mjs +142 -0
- package/dist/core/push-decide.mjs +206 -0
- package/dist/core/push.mjs +1070 -0
- package/dist/core/receipts.d.mts +7 -0
- package/dist/core/receipts.mjs +234 -0
- package/dist/core/ref-conflicts.mjs +27 -0
- package/dist/core/refs.mjs +359 -0
- package/dist/core/repack.mjs +521 -0
- package/dist/core/repos.mjs +752 -0
- package/dist/core/rules/changes.mjs +57 -0
- package/dist/core/rules/check.mjs +101 -0
- package/dist/core/rules/commit-changes.mjs +216 -0
- package/dist/core/rules/context.d.mts +9 -0
- package/dist/core/rules/context.mjs +120 -0
- package/dist/core/rules/define.d.mts +5 -0
- package/dist/core/rules/define.mjs +13 -0
- package/dist/core/rules/facts.mjs +13 -0
- package/dist/core/rules/fetch.d.mts +5 -0
- package/dist/core/rules/fetch.mjs +59 -0
- package/dist/core/rules/file-globs.mjs +55 -0
- package/dist/core/rules/files.mjs +142 -0
- package/dist/core/rules/patterns.mjs +23 -0
- package/dist/core/rules/protect.d.mts +9 -0
- package/dist/core/rules/protect.mjs +116 -0
- package/dist/core/seam.d.mts +26 -0
- package/dist/core/seam.mjs +54 -0
- package/dist/core/sight.mjs +99 -0
- package/dist/core/tokens.mjs +95 -0
- package/dist/core/view.d.mts +9 -0
- package/dist/core/view.mjs +221 -0
- package/dist/core/work.mjs +92 -0
- package/dist/effect.d.mts +20 -0
- package/dist/effect.mjs +18 -0
- package/dist/engine/allotted-xdiff.d.mts +4 -0
- package/dist/engine/allotted-xdiff.mjs +80 -0
- package/dist/engine/attribute-patterns.mjs +163 -0
- package/dist/engine/attributes.mjs +226 -0
- package/dist/engine/combined.mjs +653 -0
- package/dist/engine/commits.mjs +90 -0
- package/dist/engine/content.d.mts +4 -0
- package/dist/engine/content.mjs +221 -0
- package/dist/engine/diff.mjs +49 -0
- package/dist/engine/engine.d.mts +25 -0
- package/dist/engine/engine.mjs +49 -0
- package/dist/engine/failures.d.mts +4 -0
- package/dist/engine/failures.mjs +23 -0
- package/dist/engine/line-count.mjs +23 -0
- package/dist/engine/merge-base-walk.d.mts +2 -0
- package/dist/engine/merge-base-walk.mjs +265 -0
- package/dist/engine/merge-bases.mjs +27 -0
- package/dist/engine/merge-renames.mjs +165 -0
- package/dist/engine/merge.mjs +1125 -0
- package/dist/engine/parts.d.mts +8 -0
- package/dist/engine/parts.mjs +9 -0
- package/dist/engine/reads.d.mts +5 -0
- package/dist/engine/reads.mjs +105 -0
- package/dist/engine/walk.mjs +328 -0
- package/dist/engine/xdiff/NOTICE.md +63 -0
- package/dist/engine/xdiff/compiled.d.mts +7 -0
- package/dist/engine/xdiff/compiled.mjs +9 -0
- package/dist/engine/xdiff/embedded.mjs +4 -0
- package/dist/engine/xdiff/node.d.mts +7 -0
- package/dist/engine/xdiff/node.mjs +10 -0
- package/dist/engine/xdiff/upstream/LGPL-2.1 +511 -0
- package/dist/engine/xdiff/xdiff.wasm +0 -0
- package/dist/engine/xdiff.d.mts +34 -0
- package/dist/engine/xdiff.mjs +380 -0
- package/dist/engine.d.mts +3 -0
- package/dist/engine.mjs +3 -0
- package/dist/extend.d.mts +4 -0
- package/dist/extend.mjs +3 -0
- package/dist/http/answers.mjs +74 -0
- package/dist/http/bodies.mjs +143 -0
- package/dist/http/core-parts.mjs +252 -0
- package/dist/http/fetch-depth.mjs +26 -0
- package/dist/http/handler.mjs +94 -0
- package/dist/http/node.d.mts +70 -0
- package/dist/http/node.mjs +178 -0
- package/dist/http/paths.d.mts +9 -0
- package/dist/http/paths.mjs +118 -0
- package/dist/http/push-uploads.mjs +286 -0
- package/dist/http/receive-pack.mjs +235 -0
- package/dist/http/upload-pack.mjs +229 -0
- package/dist/index.d.mts +46 -0
- package/dist/index.mjs +16 -0
- package/dist/lfs/calls.mjs +16 -0
- package/dist/lfs/locks.mjs +161 -0
- package/dist/lfs/objects.mjs +370 -0
- package/dist/lfs/pointers.mjs +141 -0
- package/dist/lfs/repo.mjs +42 -0
- package/dist/lfs/rows.mjs +108 -0
- package/dist/lfs/service.mjs +34 -0
- package/dist/lfs/upkeep.mjs +162 -0
- package/dist/lfs/wire.mjs +102 -0
- package/dist/node.d.mts +3 -0
- package/dist/node.mjs +3 -0
- package/dist/protocol/bytes/buffers.d.mts +38 -0
- package/dist/protocol/bytes/buffers.mjs +62 -0
- package/dist/protocol/bytes/crc32.d.mts +4 -0
- package/dist/protocol/bytes/crc32.mjs +14 -0
- package/dist/protocol/bytes/deflate.d.mts +78 -0
- package/dist/protocol/bytes/deflate.mjs +175 -0
- package/dist/protocol/bytes/errors.d.mts +20 -0
- package/dist/protocol/bytes/errors.mjs +19 -0
- package/dist/protocol/bytes/hex.mjs +16 -0
- package/dist/protocol/bytes/hmac-sha256.mjs +91 -0
- package/dist/protocol/bytes/inflate.d.mts +40 -0
- package/dist/protocol/bytes/inflate.mjs +109 -0
- package/dist/protocol/bytes/joined.d.mts +2 -0
- package/dist/protocol/bytes/joined.mjs +25 -0
- package/dist/protocol/bytes/sha1-hasher.d.mts +20 -0
- package/dist/protocol/bytes/sha1-hasher.mjs +72 -0
- package/dist/protocol/bytes/sha1.d.mts +35 -0
- package/dist/protocol/bytes/sha1.mjs +409 -0
- package/dist/protocol/bytes/sha256.mjs +156 -0
- package/dist/protocol/bytes/streams.mjs +11 -0
- package/dist/protocol/bytes/text.mjs +19 -0
- package/dist/protocol/diff/diff-raw.d.mts +29 -0
- package/dist/protocol/diff/diff-raw.mjs +73 -0
- package/dist/protocol/diff/patch.mjs +92 -0
- package/dist/protocol/diff/paths.mjs +67 -0
- package/dist/protocol/diff/read.d.mts +62 -0
- package/dist/protocol/diff/read.mjs +342 -0
- package/dist/protocol/diff/rename-similarity.mjs +428 -0
- package/dist/protocol/diff/text.mjs +12 -0
- package/dist/protocol/diff/tree-diff.d.mts +41 -0
- package/dist/protocol/diff/tree-diff.mjs +607 -0
- package/dist/protocol/framing/band.d.mts +10 -0
- package/dist/protocol/framing/band.mjs +16 -0
- package/dist/protocol/framing/pkt-line.d.mts +48 -0
- package/dist/protocol/framing/pkt-line.mjs +92 -0
- package/dist/protocol/objects/checked-blobs.mjs +127 -0
- package/dist/protocol/objects/commit.d.mts +25 -0
- package/dist/protocol/objects/commit.mjs +138 -0
- package/dist/protocol/objects/fsck-gitmodules.mjs +296 -0
- package/dist/protocol/objects/fsck-names.mjs +189 -0
- package/dist/protocol/objects/fsck.mjs +297 -0
- package/dist/protocol/objects/headers.mjs +109 -0
- package/dist/protocol/objects/held.mjs +56 -0
- package/dist/protocol/objects/iconv.mjs +145 -0
- package/dist/protocol/objects/ident.mjs +111 -0
- package/dist/protocol/objects/lfs-pointer.d.mts +8 -0
- package/dist/protocol/objects/lfs-pointer.mjs +63 -0
- package/dist/protocol/objects/links-raw.mjs +89 -0
- package/dist/protocol/objects/object-rules.mjs +75 -0
- package/dist/protocol/objects/object.d.mts +16 -0
- package/dist/protocol/objects/object.mjs +29 -0
- package/dist/protocol/objects/tag.d.mts +21 -0
- package/dist/protocol/objects/tag.mjs +96 -0
- package/dist/protocol/objects/tree.d.mts +43 -0
- package/dist/protocol/objects/tree.mjs +162 -0
- package/dist/protocol/objects/utf8-verify.mjs +71 -0
- package/dist/protocol/packs/delta.d.mts +57 -0
- package/dist/protocol/packs/delta.mjs +229 -0
- package/dist/protocol/packs/graph.mjs +78 -0
- package/dist/protocol/packs/idx.d.mts +54 -0
- package/dist/protocol/packs/idx.mjs +274 -0
- package/dist/protocol/packs/indexer.d.mts +167 -0
- package/dist/protocol/packs/indexer.mjs +507 -0
- package/dist/protocol/packs/parts.d.mts +40 -0
- package/dist/protocol/packs/parts.mjs +89 -0
- package/dist/protocol/packs/pos.mjs +51 -0
- package/dist/protocol/packs/reader.d.mts +180 -0
- package/dist/protocol/packs/reader.mjs +414 -0
- package/dist/protocol/packs/rev.d.mts +32 -0
- package/dist/protocol/packs/rev.mjs +99 -0
- package/dist/protocol/packs/step.d.mts +10 -0
- package/dist/protocol/packs/step.mjs +12 -0
- package/dist/protocol/packs/write-error.d.mts +12 -0
- package/dist/protocol/packs/write-error.mjs +27 -0
- package/dist/protocol/packs/writer.d.mts +157 -0
- package/dist/protocol/packs/writer.mjs +353 -0
- package/dist/protocol/wire/advertisement.d.mts +72 -0
- package/dist/protocol/wire/advertisement.mjs +161 -0
- package/dist/protocol/wire/fetch.d.mts +155 -0
- package/dist/protocol/wire/fetch.mjs +458 -0
- package/dist/protocol/wire/lines.mjs +107 -0
- package/dist/protocol/wire/push-uploads.mjs +43 -0
- package/dist/protocol/wire/receive-pack.d.mts +71 -0
- package/dist/protocol/wire/receive-pack.mjs +157 -0
- package/dist/protocol/wire/report-status.d.mts +47 -0
- package/dist/protocol/wire/report-status.mjs +119 -0
- package/dist/protocol/wire/v2.d.mts +90 -0
- package/dist/protocol/wire/v2.mjs +185 -0
- package/dist/protocol.d.mts +31 -0
- package/dist/protocol.mjs +31 -0
- package/dist/queue/advance.mjs +1037 -0
- package/dist/queue/callers.mjs +134 -0
- package/dist/queue/calls.mjs +1154 -0
- package/dist/queue/commit.mjs +85 -0
- package/dist/queue/host.d.mts +15 -0
- package/dist/queue/host.mjs +88 -0
- package/dist/queue/ids.d.mts +5 -0
- package/dist/queue/ids.mjs +21 -0
- package/dist/queue/lanes.mjs +86 -0
- package/dist/queue/limits.mjs +99 -0
- package/dist/queue/pages.mjs +76 -0
- package/dist/queue/push-option.mjs +62 -0
- package/dist/queue/rows.mjs +206 -0
- package/dist/queue/schedule.mjs +132 -0
- package/dist/queue/search.mjs +315 -0
- package/dist/queue/state.mjs +325 -0
- package/dist/queue/steps.mjs +317 -0
- package/dist/remote-helper.d.mts +3 -0
- package/dist/remote-helper.mjs +3 -0
- package/dist/rest/api.d.mts +23 -0
- package/dist/rest/api.mjs +27 -0
- package/dist/rest/blobs.d.mts +58 -0
- package/dist/rest/blobs.mjs +41 -0
- package/dist/rest/caller.d.mts +102 -0
- package/dist/rest/caller.mjs +18 -0
- package/dist/rest/client.d.mts +18 -0
- package/dist/rest/client.mjs +587 -0
- package/dist/rest/commits.d.mts +435 -0
- package/dist/rest/commits.mjs +140 -0
- package/dist/rest/errors.d.mts +44 -0
- package/dist/rest/errors.mjs +186 -0
- package/dist/rest/events.d.mts +38 -0
- package/dist/rest/events.mjs +74 -0
- package/dist/rest/files.d.mts +179 -0
- package/dist/rest/files.mjs +92 -0
- package/dist/rest/forks.d.mts +205 -0
- package/dist/rest/forks.mjs +51 -0
- package/dist/rest/handler.d.mts +18 -0
- package/dist/rest/handler.mjs +129 -0
- package/dist/rest/handlers.d.mts +8 -0
- package/dist/rest/handlers.mjs +592 -0
- package/dist/rest/listen.d.mts +24 -0
- package/dist/rest/listen.mjs +142 -0
- package/dist/rest/me.d.mts +55 -0
- package/dist/rest/me.mjs +21 -0
- package/dist/rest/merges.d.mts +90 -0
- package/dist/rest/merges.mjs +39 -0
- package/dist/rest/paths.mjs +86 -0
- package/dist/rest/queue.d.mts +486 -0
- package/dist/rest/queue.mjs +228 -0
- package/dist/rest/refs.d.mts +232 -0
- package/dist/rest/refs.mjs +86 -0
- package/dist/rest/repos.d.mts +223 -0
- package/dist/rest/repos.mjs +93 -0
- package/dist/rest/tags.d.mts +153 -0
- package/dist/rest/tags.mjs +72 -0
- package/dist/rest/tokens.d.mts +297 -0
- package/dist/rest/tokens.mjs +88 -0
- package/dist/rest/topics.d.mts +257 -0
- package/dist/rest/topics.mjs +116 -0
- package/dist/rest/trees.d.mts +158 -0
- package/dist/rest/trees.mjs +118 -0
- package/dist/rest/wire.mjs +57 -0
- package/dist/rest/work.d.mts +107 -0
- package/dist/rest/work.mjs +77 -0
- package/dist/rest.d.mts +8 -0
- package/dist/rest.mjs +5 -0
- package/dist/server/extension.d.mts +17 -0
- package/dist/server/extension.mjs +93 -0
- package/dist/server/lifecycle.d.mts +3 -0
- package/dist/server/lifecycle.mjs +89 -0
- package/dist/server/routes.d.mts +28 -0
- package/dist/server/routes.mjs +60 -0
- package/dist/server/server.d.mts +8 -0
- package/dist/server/server.mjs +615 -0
- package/dist/signin/codes.mjs +47 -0
- package/dist/signin/context.d.mts +9 -0
- package/dist/signin/context.mjs +121 -0
- package/dist/signin/device.mjs +122 -0
- package/dist/signin/forms.mjs +157 -0
- package/dist/signin/grants.d.mts +5 -0
- package/dist/signin/grants.mjs +257 -0
- package/dist/signin/route.mjs +68 -0
- package/dist/signin/web.mjs +125 -0
- package/dist/signin/wire.d.mts +42 -0
- package/dist/signin/wire.mjs +43 -0
- package/dist/storage/allotted.mjs +102 -0
- package/dist/storage/bits.mjs +41 -0
- package/dist/storage/budget.mjs +96 -0
- package/dist/storage/calls.d.mts +18 -0
- package/dist/storage/calls.mjs +273 -0
- package/dist/storage/clean-up.mjs +124 -0
- package/dist/storage/distinct-ids.mjs +39 -0
- package/dist/storage/ewah.mjs +97 -0
- package/dist/storage/fetch.d.mts +15 -0
- package/dist/storage/fetch.mjs +998 -0
- package/dist/storage/fsck.mjs +77 -0
- package/dist/storage/held-memo.mjs +188 -0
- package/dist/storage/index-bitmaps.d.mts +4 -0
- package/dist/storage/index-bitmaps.mjs +654 -0
- package/dist/storage/index-build.d.mts +15 -0
- package/dist/storage/index-build.mjs +1447 -0
- package/dist/storage/index-fetch.d.mts +10 -0
- package/dist/storage/index-fetch.mjs +677 -0
- package/dist/storage/index-files.mjs +232 -0
- package/dist/storage/index-graph.d.mts +3 -0
- package/dist/storage/index-graph.mjs +1049 -0
- package/dist/storage/index-layers.mjs +317 -0
- package/dist/storage/index-reach.mjs +216 -0
- package/dist/storage/index-remap.d.mts +8 -0
- package/dist/storage/index-remap.mjs +592 -0
- package/dist/storage/layout.mjs +69 -0
- package/dist/storage/lfs-pointers.d.mts +21 -0
- package/dist/storage/lfs-pointers.mjs +175 -0
- package/dist/storage/link-join.mjs +106 -0
- package/dist/storage/links.mjs +105 -0
- package/dist/storage/loose.d.mts +15 -0
- package/dist/storage/loose.mjs +121 -0
- package/dist/storage/memory-budget.d.mts +8 -0
- package/dist/storage/memory-budget.mjs +546 -0
- package/dist/storage/merge.mjs +416 -0
- package/dist/storage/object-rows.d.mts +6 -0
- package/dist/storage/object-rows.mjs +211 -0
- package/dist/storage/pack-order.d.mts +8 -0
- package/dist/storage/pack-order.mjs +781 -0
- package/dist/storage/pack-ranges.d.mts +5 -0
- package/dist/storage/pack-ranges.mjs +284 -0
- package/dist/storage/pack-reads.d.mts +11 -0
- package/dist/storage/pack-reads.mjs +1007 -0
- package/dist/storage/pack-receive.d.mts +11 -0
- package/dist/storage/pack-receive.mjs +449 -0
- package/dist/storage/packs.d.mts +56 -0
- package/dist/storage/packs.mjs +603 -0
- package/dist/storage/prune.mjs +506 -0
- package/dist/storage/push-allotment.mjs +109 -0
- package/dist/storage/push-uploads.mjs +152 -0
- package/dist/storage/pushed-commits.mjs +136 -0
- package/dist/storage/quarantine.mjs +98 -0
- package/dist/storage/raw-ids.mjs +44 -0
- package/dist/storage/ready.d.mts +19 -0
- package/dist/storage/ready.mjs +328 -0
- package/dist/storage/receive-links.mjs +297 -0
- package/dist/storage/repack-job.mjs +48 -0
- package/dist/storage/repack.d.mts +31 -0
- package/dist/storage/repack.mjs +182 -0
- package/dist/storage/roots.mjs +42 -0
- package/dist/storage/rows.d.mts +4 -0
- package/dist/storage/rows.mjs +71 -0
- package/dist/storage/send-list.d.mts +8 -0
- package/dist/storage/send-list.mjs +319 -0
- package/dist/storage/shallow.d.mts +4 -0
- package/dist/storage/shallow.mjs +128 -0
- package/dist/storage/stream-whole.mjs +236 -0
- package/dist/storage/unpack.mjs +238 -0
- package/dist/storage/visible.mjs +137 -0
- package/dist/storage/walk.d.mts +8 -0
- package/dist/storage/walk.mjs +176 -0
- package/dist/storage/wants.mjs +362 -0
- package/dist/store/call-count.d.mts +47 -0
- package/dist/store/call-count.mjs +207 -0
- package/dist/store/catalogue.d.mts +7 -0
- package/dist/store/catalogue.mjs +643 -0
- package/dist/store/closed.d.mts +21 -0
- package/dist/store/closed.mjs +34 -0
- package/dist/store/crossing.mjs +69 -0
- package/dist/store/cursor-seal.d.mts +2 -0
- package/dist/store/cursor-seal.mjs +88 -0
- package/dist/store/errors.d.mts +12 -0
- package/dist/store/errors.mjs +135 -0
- package/dist/store/git-store.mjs +75 -0
- package/dist/store/list-job.mjs +35 -0
- package/dist/store/outbox.d.mts +7 -0
- package/dist/store/outbox.mjs +297 -0
- package/dist/store/promises.d.mts +5 -0
- package/dist/store/promises.mjs +258 -0
- package/dist/store/queue-jobs.mjs +43 -0
- package/dist/store/random.mjs +28 -0
- package/dist/store/records.d.mts +4 -0
- package/dist/store/records.mjs +192 -0
- package/dist/store/ref-rows.d.mts +4 -0
- package/dist/store/ref-rows.mjs +30 -0
- package/dist/store/repo-record.mjs +100 -0
- package/dist/store/reservations.mjs +82 -0
- package/dist/store/scopes.mjs +170 -0
- package/dist/store/settle.mjs +63 -0
- package/dist/store/topic-jobs.mjs +62 -0
- package/dist/sync/bound.d.mts +7 -0
- package/dist/sync/bound.mjs +34 -0
- package/dist/sync/github.d.mts +12 -0
- package/dist/sync/github.mjs +297 -0
- package/dist/sync/import.d.mts +8 -0
- package/dist/sync/import.mjs +154 -0
- package/dist/sync/jobs.d.mts +9 -0
- package/dist/sync/jobs.mjs +83 -0
- package/dist/sync/mirror.d.mts +9 -0
- package/dist/sync/mirror.mjs +227 -0
- package/dist/sync/publish.d.mts +5 -0
- package/dist/sync/publish.mjs +117 -0
- package/dist/sync/records.mjs +73 -0
- package/dist/sync/smart-http.d.mts +8 -0
- package/dist/sync/smart-http.mjs +23 -0
- package/dist/sync/step.mjs +334 -0
- package/dist/sync/tries.mjs +126 -0
- package/dist/sync.d.mts +8 -0
- package/dist/sync.mjs +8 -0
- package/dist/topics/advance.mjs +555 -0
- package/dist/topics/calls.mjs +346 -0
- package/dist/topics/directory.mjs +107 -0
- package/dist/topics/host.d.mts +11 -0
- package/dist/topics/host.mjs +71 -0
- package/dist/topics/members.mjs +177 -0
- package/dist/topics/rows.mjs +99 -0
- package/dist/topics/topic.mjs +141 -0
- package/package.json +86 -5
|
@@ -0,0 +1,1007 @@
|
|
|
1
|
+
import { BufferError, BufferMeter } from "../protocol/bytes/buffers.mjs";
|
|
2
|
+
import { hexOf } from "../protocol/bytes/hex.mjs";
|
|
3
|
+
import { Sha1 } from "../protocol/bytes/sha1.mjs";
|
|
4
|
+
import { sha1Now } from "../protocol/bytes/sha1-hasher.mjs";
|
|
5
|
+
import { objectHeader, objectId } from "../protocol/objects/object.mjs";
|
|
6
|
+
import { DeltaError, deltaResultSize } from "../protocol/packs/delta.mjs";
|
|
7
|
+
import { readPackIndex } from "../protocol/packs/idx.mjs";
|
|
8
|
+
import { readPackReverse } from "../protocol/packs/rev.mjs";
|
|
9
|
+
import { IndexerCache, PackIndexer, fixedRoom, readEntryAt } from "../protocol/packs/indexer.mjs";
|
|
10
|
+
import { stepEffect } from "../protocol/packs/step.mjs";
|
|
11
|
+
import { PackError, packReadBytes, readEntryHeader, readPackFrom } from "../protocol/packs/reader.mjs";
|
|
12
|
+
import { callScope } from "../store/call-count.mjs";
|
|
13
|
+
import { forkIn, noCall, runIn } from "../store/crossing.mjs";
|
|
14
|
+
import { gitError } from "../store/errors.mjs";
|
|
15
|
+
import { decodePacks } from "../store/git-store.mjs";
|
|
16
|
+
import { collections, repoScope } from "../store/scopes.mjs";
|
|
17
|
+
import { bucketCall } from "./calls.mjs";
|
|
18
|
+
import { isPackId, objectCollections, packFiles } from "./layout.mjs";
|
|
19
|
+
import { eachHeldRow, gitObjectOf, rowHeaders, rowSizes } from "./object-rows.mjs";
|
|
20
|
+
import { LeavingRow, decodeHeld } from "./rows.mjs";
|
|
21
|
+
import { allotted, keptOrLeft } from "./allotted.mjs";
|
|
22
|
+
import * as Effect from "effect/Effect";
|
|
23
|
+
import * as Option from "effect/Option";
|
|
24
|
+
import * as Cause from "effect/Cause";
|
|
25
|
+
import * as Hex from "effect/encoding/Hex";
|
|
26
|
+
import * as Fiber from "effect/Fiber";
|
|
27
|
+
// src/storage/pack-reads.ts
|
|
28
|
+
/** The largest object `packs()` reads whole: a file past it is stored and sent as it is. */
|
|
29
|
+
const packObjectBytes = 16777216;
|
|
30
|
+
/**
|
|
31
|
+
* The largest file `packs()` takes, GitHub's limit: a blob sent whole, hashed as it streams and
|
|
32
|
+
* never held, and sent back as it is stored.
|
|
33
|
+
*/
|
|
34
|
+
const packFileBytes = 104857600;
|
|
35
|
+
/** How `packs()` resolves an entry, on a receive and on a read. */
|
|
36
|
+
const packIndexerLimits = {
|
|
37
|
+
objectBytes: packObjectBytes,
|
|
38
|
+
deltaBytes: packObjectBytes,
|
|
39
|
+
cacheBytes: 33554432,
|
|
40
|
+
nameBytes: 4 * packObjectBytes,
|
|
41
|
+
chainReads: 64
|
|
42
|
+
};
|
|
43
|
+
/** How large an entry's header may say it is, for reads of headers alone: a file's to `packFileBytes`. */
|
|
44
|
+
const headerLimits = {
|
|
45
|
+
...packIndexerLimits,
|
|
46
|
+
objectBytes: packFileBytes
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* What one operation's reads keep of the objects they resolve, across every pack it reads: a
|
|
50
|
+
* fetch of a repo of many packs holds no more than one of few.
|
|
51
|
+
*/
|
|
52
|
+
const readCacheBytes = 16777216;
|
|
53
|
+
/** What one read of an entry may hold besides its data: its inflater and buffers. */
|
|
54
|
+
const entryReaderBytes = 1048576;
|
|
55
|
+
/** A stored pack's neighbourhood one bucket read fetches: 1 MiB, aligned. */
|
|
56
|
+
const blockBytes = 1048576;
|
|
57
|
+
/** What a block takes as a cache counts it: its bytes and its entry's overhead. */
|
|
58
|
+
const blockHeld = (bytes) => bytes + 384;
|
|
59
|
+
/**
|
|
60
|
+
* The `leaving` rows a read takes at a time, while it still looks for objects: each is small, so a
|
|
61
|
+
* page stays far below a store's answer limit.
|
|
62
|
+
*/
|
|
63
|
+
const leavingPageRows = 1e3;
|
|
64
|
+
const lost = (message) => gitError("DATA_LOSS", message);
|
|
65
|
+
/** The whole of a file, or `undefined` when the bucket has none. */
|
|
66
|
+
const readWhole = (bucket, key, range) => bucketCall(async (signal) => {
|
|
67
|
+
const body = await bucket.read(key, range, { signal });
|
|
68
|
+
return body === void 0 ? void 0 : new Uint8Array(await new Response(body).arrayBuffer());
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* Blocks kept by key, each counted with `blockHeld`, the least recently used let go first: the one
|
|
72
|
+
* rule `PackBlocks` keeps them by, and its forecast replays.
|
|
73
|
+
*/
|
|
74
|
+
var KeptBlocks = class {
|
|
75
|
+
#kept = /* @__PURE__ */ new Map();
|
|
76
|
+
held = 0;
|
|
77
|
+
/** The block at `key`, made the most recent, or `undefined`. */
|
|
78
|
+
get(key) {
|
|
79
|
+
const kept = this.#kept.get(key);
|
|
80
|
+
if (kept === void 0) return void 0;
|
|
81
|
+
this.#kept.delete(key);
|
|
82
|
+
this.#kept.set(key, kept);
|
|
83
|
+
return kept.block;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `block` at `key`, the most recent. One already there, as two reads of one block that both
|
|
87
|
+
* missed leave it, is let go first, so `held` is always the sum of the blocks kept.
|
|
88
|
+
*/
|
|
89
|
+
add(key, block, length) {
|
|
90
|
+
const bytes = blockHeld(length);
|
|
91
|
+
const displaced = this.#kept.get(key);
|
|
92
|
+
if (displaced !== void 0) {
|
|
93
|
+
this.#kept.delete(key);
|
|
94
|
+
this.held -= displaced.bytes;
|
|
95
|
+
}
|
|
96
|
+
this.#kept.set(key, {
|
|
97
|
+
block,
|
|
98
|
+
bytes
|
|
99
|
+
});
|
|
100
|
+
this.held += bytes;
|
|
101
|
+
}
|
|
102
|
+
evictTo(bytes) {
|
|
103
|
+
for (const [key, each] of this.#kept) {
|
|
104
|
+
if (this.held <= bytes) break;
|
|
105
|
+
this.#kept.delete(key);
|
|
106
|
+
this.held -= each.bytes;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
/** A block's key, by its pack and the offset it starts at. */
|
|
111
|
+
const blockKey = (pack, start) => `${pack.id}@${start}`;
|
|
112
|
+
/** The length of the block at `start`: `blockBytes`, or less at the pack's end. */
|
|
113
|
+
const blockLength = (pack, start) => Math.min(blockBytes, pack.bytes - start);
|
|
114
|
+
/**
|
|
115
|
+
* A stored pack's bytes, a neighbourhood at a time: each read of `blockBytes` from the bucket
|
|
116
|
+
* kept for the operation, so an entry and the bases near it cost one read. Missing or short bytes
|
|
117
|
+
* are `DATA_LOSS`.
|
|
118
|
+
*/
|
|
119
|
+
var PackBlocks = class {
|
|
120
|
+
#bucket;
|
|
121
|
+
#room;
|
|
122
|
+
#kept = new KeptBlocks();
|
|
123
|
+
/** `room`: what it may keep, each block counted with `blockHeld`. */
|
|
124
|
+
constructor(bucket, room) {
|
|
125
|
+
this.#bucket = bucket;
|
|
126
|
+
this.#room = room;
|
|
127
|
+
room.watch((bytes) => this.#kept.evictTo(bytes));
|
|
128
|
+
}
|
|
129
|
+
block = (pack, start) => Effect.gen({ self: this }, function* () {
|
|
130
|
+
const key = blockKey(pack, start);
|
|
131
|
+
const kept = this.#kept.get(key);
|
|
132
|
+
if (kept !== void 0) return kept;
|
|
133
|
+
const length = blockLength(pack, start);
|
|
134
|
+
const bytes = yield* readWhole(this.#bucket, packFiles(pack.id).pack, {
|
|
135
|
+
offset: start,
|
|
136
|
+
length
|
|
137
|
+
});
|
|
138
|
+
if (bytes?.byteLength !== length) return yield* Effect.fail(lost(`Pack ${pack.id} is missing its bytes from ${start}`));
|
|
139
|
+
this.#kept.add(key, bytes, length);
|
|
140
|
+
const over = this.#kept.held - this.#room.bytes;
|
|
141
|
+
if (over <= 0 || this.#room.grow(over)) return bytes;
|
|
142
|
+
this.#kept.evictTo(this.#room.bytes);
|
|
143
|
+
return bytes;
|
|
144
|
+
});
|
|
145
|
+
/**
|
|
146
|
+
* The bucket gets reading each of `entries`' bytes in turn would take, with no I/O: their blocks
|
|
147
|
+
* replayed through `KeptBlocks`, in a room left at its floor, which a shrink may leave it at any
|
|
148
|
+
* time and no grow is sure to pass. Blocks this reader keeps now aren't counted as kept.
|
|
149
|
+
*/
|
|
150
|
+
gets(entries) {
|
|
151
|
+
const kept = new KeptBlocks();
|
|
152
|
+
const floor = this.#room.floor;
|
|
153
|
+
let gets = 0;
|
|
154
|
+
for (const { pack, offset, bytes } of entries) for (let start = offset - offset % blockBytes; start < offset + bytes; start += blockBytes) {
|
|
155
|
+
const key = blockKey(pack, start);
|
|
156
|
+
if (kept.get(key) !== void 0) continue;
|
|
157
|
+
gets += 1;
|
|
158
|
+
kept.add(key, true, blockLength(pack, start));
|
|
159
|
+
if (kept.held > floor) kept.evictTo(floor);
|
|
160
|
+
}
|
|
161
|
+
return gets;
|
|
162
|
+
}
|
|
163
|
+
/** The pack's bytes from `offset` on, a reader's piece at a time. */
|
|
164
|
+
sourceAt(pack, offset) {
|
|
165
|
+
let next = offset;
|
|
166
|
+
return { read: Effect.gen({ self: this }, function* () {
|
|
167
|
+
if (next >= pack.bytes) return void 0;
|
|
168
|
+
const start = next - next % blockBytes;
|
|
169
|
+
const block = yield* this.block(pack, start);
|
|
170
|
+
const from = next - start;
|
|
171
|
+
const piece = block.subarray(from, Math.min(block.byteLength, from + packReadBytes));
|
|
172
|
+
next += piece.byteLength;
|
|
173
|
+
return piece;
|
|
174
|
+
}) };
|
|
175
|
+
}
|
|
176
|
+
/** Up to `headerBytesMost` bytes of the pack from `offset`, across a neighbourhood's end. */
|
|
177
|
+
headAt = (pack, offset) => Effect.gen({ self: this }, function* () {
|
|
178
|
+
const length = Math.min(64, pack.bytes - offset);
|
|
179
|
+
const head = new Uint8Array(length);
|
|
180
|
+
for (let at = 0; at < length;) {
|
|
181
|
+
const start = offset + at - (offset + at) % blockBytes;
|
|
182
|
+
const piece = (yield* this.block(pack, start)).subarray(offset + at - start, offset + length - start);
|
|
183
|
+
head.set(piece, at);
|
|
184
|
+
at += piece.byteLength;
|
|
185
|
+
}
|
|
186
|
+
return head;
|
|
187
|
+
});
|
|
188
|
+
/**
|
|
189
|
+
* The entry at `offset`, read whole, `before` run on its header before its data is held; a
|
|
190
|
+
* stored pack that won't read is `DATA_LOSS`.
|
|
191
|
+
*/
|
|
192
|
+
entryAt = (pack, offset, before) => readEntryAt(this.sourceAt(pack, offset), offset, packIndexerLimits, new BufferMeter(entryReaderBytes), before).pipe(Effect.mapError((error) => error instanceof PackError || error instanceof BufferError ? lost(`Pack ${pack.id} is unreadable at ${offset}: ${error.message}`) : error));
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* The `.idx` and `.rev` of each pack a server has read, across every repo, by the pack's ID: a
|
|
196
|
+
* pack's files never change, so one is checked once, its trailer against the index's and the
|
|
197
|
+
* reverse index against both, and kept until the cache is full.
|
|
198
|
+
*/
|
|
199
|
+
var PackIndexes = class {
|
|
200
|
+
#kept = /* @__PURE__ */ new Map();
|
|
201
|
+
#room;
|
|
202
|
+
#held = 0;
|
|
203
|
+
/**
|
|
204
|
+
* `room`: what it keeps of the `.idx` and `.rev` it reads, across every repo, each pack's
|
|
205
|
+
* counted with `cacheEntryBytes`. A room of 0 that never grows keeps none.
|
|
206
|
+
*/
|
|
207
|
+
constructor(room) {
|
|
208
|
+
this.#room = room;
|
|
209
|
+
room.watch((bytes) => this.#evictTo(bytes));
|
|
210
|
+
}
|
|
211
|
+
load = (bucket, listed) => Effect.gen({ self: this }, function* () {
|
|
212
|
+
const { id } = listed;
|
|
213
|
+
if (!isPackId(id)) return yield* Effect.fail(lost(`The pack row '${id}' doesn't name a pack`));
|
|
214
|
+
const pack = {
|
|
215
|
+
id,
|
|
216
|
+
bytes: listed.bytes
|
|
217
|
+
};
|
|
218
|
+
const kept = this.#kept.get(id);
|
|
219
|
+
if (kept !== void 0) {
|
|
220
|
+
this.#kept.delete(id);
|
|
221
|
+
this.#kept.set(id, kept);
|
|
222
|
+
return {
|
|
223
|
+
pack,
|
|
224
|
+
index: kept.index,
|
|
225
|
+
reverse: kept.reverse
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
const files = packFiles(id);
|
|
229
|
+
const bytes = yield* readWhole(bucket, files.idx);
|
|
230
|
+
if (bytes === void 0) return yield* Effect.fail(lost(`Pack ${id} has no index`));
|
|
231
|
+
const index = yield* readPackIndex(bytes).pipe(Effect.mapError((error) => lost(`Pack ${id}'s index is unreadable: ${error.message}`)));
|
|
232
|
+
if (index.count !== listed.objects) return yield* Effect.fail(lost(`Pack ${id}'s index lists ${index.count} objects; its row, ${listed.objects}`));
|
|
233
|
+
const trailer = yield* readWhole(bucket, files.pack, {
|
|
234
|
+
offset: listed.bytes - 20,
|
|
235
|
+
length: 20
|
|
236
|
+
});
|
|
237
|
+
if (trailer === void 0 || Hex.encode(trailer) !== index.packChecksum) return yield* Effect.fail(lost(`Pack ${id}'s bytes aren't those its index lists`));
|
|
238
|
+
const reversed = yield* readWhole(bucket, files.rev);
|
|
239
|
+
if (reversed === void 0) return yield* Effect.fail(lost(`Pack ${id} has no reverse index`));
|
|
240
|
+
const reverse = yield* readPackReverse(reversed, index).pipe(Effect.mapError((error) => lost(`Pack ${id}'s reverse index is unreadable: ${error.message}`)));
|
|
241
|
+
const held = 384 + bytes.byteLength + reversed.byteLength;
|
|
242
|
+
this.#remember(id, {
|
|
243
|
+
index,
|
|
244
|
+
reverse,
|
|
245
|
+
bytes: held
|
|
246
|
+
});
|
|
247
|
+
return {
|
|
248
|
+
pack,
|
|
249
|
+
index,
|
|
250
|
+
reverse
|
|
251
|
+
};
|
|
252
|
+
});
|
|
253
|
+
/**
|
|
254
|
+
* `kept` at `id`, the most recent. One already there, as two loads of one pack that both missed
|
|
255
|
+
* leave it, is let go first, so `#held` is always the sum of the indexes kept: a second load
|
|
256
|
+
* costs its reads, never a charge that outlives its entry.
|
|
257
|
+
*/
|
|
258
|
+
#remember(id, kept) {
|
|
259
|
+
const displaced = this.#kept.get(id);
|
|
260
|
+
if (displaced !== void 0) {
|
|
261
|
+
this.#kept.delete(id);
|
|
262
|
+
this.#held -= displaced.bytes;
|
|
263
|
+
}
|
|
264
|
+
this.#kept.set(id, kept);
|
|
265
|
+
this.#held += kept.bytes;
|
|
266
|
+
const over = this.#held - this.#room.bytes;
|
|
267
|
+
if (over > 0 && !this.#room.grow(over)) this.#evictTo(this.#room.bytes);
|
|
268
|
+
}
|
|
269
|
+
#evictTo(bytes) {
|
|
270
|
+
for (const [each, kept] of this.#kept) {
|
|
271
|
+
if (this.#held <= bytes) break;
|
|
272
|
+
this.#kept.delete(each);
|
|
273
|
+
this.#held -= kept.bytes;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Where the entry at `offset` ends: the next entry's offset, by the pack's `.rev`, or the trailer's
|
|
279
|
+
* for its last; `undefined` when no entry starts there.
|
|
280
|
+
*/
|
|
281
|
+
const entryEnd = (indexed, offset) => {
|
|
282
|
+
const { index, reverse, pack } = indexed;
|
|
283
|
+
const offsetOf = (at) => index.offsetAt(reverse.rankAt(at));
|
|
284
|
+
let low = 0;
|
|
285
|
+
let high = reverse.count;
|
|
286
|
+
while (low < high) {
|
|
287
|
+
const middle = low + high >>> 1;
|
|
288
|
+
const at = offsetOf(middle);
|
|
289
|
+
if (at === offset) return middle + 1 < reverse.count ? offsetOf(middle + 1) : pack.bytes - 20;
|
|
290
|
+
if (at < offset) low = middle + 1;
|
|
291
|
+
else high = middle;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
const delta = (base) => ({
|
|
295
|
+
kind: "delta",
|
|
296
|
+
base
|
|
297
|
+
});
|
|
298
|
+
/** Each pack's entries in the order of their offsets, so its neighbourhoods are read once. */
|
|
299
|
+
const byPlace = (where) => [...where].sort(([, a], [, b]) => a.indexed.pack.id === b.indexed.pack.id ? a.offset - b.offset : a.indexed.pack.id < b.indexed.pack.id ? -1 : 1);
|
|
300
|
+
/** The most bytes an object may hold for its hash check to run at once, not as a promise. */
|
|
301
|
+
const hashedNowMost = 65536;
|
|
302
|
+
/** The most bytes `objects` checks at once in a row, about 1 MiB, before it yields the thread. */
|
|
303
|
+
const hashedRunMost = 1048576;
|
|
304
|
+
/**
|
|
305
|
+
* A turn of the event loop, a macrotask, so the isolate's other requests, whose I/O comes back as
|
|
306
|
+
* macrotasks, run before this one goes on. `Effect.yieldNow`, and `Effect.sleep(0)`, which is it,
|
|
307
|
+
* let only other fibers run, and `Effect.sleep(1)` would wait a millisecond for each.
|
|
308
|
+
*/
|
|
309
|
+
const aTurn = Effect.promise(() => new Promise((resolve) => {
|
|
310
|
+
setTimeout(resolve, 0);
|
|
311
|
+
}));
|
|
312
|
+
/** Why an entry that didn't resolve holds no object to check. */
|
|
313
|
+
const unresolvedEntry = (pack, oid, resolved) => resolved.why === "too big" ? gitError("RESOURCE_EXHAUSTED", `Object ${oid} is past the ${packObjectBytes} bytes this server reads whole`, { context: { reason: "object-too-large" } }) : lost(`Object ${oid} in pack ${pack.id} won't resolve: ${resolved.why}`);
|
|
314
|
+
/**
|
|
315
|
+
* `bytes`, copied out of what resolved them, checked against `oid` at once by `sha1Now`: the
|
|
316
|
+
* object, or why it isn't the one the index lists.
|
|
317
|
+
*/
|
|
318
|
+
const checkedNow = (pack, oid, type, bytes) => {
|
|
319
|
+
const hashed = hexOf(sha1Now([objectHeader(type, bytes.byteLength), bytes]));
|
|
320
|
+
if (hashed !== oid) return lost(`Object ${oid} in pack ${pack.id} hashes to ${hashed}`);
|
|
321
|
+
return {
|
|
322
|
+
oid,
|
|
323
|
+
type,
|
|
324
|
+
bytes
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* An object resolved from a stored pack, hashed again against the ID its index lists: at once
|
|
329
|
+
* below `hashedNowMost`, through `objectId` from it up.
|
|
330
|
+
*/
|
|
331
|
+
const checkedObject = Effect.fnUntraced(function* (pack, oid, resolved) {
|
|
332
|
+
if (resolved.kind !== "resolved") return yield* Effect.fail(unresolvedEntry(pack, oid, resolved));
|
|
333
|
+
const { kind: type } = resolved.object;
|
|
334
|
+
const bytes = new Uint8Array(resolved.object.bytes);
|
|
335
|
+
if (bytes.byteLength < 65536) {
|
|
336
|
+
const checked = checkedNow(pack, oid, type, bytes);
|
|
337
|
+
return "code" in checked ? yield* Effect.fail(checked) : checked;
|
|
338
|
+
}
|
|
339
|
+
const hashed = yield* objectId({
|
|
340
|
+
type,
|
|
341
|
+
bytes
|
|
342
|
+
});
|
|
343
|
+
if (hashed !== oid) return yield* Effect.fail(lost(`Object ${oid} in pack ${pack.id} hashes to ${hashed}`));
|
|
344
|
+
return {
|
|
345
|
+
oid,
|
|
346
|
+
type,
|
|
347
|
+
bytes
|
|
348
|
+
};
|
|
349
|
+
});
|
|
350
|
+
/**
|
|
351
|
+
* Objects of stored packs, each resolved whole from its offset and hashed again against its ID:
|
|
352
|
+
* one indexer for each pack, and one cache for them all. An indexer holds the pack's index only
|
|
353
|
+
* while a resolve of it runs, so it keeps no `.idx` past its read: a reader keeps its listed
|
|
354
|
+
* packs' indexes itself, and a pack it doesn't list is each read's alone.
|
|
355
|
+
*/
|
|
356
|
+
const packObjects = (blocks, room, outside) => {
|
|
357
|
+
const indexers = /* @__PURE__ */ new Map();
|
|
358
|
+
const cache = new IndexerCache(room);
|
|
359
|
+
const indexingOf = (indexed) => {
|
|
360
|
+
const kept = indexers.get(indexed.pack.id);
|
|
361
|
+
if (kept !== void 0) return kept;
|
|
362
|
+
const { pack } = indexed;
|
|
363
|
+
const made = {
|
|
364
|
+
using: void 0,
|
|
365
|
+
resolving: 0,
|
|
366
|
+
indexer: new PackIndexer({
|
|
367
|
+
entryAt: (offset, before) => blocks.entryAt(pack, offset, before),
|
|
368
|
+
offsetOf: (oid) => made.using?.index.find(oid)?.offset,
|
|
369
|
+
...outside && { allot: outside }
|
|
370
|
+
}, packIndexerLimits, cache)
|
|
371
|
+
};
|
|
372
|
+
indexers.set(pack.id, made);
|
|
373
|
+
return made;
|
|
374
|
+
};
|
|
375
|
+
/** `indexed`'s index lent to its indexer while `resolve` runs, and dropped when the last ends. */
|
|
376
|
+
const lent = (indexing, indexed, resolve) => Effect.acquireUseRelease(Effect.sync(() => {
|
|
377
|
+
indexing.using = indexed;
|
|
378
|
+
indexing.resolving += 1;
|
|
379
|
+
}), () => resolve, () => Effect.sync(() => {
|
|
380
|
+
indexing.resolving -= 1;
|
|
381
|
+
if (indexing.resolving === 0) indexing.using = void 0;
|
|
382
|
+
}));
|
|
383
|
+
/** What the entry at `offset` resolves to, reading its chain as it needs. */
|
|
384
|
+
const resolving = (oid, indexed, offset) => {
|
|
385
|
+
const indexing = indexingOf(indexed);
|
|
386
|
+
return lent(indexing, indexed, stepEffect(indexing.indexer.resolve(offset))).pipe(Effect.catchIf((error) => error instanceof DeltaError, (error) => Effect.fail(lost(`Object ${oid} in pack ${indexed.pack.id} won't resolve: ${error.message}`))));
|
|
387
|
+
};
|
|
388
|
+
const at = Effect.fnUntraced(function* (oid, indexed, offset) {
|
|
389
|
+
return yield* checkedObject(indexed.pack, oid, yield* resolving(oid, indexed, offset));
|
|
390
|
+
});
|
|
391
|
+
/**
|
|
392
|
+
* What the entry at `offset` resolves to at once, from its pack's indexer's cache, with nothing
|
|
393
|
+
* read; `undefined` when `resolving` must read it.
|
|
394
|
+
*/
|
|
395
|
+
const recalled = (indexed, offset) => indexingOf(indexed).indexer.recalled(offset);
|
|
396
|
+
/** Lets go of the cache and each pack's indexer. */
|
|
397
|
+
const clear = () => {
|
|
398
|
+
indexers.clear();
|
|
399
|
+
cache.clear();
|
|
400
|
+
};
|
|
401
|
+
return Object.assign(at, {
|
|
402
|
+
clear,
|
|
403
|
+
recalled,
|
|
404
|
+
resolving
|
|
405
|
+
});
|
|
406
|
+
};
|
|
407
|
+
/**
|
|
408
|
+
* A whole entry's object as a stream, which reads nothing until its first pull: then its pack's
|
|
409
|
+
* neighbourhoods, through `blocks`, are inflated a piece at a time and each piece handed on once
|
|
410
|
+
* the reader asks, hashed as it goes. The last piece waits for the hash, so a mismatch, or an
|
|
411
|
+
* entry that won't read, errors the stream with `DATA_LOSS` before its last byte, and a REST body
|
|
412
|
+
* ends short of its `content-length`. A cancel, or `signal`, interrupts the read, which frees its
|
|
413
|
+
* inflater. It holds the blocks kept, the inflater and two pieces of `packReadBytes`.
|
|
414
|
+
*/
|
|
415
|
+
const entryStream = (blocks, at, signal, count) => {
|
|
416
|
+
let controller;
|
|
417
|
+
let fiber;
|
|
418
|
+
let pulled;
|
|
419
|
+
let wake;
|
|
420
|
+
let done = false;
|
|
421
|
+
const demand = Effect.callback((resume) => {
|
|
422
|
+
if (pulled !== void 0) return resume(Effect.void);
|
|
423
|
+
wake = () => resume(Effect.void);
|
|
424
|
+
return Effect.sync(() => {
|
|
425
|
+
wake = void 0;
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
const hand = (bytes) => Effect.gen(function* () {
|
|
429
|
+
yield* demand;
|
|
430
|
+
const answer = pulled;
|
|
431
|
+
pulled = void 0;
|
|
432
|
+
if (!done) controller?.enqueue(bytes);
|
|
433
|
+
answer?.();
|
|
434
|
+
});
|
|
435
|
+
const read = Effect.gen(function* () {
|
|
436
|
+
const sha = new Sha1();
|
|
437
|
+
sha.update(objectHeader(at.type, at.size));
|
|
438
|
+
let last;
|
|
439
|
+
yield* readPackFrom(blocks.sourceAt(at.pack, at.offset), {
|
|
440
|
+
write: () => Effect.void,
|
|
441
|
+
digest: Effect.succeed(/* @__PURE__ */ new Uint8Array(20))
|
|
442
|
+
}, {
|
|
443
|
+
begin: () => Effect.void,
|
|
444
|
+
entry: () => Effect.void,
|
|
445
|
+
data: (bytes) => Effect.gen(function* () {
|
|
446
|
+
sha.update(bytes);
|
|
447
|
+
if (last !== void 0) yield* hand(last);
|
|
448
|
+
last = bytes.slice();
|
|
449
|
+
}),
|
|
450
|
+
entryEnd: () => Effect.succeed("pause")
|
|
451
|
+
}, headerLimits, new BufferMeter(entryReaderBytes), {
|
|
452
|
+
version: 2,
|
|
453
|
+
count: 2,
|
|
454
|
+
index: 0,
|
|
455
|
+
offset: at.offset
|
|
456
|
+
}).pipe(Effect.mapError((error) => "code" in error ? error : lost(`Pack ${at.pack.id} is unreadable at ${at.offset}: ${error.message}`)));
|
|
457
|
+
const hashed = Hex.encode(sha.digest());
|
|
458
|
+
if (hashed !== at.oid) return yield* Effect.fail(lost(`Object ${at.oid} in pack ${at.pack.id} hashes to ${hashed}`));
|
|
459
|
+
if (last !== void 0) yield* hand(last);
|
|
460
|
+
});
|
|
461
|
+
/** Ends the stream once, erring it with `erred`, and the fiber reading it. */
|
|
462
|
+
const stop = (erred) => {
|
|
463
|
+
if (done) return;
|
|
464
|
+
done = true;
|
|
465
|
+
pulled?.();
|
|
466
|
+
erred();
|
|
467
|
+
if (fiber !== void 0) forkIn(Fiber.interrupt(fiber), noCall);
|
|
468
|
+
};
|
|
469
|
+
const aborted = () => stop(() => controller?.error(signal?.reason));
|
|
470
|
+
const start = () => {
|
|
471
|
+
if (signal?.aborted === true) return aborted();
|
|
472
|
+
signal?.addEventListener("abort", aborted, { once: true });
|
|
473
|
+
fiber = forkIn(read.pipe(Effect.tap(() => Effect.sync(() => {
|
|
474
|
+
if (!done) controller?.close();
|
|
475
|
+
done = true;
|
|
476
|
+
})), Effect.tapCause((cause) => Effect.sync(() => stop(() => controller?.error(Cause.squash(cause))))), Effect.ensuring(Effect.sync(() => signal?.removeEventListener("abort", aborted)))), count);
|
|
477
|
+
};
|
|
478
|
+
return new ReadableStream({
|
|
479
|
+
start: (each) => {
|
|
480
|
+
controller = each;
|
|
481
|
+
if (signal?.aborted === true) aborted();
|
|
482
|
+
},
|
|
483
|
+
pull: () => new Promise((resolve) => {
|
|
484
|
+
if (done) return resolve();
|
|
485
|
+
pulled = resolve;
|
|
486
|
+
if (fiber === void 0) start();
|
|
487
|
+
const waking = wake;
|
|
488
|
+
wake = void 0;
|
|
489
|
+
waking?.();
|
|
490
|
+
}),
|
|
491
|
+
cancel: async () => {
|
|
492
|
+
done = true;
|
|
493
|
+
pulled?.();
|
|
494
|
+
if (fiber !== void 0) await runIn(Fiber.interrupt(fiber), noCall);
|
|
495
|
+
}
|
|
496
|
+
}, { highWaterMark: 0 });
|
|
497
|
+
};
|
|
498
|
+
/**
|
|
499
|
+
* A reader's memory outside any budget: the read cache and every block it may keep, fixed. For
|
|
500
|
+
* maintenance, whose Durable Object runs one step at a time in its own isolate.
|
|
501
|
+
*/
|
|
502
|
+
const fixedReaderMemory = () => ({
|
|
503
|
+
cache: fixedRoom(readCacheBytes),
|
|
504
|
+
blocks: fixedRoom(8 * blockHeld(blockBytes)),
|
|
505
|
+
index: () => Effect.void,
|
|
506
|
+
outside: () => void 0
|
|
507
|
+
});
|
|
508
|
+
/**
|
|
509
|
+
* What a pack's `.idx` and `.rev` take, by its objects, as an index read holds them: the `.idx`'s
|
|
510
|
+
* header, fan-out and trailer, its ID, CRC and offset for each object, and a large offset for each
|
|
511
|
+
* past 2 GiB; the `.rev`'s header, trailer and a position for each; and their entry's overhead.
|
|
512
|
+
*/
|
|
513
|
+
const indexBytes = (pack) => {
|
|
514
|
+
const n = pack.objects;
|
|
515
|
+
const large = pack.bytes > 2 ** 31 ? 8 * n : 0;
|
|
516
|
+
return 1072 + 28 * n + large + 52 + 4 * n + 384;
|
|
517
|
+
};
|
|
518
|
+
/**
|
|
519
|
+
* One operation's reads of a repo's objects under `packs()`: its rows first, a small push's,
|
|
520
|
+
* then each pack its list names, by the pack's `.idx`. An object is resolved from the pack's
|
|
521
|
+
* neighbourhoods the operation keeps, each delta's base from the same pack, and hashed again
|
|
522
|
+
* against its ID.
|
|
523
|
+
*/
|
|
524
|
+
const packReader = (input) => {
|
|
525
|
+
const { store, bucket, indexes, listed, memory } = input;
|
|
526
|
+
const blocks = new PackBlocks(bucket, memory.blocks);
|
|
527
|
+
const { listedOnly } = input;
|
|
528
|
+
const rows = listedOnly === true ? () => Effect.void : eachHeldRow(store, listed);
|
|
529
|
+
const rowsSized = listedOnly === true ? () => Effect.succeed(/* @__PURE__ */ new Map()) : rowSizes(store, listed);
|
|
530
|
+
const rowsHeaders = listedOnly === true ? () => Effect.succeed(/* @__PURE__ */ new Map()) : rowHeaders(store, listed);
|
|
531
|
+
const wholeAt = packObjects(blocks, memory.cache, memory.outside);
|
|
532
|
+
const named = new Set(listed.packs.map((pack) => pack.id));
|
|
533
|
+
const kept = /* @__PURE__ */ new Map();
|
|
534
|
+
const charged = /* @__PURE__ */ new Set();
|
|
535
|
+
const unnamed = (pack) => !named.has(pack.id);
|
|
536
|
+
/** The packs the repo lists now that `listed` didn't, such as a merge's that folded rows. */
|
|
537
|
+
const listedSince = Effect.fnUntraced(function* () {
|
|
538
|
+
const snapshot = yield* store.read({
|
|
539
|
+
scope: repoScope(listed.repo),
|
|
540
|
+
reads: [{ collection: collections.packs }]
|
|
541
|
+
});
|
|
542
|
+
return (yield* decodePacks(snapshot.results[0] ?? [])).filter(unnamed);
|
|
543
|
+
});
|
|
544
|
+
/**
|
|
545
|
+
* A page of the packs the repo's delete let go of, after `after`: a merge that folded rows this
|
|
546
|
+
* read finds gone listed their objects in its own pack, and the delete may have moved that to
|
|
547
|
+
* `leaving`, where its bytes stay until this read's time is up. A step's `leaving` pack is never
|
|
548
|
+
* read: what only it holds, a pass dropped, and a push that found it there would name an object
|
|
549
|
+
* soon gone.
|
|
550
|
+
*/
|
|
551
|
+
const leavingPage = Effect.fnUntraced(function* (after) {
|
|
552
|
+
const page = after === void 0 ? {} : { after };
|
|
553
|
+
const rows = (yield* store.read({
|
|
554
|
+
scope: repoScope(listed.repo),
|
|
555
|
+
reads: [{
|
|
556
|
+
collection: objectCollections.leaving,
|
|
557
|
+
limit: leavingPageRows,
|
|
558
|
+
...page
|
|
559
|
+
}]
|
|
560
|
+
})).results[0] ?? [];
|
|
561
|
+
return {
|
|
562
|
+
packs: (yield* Effect.forEach(rows, (row) => decodeHeld(LeavingRow, row))).filter(({ value }) => value.deleted === true).map(({ pack, value }) => ({
|
|
563
|
+
id: pack,
|
|
564
|
+
objects: value.objects,
|
|
565
|
+
bytes: value.bytes
|
|
566
|
+
})).filter(unnamed),
|
|
567
|
+
next: rows.length < leavingPageRows ? void 0 : rows.at(-1)?.id
|
|
568
|
+
};
|
|
569
|
+
});
|
|
570
|
+
/**
|
|
571
|
+
* Where each of `oids` is in the listed packs, by the first pack that lists it, then in those
|
|
572
|
+
* listed since, then in those the repo's delete let go of, a page at a time, for any not found:
|
|
573
|
+
* each read apart, so neither collection's rows count against the other's answer. Each listed
|
|
574
|
+
* pack's indexes it loads are kept by the pack's ID, in `loaded` when the caller gives one and in
|
|
575
|
+
* the reader's own `kept` otherwise, and read before the server's cache: a reader loads a listed
|
|
576
|
+
* pack's indexes once, however small that cache is. Either holds only what was loaded, each
|
|
577
|
+
* `IndexedPack` until the reader is released or the caller drops its map, outside the index
|
|
578
|
+
* cache: at most every listed pack's `.idx` and `.rev` at once. Each pack's are charged to the
|
|
579
|
+
* reader's allotment before its first load, and stay charged until the allotment ends.
|
|
580
|
+
* A pack `listed` doesn't name, listed since or leaving, is this call's alone, through the
|
|
581
|
+
* server's cache, so a reader holds no more than its listing names.
|
|
582
|
+
*/
|
|
583
|
+
const found = Effect.fnUntraced(function* (oids, loaded = kept, listedAlone = false) {
|
|
584
|
+
const where = /* @__PURE__ */ new Map();
|
|
585
|
+
let left = [...new Set(oids)];
|
|
586
|
+
const look = Effect.fnUntraced(function* (packs, held, going = false) {
|
|
587
|
+
for (const listedPack of packs) {
|
|
588
|
+
if (left.length === 0) break;
|
|
589
|
+
const known = held.get(listedPack.id);
|
|
590
|
+
if (known === void 0 && !charged.has(listedPack.id)) {
|
|
591
|
+
yield* memory.index(indexBytes(listedPack));
|
|
592
|
+
charged.add(listedPack.id);
|
|
593
|
+
}
|
|
594
|
+
const indexed = known === void 0 ? yield* indexes.load(bucket, listedPack).pipe(Effect.asSome, Effect.catch((error) => going && error.code === "DATA_LOSS" ? Effect.succeedNone : Effect.fail(error))) : Option.some(known);
|
|
595
|
+
if (Option.isNone(indexed)) continue;
|
|
596
|
+
held.set(listedPack.id, indexed.value);
|
|
597
|
+
left = left.filter((oid) => {
|
|
598
|
+
const object = indexed.value.index.find(oid);
|
|
599
|
+
if (object === void 0) return true;
|
|
600
|
+
where.set(oid, {
|
|
601
|
+
indexed: indexed.value,
|
|
602
|
+
offset: object.offset,
|
|
603
|
+
crc32: object.crc32
|
|
604
|
+
});
|
|
605
|
+
return false;
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
yield* look(listed.packs, loaded);
|
|
610
|
+
if (left.length === 0 || listedOnly === true || listedAlone) return where;
|
|
611
|
+
const unlisted = /* @__PURE__ */ new Map();
|
|
612
|
+
yield* look(yield* listedSince(), unlisted);
|
|
613
|
+
let after;
|
|
614
|
+
do {
|
|
615
|
+
if (left.length === 0) break;
|
|
616
|
+
const page = yield* leavingPage(after);
|
|
617
|
+
yield* look(page.packs, unlisted, true);
|
|
618
|
+
after = page.next;
|
|
619
|
+
} while (after !== void 0);
|
|
620
|
+
return where;
|
|
621
|
+
});
|
|
622
|
+
/**
|
|
623
|
+
* Where each of `oids` is, in one order for single reads and batches alike: the listed packs
|
|
624
|
+
* first, by their `.idx`, which reads no record; then the rows of those no listed pack holds,
|
|
625
|
+
* each handed to `row`; then, for what neither holds, the packs listed since and those leaving,
|
|
626
|
+
* as a merge that folded the rows after this read's listing leaves them.
|
|
627
|
+
*/
|
|
628
|
+
const located = Effect.fnUntraced(function* (oids, row) {
|
|
629
|
+
const where = yield* found(oids, kept, true);
|
|
630
|
+
const unpacked = oids.filter((oid) => !where.has(oid));
|
|
631
|
+
if (unpacked.length === 0) return where;
|
|
632
|
+
const inRows = /* @__PURE__ */ new Set();
|
|
633
|
+
yield* rows(unpacked, (object) => {
|
|
634
|
+
inRows.add(object.oid);
|
|
635
|
+
return row(object);
|
|
636
|
+
});
|
|
637
|
+
const missing = unpacked.filter((oid) => !inRows.has(oid));
|
|
638
|
+
if (missing.length > 0) for (const [oid, place] of yield* found(missing)) where.set(oid, place);
|
|
639
|
+
return where;
|
|
640
|
+
});
|
|
641
|
+
/**
|
|
642
|
+
* Each of `oids` the repo holds, read whole and handed on before the next, found as `located`
|
|
643
|
+
* finds them: the listed packs first, so a walk over a repo whose objects are all packed asks the
|
|
644
|
+
* store for no row (#647), then the rows, then the packs listed since and those leaving.
|
|
645
|
+
*/
|
|
646
|
+
const each = Effect.fnUntraced(function* (oids, take) {
|
|
647
|
+
const where = yield* located(oids, take);
|
|
648
|
+
for (const [oid, { indexed, offset }] of where) yield* take(yield* wholeAt(oid, indexed, offset));
|
|
649
|
+
});
|
|
650
|
+
/** Which of `oids` the repo holds, read whole. */
|
|
651
|
+
const held = Effect.fnUntraced(function* (oids) {
|
|
652
|
+
const objects = /* @__PURE__ */ new Map();
|
|
653
|
+
yield* each(oids, (object) => Effect.sync(() => void objects.set(object.oid, object)));
|
|
654
|
+
return objects;
|
|
655
|
+
});
|
|
656
|
+
/** Each of `entries` read whole where the index placed it, as `held` reads one it found. */
|
|
657
|
+
const heldAt = Effect.fnUntraced(function* (entries) {
|
|
658
|
+
const objects = /* @__PURE__ */ new Map();
|
|
659
|
+
for (const { oid, indexed, offset } of entries) objects.set(oid, yield* wholeAt(oid, indexed, offset));
|
|
660
|
+
return objects;
|
|
661
|
+
});
|
|
662
|
+
/**
|
|
663
|
+
* The size of the object an entry holds, from its header, or a delta's from its instructions'
|
|
664
|
+
* header, its base never read; an entry whose header won't say is resolved whole.
|
|
665
|
+
*/
|
|
666
|
+
const sizeAt = Effect.fnUntraced(function* (oid, indexed, offset) {
|
|
667
|
+
const head = yield* blocks.headAt(indexed.pack, offset);
|
|
668
|
+
const header = readEntryHeader(head, head.byteLength, offset, headerLimits);
|
|
669
|
+
if (header.kind === "entry" && header.type !== "ofs" && header.type !== "ref") return header.size;
|
|
670
|
+
if (header.kind === "entry") {
|
|
671
|
+
const read = yield* blocks.entryAt(indexed.pack, offset);
|
|
672
|
+
const size = read === "too big" ? void 0 : deltaResultSize(read.data);
|
|
673
|
+
if (size !== void 0) return size;
|
|
674
|
+
}
|
|
675
|
+
return (yield* wholeAt(oid, indexed, offset)).bytes.byteLength;
|
|
676
|
+
});
|
|
677
|
+
/**
|
|
678
|
+
* The size of each of `oids` the repo holds, none held whole past its own read: each pack's in
|
|
679
|
+
* the order of its offsets, so its neighbourhoods are read once.
|
|
680
|
+
*/
|
|
681
|
+
const sizes = Effect.fnUntraced(function* (oids) {
|
|
682
|
+
const sized = /* @__PURE__ */ new Map();
|
|
683
|
+
for (const [oid, size] of yield* rowsSized(oids)) sized.set(oid, size);
|
|
684
|
+
const where = byPlace(yield* found(oids.filter((oid) => !sized.has(oid))));
|
|
685
|
+
for (const [oid, { indexed, offset }] of where) sized.set(oid, yield* sizeAt(oid, indexed, offset));
|
|
686
|
+
return sized;
|
|
687
|
+
});
|
|
688
|
+
/**
|
|
689
|
+
* The size of each of `at`'s entries of `pack`, in its order, as `sizes` sizes them, with no
|
|
690
|
+
* look-up by ID: a fetch's send list knows each entry's place from the index (#522).
|
|
691
|
+
*/
|
|
692
|
+
const sizesAt = Effect.fnUntraced(function* (pack, at) {
|
|
693
|
+
const sized = new Float64Array(at.length);
|
|
694
|
+
for (const [slot, { oid, offset }] of at.entries()) sized[slot] = yield* sizeAt(oid, pack, offset);
|
|
695
|
+
return sized;
|
|
696
|
+
});
|
|
697
|
+
/**
|
|
698
|
+
* The type an entry holds, by headers alone: its own, or a delta's base's, followed through
|
|
699
|
+
* offset and ID bases to the first entry that isn't a delta, at most `chainReads` entries deep,
|
|
700
|
+
* the deepest a stored pack holds. An ID base is looked for in the delta's own pack first, then
|
|
701
|
+
* in the other packs' indexes, which the reader loads once, and in the rows only when no pack
|
|
702
|
+
* holds it, which ends the chain: at most one store read a chain.
|
|
703
|
+
* `known` keeps each entry's type, by pack and offset, for one `headers` call, so chains that
|
|
704
|
+
* share a base are walked once. `undefined` past the bound, or for a header that won't say or a
|
|
705
|
+
* base the repo doesn't hold.
|
|
706
|
+
*/
|
|
707
|
+
const typeAt = Effect.fnUntraced(function* (indexed, offset, known) {
|
|
708
|
+
const walked = [];
|
|
709
|
+
const answer = (type) => {
|
|
710
|
+
if (type === void 0) return type;
|
|
711
|
+
for (const step of walked) {
|
|
712
|
+
const inPack = known.get(step.pack) ?? /* @__PURE__ */ new Map();
|
|
713
|
+
inPack.set(step.offset, type);
|
|
714
|
+
known.set(step.pack, inPack);
|
|
715
|
+
}
|
|
716
|
+
return type;
|
|
717
|
+
};
|
|
718
|
+
let at = {
|
|
719
|
+
indexed,
|
|
720
|
+
offset
|
|
721
|
+
};
|
|
722
|
+
for (let depth = 0; depth < packIndexerLimits.chainReads; depth += 1) {
|
|
723
|
+
const already = known.get(at.indexed.pack.id)?.get(at.offset);
|
|
724
|
+
if (already !== void 0) return answer(already);
|
|
725
|
+
walked.push({
|
|
726
|
+
pack: at.indexed.pack.id,
|
|
727
|
+
offset: at.offset
|
|
728
|
+
});
|
|
729
|
+
const head = yield* blocks.headAt(at.indexed.pack, at.offset);
|
|
730
|
+
const header = readEntryHeader(head, head.byteLength, at.offset, headerLimits);
|
|
731
|
+
if (header.kind !== "entry") return void 0;
|
|
732
|
+
const { type, base } = header;
|
|
733
|
+
if (type !== "ofs" && type !== "ref") return answer(type);
|
|
734
|
+
if (base?.kind === "offset") {
|
|
735
|
+
at = {
|
|
736
|
+
indexed: at.indexed,
|
|
737
|
+
offset: base.offset
|
|
738
|
+
};
|
|
739
|
+
continue;
|
|
740
|
+
}
|
|
741
|
+
if (base?.kind !== "oid") return void 0;
|
|
742
|
+
const here = at.indexed.index.find(base.oid);
|
|
743
|
+
if (here !== void 0) {
|
|
744
|
+
at = {
|
|
745
|
+
indexed: at.indexed,
|
|
746
|
+
offset: here.offset
|
|
747
|
+
};
|
|
748
|
+
continue;
|
|
749
|
+
}
|
|
750
|
+
const where = (yield* found([base.oid])).get(base.oid);
|
|
751
|
+
if (where === void 0) return answer((yield* rowsHeaders([base.oid])).get(base.oid)?.type);
|
|
752
|
+
at = {
|
|
753
|
+
indexed: where.indexed,
|
|
754
|
+
offset: where.offset
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
/**
|
|
759
|
+
* The type and size of each of `oids` the repo holds, as `git cat-file --batch-check` gives
|
|
760
|
+
* them, from headers alone: rows first, then each pack's entries in the order of their offsets.
|
|
761
|
+
* A delta's size is its result's and its type its chain's, as `typeAt` follows it. An entry whose
|
|
762
|
+
* header or chain won't say is read whole.
|
|
763
|
+
*/
|
|
764
|
+
const headers = Effect.fnUntraced(function* (oids) {
|
|
765
|
+
const answer = new Map(yield* rowsHeaders(oids));
|
|
766
|
+
const where = byPlace(yield* found(oids.filter((oid) => !answer.has(oid))));
|
|
767
|
+
const known = /* @__PURE__ */ new Map();
|
|
768
|
+
for (const [oid, { indexed, offset }] of where) {
|
|
769
|
+
const type = yield* typeAt(indexed, offset, known);
|
|
770
|
+
if (type === void 0) {
|
|
771
|
+
const whole = yield* wholeAt(oid, indexed, offset);
|
|
772
|
+
answer.set(oid, {
|
|
773
|
+
type: whole.type,
|
|
774
|
+
size: whole.bytes.byteLength
|
|
775
|
+
});
|
|
776
|
+
continue;
|
|
777
|
+
}
|
|
778
|
+
answer.set(oid, {
|
|
779
|
+
type,
|
|
780
|
+
size: yield* sizeAt(oid, indexed, offset)
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
return answer;
|
|
784
|
+
});
|
|
785
|
+
/**
|
|
786
|
+
* Which of `oids` the repo holds, and where, by its rows and its packs' indexes, none read: the
|
|
787
|
+
* listed pack an index found it in, by ID, or `undefined` for a row. `loaded`, when given, keeps
|
|
788
|
+
* the packs' indexes it loads, as `found` says, for later calls given it too.
|
|
789
|
+
*/
|
|
790
|
+
const heldIn = Effect.fnUntraced(function* (oids, loaded) {
|
|
791
|
+
const there = /* @__PURE__ */ new Map();
|
|
792
|
+
for (const oid of (yield* rowsSized(oids)).keys()) there.set(oid, void 0);
|
|
793
|
+
const packed = yield* found(oids.filter((oid) => !there.has(oid)), loaded);
|
|
794
|
+
for (const [oid, { indexed }] of packed) there.set(oid, indexed.pack.id);
|
|
795
|
+
return there;
|
|
796
|
+
});
|
|
797
|
+
/** Which of `oids` the repo holds, as `heldIn` finds them. */
|
|
798
|
+
const has = (oids, loaded) => Effect.map(heldIn(oids, loaded), (there) => new Set(there.keys()));
|
|
799
|
+
/** What the entry at `offset` holds, by its header, or `undefined` for one that won't say. */
|
|
800
|
+
const holdsAt = Effect.fnUntraced(function* (indexed, offset) {
|
|
801
|
+
const head = yield* blocks.headAt(indexed.pack, offset);
|
|
802
|
+
const header = readEntryHeader(head, head.byteLength, offset, headerLimits);
|
|
803
|
+
if (header.kind !== "entry") return void 0;
|
|
804
|
+
const { type, size, base } = header;
|
|
805
|
+
if (type === "ref") return base?.kind === "oid" ? delta(base.oid) : void 0;
|
|
806
|
+
return type === "ofs" ? void 0 : {
|
|
807
|
+
kind: "whole",
|
|
808
|
+
type,
|
|
809
|
+
size
|
|
810
|
+
};
|
|
811
|
+
});
|
|
812
|
+
/**
|
|
813
|
+
* The entry each of `oids` is stored as, to copy as it is: its length by the pack's `.rev`, its
|
|
814
|
+
* CRC-32 by its `.idx`, and what it holds by its header, a whole object or a delta on a base it
|
|
815
|
+
* names by ID. An entry that won't say, or an offset delta, is left out, to be read whole.
|
|
816
|
+
*/
|
|
817
|
+
const storedOf = Effect.fnUntraced(function* (oids, loaded) {
|
|
818
|
+
const entries = /* @__PURE__ */ new Map();
|
|
819
|
+
for (const [oid, { indexed, offset, crc32 }] of byPlace(yield* found(oids, loaded))) {
|
|
820
|
+
const { pack } = indexed;
|
|
821
|
+
const end = entryEnd(indexed, offset);
|
|
822
|
+
if (end === void 0 || end <= offset) return yield* Effect.fail(lost(`Pack ${pack.id}'s reverse index has no entry at ${offset}`));
|
|
823
|
+
const holds = yield* holdsAt(indexed, offset);
|
|
824
|
+
if (holds === void 0) continue;
|
|
825
|
+
entries.set(oid, {
|
|
826
|
+
oid,
|
|
827
|
+
pack,
|
|
828
|
+
offset,
|
|
829
|
+
bytes: end - offset,
|
|
830
|
+
crc32,
|
|
831
|
+
holds
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
return entries;
|
|
835
|
+
});
|
|
836
|
+
const read = (entry, at) => {
|
|
837
|
+
const from = entry.offset + at;
|
|
838
|
+
const start = from - from % blockBytes;
|
|
839
|
+
return Effect.map(blocks.block(entry.pack, start), (block) => block.subarray(from - start, Math.min(block.byteLength, from - start + entry.bytes - at)));
|
|
840
|
+
};
|
|
841
|
+
const stored = {
|
|
842
|
+
find: storedOf,
|
|
843
|
+
read,
|
|
844
|
+
gets: (entries) => blocks.gets(entries),
|
|
845
|
+
packed: (oids) => Effect.map(found(oids, kept, true), (where) => new Set(where.keys()))
|
|
846
|
+
};
|
|
847
|
+
/**
|
|
848
|
+
* The object `oid` as `ObjectReader.read` hands it on, rows first: a whole entry past
|
|
849
|
+
* `packObjectBytes` streamed, as `entryStream` says, and any other resolved whole.
|
|
850
|
+
*/
|
|
851
|
+
const object = Effect.fnUntraced(function* (oid, signal) {
|
|
852
|
+
let row;
|
|
853
|
+
const place = (yield* located([oid], (each) => Effect.sync(() => void (row = each)))).get(oid);
|
|
854
|
+
if (row !== void 0) return gitObjectOf(row);
|
|
855
|
+
if (place === void 0) return void 0;
|
|
856
|
+
const { indexed, offset } = place;
|
|
857
|
+
const holds = yield* holdsAt(indexed, offset);
|
|
858
|
+
if (holds?.kind === "whole" && holds.size > 16777216) {
|
|
859
|
+
const { type, size } = holds;
|
|
860
|
+
const count = yield* callScope;
|
|
861
|
+
const at = {
|
|
862
|
+
oid,
|
|
863
|
+
type,
|
|
864
|
+
size,
|
|
865
|
+
pack: indexed.pack,
|
|
866
|
+
offset
|
|
867
|
+
};
|
|
868
|
+
return {
|
|
869
|
+
oid,
|
|
870
|
+
type,
|
|
871
|
+
size,
|
|
872
|
+
bytes: entryStream(blocks, at, signal, count)
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
return gitObjectOf(yield* wholeAt(oid, indexed, offset));
|
|
876
|
+
});
|
|
877
|
+
/**
|
|
878
|
+
* Each of `entries`, packed, charged to `answer` once resolved, then copied out and checked:
|
|
879
|
+
* at once below `hashedNowMost`, `hashedRunMost` bytes so in a row taking a turn.
|
|
880
|
+
*/
|
|
881
|
+
const placed = Effect.fnUntraced(function* (answer, entries, run) {
|
|
882
|
+
for (const [oid, { indexed, offset }] of entries) {
|
|
883
|
+
const resolved = wholeAt.recalled(indexed, offset) ?? (yield* wholeAt.resolving(oid, indexed, offset));
|
|
884
|
+
if (resolved.kind !== "resolved") return yield* Effect.fail(unresolvedEntry(indexed.pack, oid, resolved));
|
|
885
|
+
const size = resolved.object.bytes.byteLength;
|
|
886
|
+
let given = answer.granted(size);
|
|
887
|
+
if (Effect.isEffect(given)) {
|
|
888
|
+
given = yield* given;
|
|
889
|
+
run.at = 0;
|
|
890
|
+
}
|
|
891
|
+
if (given === "left") {
|
|
892
|
+
answer.leave(oid);
|
|
893
|
+
continue;
|
|
894
|
+
}
|
|
895
|
+
if (given !== "kept") return yield* Effect.fail(given.refused);
|
|
896
|
+
if (size >= 65536) {
|
|
897
|
+
answer.keep(yield* checkedObject(indexed.pack, oid, resolved));
|
|
898
|
+
run.at = 0;
|
|
899
|
+
continue;
|
|
900
|
+
}
|
|
901
|
+
const bytes = new Uint8Array(resolved.object.bytes);
|
|
902
|
+
const checked = checkedNow(indexed.pack, oid, resolved.object.kind, bytes);
|
|
903
|
+
if ("code" in checked) return yield* Effect.fail(checked);
|
|
904
|
+
answer.keep(checked);
|
|
905
|
+
run.at += size;
|
|
906
|
+
if (run.at >= 1048576) {
|
|
907
|
+
yield* aTurn;
|
|
908
|
+
run.at = 0;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
/**
|
|
913
|
+
* `ObjectReader.objects`: `asked[0]` read and charged first, a packed entry or a row, then the
|
|
914
|
+
* rest's rows, each charged as it's decoded, then their packed entries in the order of their
|
|
915
|
+
* offsets, each found as `located` finds it: a walk over packed objects asks the store for no
|
|
916
|
+
* row. A batch that fails lets go of every byte it was granted.
|
|
917
|
+
*/
|
|
918
|
+
const batch = Effect.fnUntraced(function* (answer, asked) {
|
|
919
|
+
const [first, ...rest] = asked;
|
|
920
|
+
if (first === void 0) return answer.read(asked);
|
|
921
|
+
const run = { at: 0 };
|
|
922
|
+
const keep = (row) => keptOrLeft(answer, row);
|
|
923
|
+
const firstPlace = (yield* located([first], keep)).get(first);
|
|
924
|
+
if (firstPlace !== void 0) yield* placed(answer, [[first, firstPlace]], run);
|
|
925
|
+
if (rest.length > 0) yield* placed(answer, byPlace(yield* located(rest, keep)), run);
|
|
926
|
+
return answer.read(asked);
|
|
927
|
+
});
|
|
928
|
+
/** `batch` over `oids`, each once, its grants let go if it fails. */
|
|
929
|
+
const objects = (oids, allotment) => allotted(allotment, (answer) => batch(answer, [...new Set(oids)]));
|
|
930
|
+
/** Those of `oids` stored as whole blobs, by their entries' headers, none of them read. */
|
|
931
|
+
const wholeBlobs = Effect.fnUntraced(function* (oids) {
|
|
932
|
+
const blobs = /* @__PURE__ */ new Set();
|
|
933
|
+
for (const [oid, { indexed, offset }] of byPlace(yield* found(oids))) {
|
|
934
|
+
const holds = yield* holdsAt(indexed, offset);
|
|
935
|
+
if (holds?.kind === "whole" && holds.type === "blob") blobs.add(oid);
|
|
936
|
+
}
|
|
937
|
+
return blobs;
|
|
938
|
+
});
|
|
939
|
+
/**
|
|
940
|
+
* `oids` in the order whose reads take the fewest blocks: the listed packs' objects by pack and
|
|
941
|
+
* offset, from their `.idx` alone with no header read, then the rest as they came (#662).
|
|
942
|
+
*/
|
|
943
|
+
const inPackOrder = Effect.fnUntraced(function* (oids) {
|
|
944
|
+
const where = yield* found(oids, kept, true);
|
|
945
|
+
return [...byPlace(where).map(([oid]) => oid), ...oids.filter((oid) => !where.has(oid))];
|
|
946
|
+
});
|
|
947
|
+
/**
|
|
948
|
+
* Lets go of what the reader holds: its read cache and the indexes it kept. Its blocks stay
|
|
949
|
+
* while a body it handed on still streams from them, and go with the reader once none does. A
|
|
950
|
+
* read after it starts again from nothing, so its caller refuses reads past it, as `GitObjects`'
|
|
951
|
+
* reader does.
|
|
952
|
+
*/
|
|
953
|
+
const release = () => {
|
|
954
|
+
wholeAt.clear();
|
|
955
|
+
kept.clear();
|
|
956
|
+
};
|
|
957
|
+
const reads = {
|
|
958
|
+
indexed: Effect.fnUntraced(function* (pack) {
|
|
959
|
+
const known = kept.get(pack.id);
|
|
960
|
+
if (known !== void 0) return known;
|
|
961
|
+
if (!charged.has(pack.id)) {
|
|
962
|
+
yield* memory.index(indexBytes(pack));
|
|
963
|
+
charged.add(pack.id);
|
|
964
|
+
}
|
|
965
|
+
const loaded = yield* indexes.load(bucket, pack);
|
|
966
|
+
kept.set(pack.id, loaded);
|
|
967
|
+
return loaded;
|
|
968
|
+
}),
|
|
969
|
+
held,
|
|
970
|
+
heldAt,
|
|
971
|
+
each,
|
|
972
|
+
has,
|
|
973
|
+
heldIn,
|
|
974
|
+
headers,
|
|
975
|
+
sizes,
|
|
976
|
+
sizesAt,
|
|
977
|
+
stored,
|
|
978
|
+
blocks,
|
|
979
|
+
object,
|
|
980
|
+
objects,
|
|
981
|
+
wholeBlobs,
|
|
982
|
+
inPackOrder,
|
|
983
|
+
release
|
|
984
|
+
};
|
|
985
|
+
return input.visible === void 0 ? reads : narrowedTo(reads, input.visible);
|
|
986
|
+
};
|
|
987
|
+
/** `reads`, each lookup by ID answering only what `visible` holds, as `PackReaderInput` says. */
|
|
988
|
+
const narrowedTo = (reads, visible) => {
|
|
989
|
+
const only = (oids) => Effect.map(visible(oids), (kept) => oids.filter((oid) => kept.has(oid)));
|
|
990
|
+
return {
|
|
991
|
+
...reads,
|
|
992
|
+
held: (oids) => Effect.flatMap(only(oids), reads.held),
|
|
993
|
+
each: (oids, take) => Effect.flatMap(only(oids), (kept) => reads.each(kept, take)),
|
|
994
|
+
has: (oids, loaded) => Effect.flatMap(only(oids), (kept) => reads.has(kept, loaded)),
|
|
995
|
+
heldIn: (oids, loaded) => Effect.flatMap(only(oids), (kept) => reads.heldIn(kept, loaded)),
|
|
996
|
+
headers: (oids) => Effect.flatMap(only(oids), reads.headers),
|
|
997
|
+
sizes: (oids) => Effect.flatMap(only(oids), reads.sizes),
|
|
998
|
+
stored: {
|
|
999
|
+
...reads.stored,
|
|
1000
|
+
find: (oids, loaded) => Effect.flatMap(only(oids), (kept) => reads.stored.find(kept, loaded))
|
|
1001
|
+
},
|
|
1002
|
+
object: (oid, signal) => Effect.flatMap(only([oid]), (kept) => kept.length === 0 ? Effect.succeed(void 0) : reads.object(oid, signal)),
|
|
1003
|
+
objects: (oids, allotment) => Effect.flatMap(only(oids), (kept) => reads.objects(kept, allotment)),
|
|
1004
|
+
wholeBlobs: (oids) => Effect.flatMap(only(oids), reads.wholeBlobs)
|
|
1005
|
+
};
|
|
1006
|
+
};
|
|
1007
|
+
export { PackBlocks, PackIndexes, blockBytes, blockHeld, fixedReaderMemory, hashedNowMost, hashedRunMost, headerLimits, indexBytes, packFileBytes, packIndexerLimits, packObjectBytes, packObjects, packReader, readCacheBytes, readWhole };
|