@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,99 @@
|
|
|
1
|
+
import { hexOf } from "../bytes/hex.mjs";
|
|
2
|
+
import { byOid, isSealed, oidBytes, refuse, sealed, writeIdx } from "./idx.mjs";
|
|
3
|
+
import { writePositions } from "./pos.mjs";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
// src/protocol/packs/rev.ts
|
|
6
|
+
/**
|
|
7
|
+
* A pack's reverse index, Git's `.rev` version 1 byte for byte, as `git index-pack --rev-index`
|
|
8
|
+
* writes it and `gitformat-pack` defines it: its `.idx`'s objects in the pack's order, so a
|
|
9
|
+
* reader walking the pack by offset goes from an entry to its object's rank by ID. Big-endian:
|
|
10
|
+
*
|
|
11
|
+
* - `RIDX`, version 1, then hash function 1, SHA-1;
|
|
12
|
+
* - for each entry in the pack's order, its object's rank in the `.idx`, 4 bytes;
|
|
13
|
+
* - the pack's own trailer, then the SHA-1 of every byte before it.
|
|
14
|
+
*/
|
|
15
|
+
const magic = [
|
|
16
|
+
82,
|
|
17
|
+
73,
|
|
18
|
+
68,
|
|
19
|
+
88
|
|
20
|
+
];
|
|
21
|
+
const version = 1;
|
|
22
|
+
const sha1Function = 1;
|
|
23
|
+
const headerBytes = 12;
|
|
24
|
+
const trailerBytes = 40;
|
|
25
|
+
/** How many bytes a `.rev` of `objects` takes. */
|
|
26
|
+
const packReverseBytes = (objects) => headerBytes + objects * 4 + trailerBytes;
|
|
27
|
+
/**
|
|
28
|
+
* The `.rev` of `sorted`, ranked by ID as their `.idx` ranks them: `ranks`, each rank in the order
|
|
29
|
+
* of its offset in the pack. Refused for two objects at one offset.
|
|
30
|
+
*/
|
|
31
|
+
const writeRev = (sorted, ranks, packChecksum) => Effect.gen(function* () {
|
|
32
|
+
const bytes = new Uint8Array(packReverseBytes(sorted.length));
|
|
33
|
+
const view = new DataView(bytes.buffer);
|
|
34
|
+
let previous = -1;
|
|
35
|
+
for (const [at, rank] of ranks.entries()) {
|
|
36
|
+
const offset = sorted[rank]?.offset ?? 0;
|
|
37
|
+
if (offset === previous) return yield* refuse("offset", `two objects are at ${offset}`);
|
|
38
|
+
view.setUint32(headerBytes + at * 4, rank);
|
|
39
|
+
previous = offset;
|
|
40
|
+
}
|
|
41
|
+
bytes.set(magic);
|
|
42
|
+
view.setUint32(4, version);
|
|
43
|
+
view.setUint32(8, sha1Function);
|
|
44
|
+
bytes.set(oidBytes(packChecksum), bytes.byteLength - trailerBytes);
|
|
45
|
+
return sealed(bytes);
|
|
46
|
+
});
|
|
47
|
+
/** A pack's `.rev` as read and checked against its `.idx`. */
|
|
48
|
+
var PackReverse = class {
|
|
49
|
+
#view;
|
|
50
|
+
/** How many objects it lists, as its `.idx` does. */
|
|
51
|
+
count;
|
|
52
|
+
constructor(bytes, count) {
|
|
53
|
+
this.#view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
54
|
+
this.count = count;
|
|
55
|
+
}
|
|
56
|
+
/** The `.idx` rank of the pack's `at`th entry, in offset order. */
|
|
57
|
+
rankAt(at) {
|
|
58
|
+
return this.#view.getUint32(headerBytes + at * 4);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* A `.rev` from its bytes, checked against `index`, the `.idx` of the same pack: its header,
|
|
63
|
+
* version, hash function and length, its own SHA-1, the same pack's trailer, and ranks that name
|
|
64
|
+
* every object once, in strictly ascending offsets, so no two objects share one.
|
|
65
|
+
*/
|
|
66
|
+
const readPackReverse = (bytes, index) => Effect.gen(function* () {
|
|
67
|
+
if (bytes.byteLength < headerBytes || magic.some((byte, at) => bytes[at] !== byte)) return yield* refuse("header", "the reverse index doesn't start as one");
|
|
68
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
69
|
+
if (view.getUint32(4) !== version || view.getUint32(8) !== sha1Function) return yield* refuse("version", `reverse index version ${view.getUint32(4)}, hash ${view.getUint32(8)} isn't read`);
|
|
70
|
+
if (bytes.byteLength !== packReverseBytes(index.count)) return yield* refuse("length", `a reverse index of ${index.count} objects isn't ${bytes.byteLength} bytes`);
|
|
71
|
+
if (!isSealed(bytes)) return yield* refuse("checksum", "the reverse index's trailer isn't its SHA-1");
|
|
72
|
+
const end = bytes.byteLength - trailerBytes;
|
|
73
|
+
const pack = hexOf(bytes.subarray(end, end + 20));
|
|
74
|
+
if (pack !== index.packChecksum) return yield* refuse("checksum", `the reverse index is of pack ${pack}, not ${index.packChecksum}`);
|
|
75
|
+
let previous = -1;
|
|
76
|
+
for (let at = 0; at < index.count; at += 1) {
|
|
77
|
+
const rank = view.getUint32(headerBytes + at * 4);
|
|
78
|
+
if (rank >= index.count) return yield* refuse("order", `rank ${rank} isn't an object's`);
|
|
79
|
+
const offset = index.offsetAt(rank);
|
|
80
|
+
if (offset <= previous) return yield* refuse("order", `offset ${offset} isn't past ${previous}`);
|
|
81
|
+
previous = offset;
|
|
82
|
+
}
|
|
83
|
+
return new PackReverse(bytes.slice(), index.count);
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* The `.idx`, `.rev` and `.pos` of a pack's `objects`, in any order, for the pack whose trailer is
|
|
87
|
+
* `packChecksum`: the first two byte for byte what Git writes for that pack. Every object the pack
|
|
88
|
+
* holds is listed, or the index isn't the pack's.
|
|
89
|
+
*/
|
|
90
|
+
const writePackIndex = (objects, packChecksum) => Effect.gen(function* () {
|
|
91
|
+
const sorted = [...objects].sort(byOid);
|
|
92
|
+
const ranks = Array.from(sorted.keys()).sort((a, b) => (sorted[a]?.offset ?? 0) - (sorted[b]?.offset ?? 0));
|
|
93
|
+
return {
|
|
94
|
+
index: yield* writeIdx(sorted, packChecksum),
|
|
95
|
+
reverse: yield* writeRev(sorted, ranks, packChecksum),
|
|
96
|
+
positions: writePositions(ranks, packChecksum)
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
export { PackReverse, packReverseBytes, readPackReverse, writePackIndex };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
/**
|
|
3
|
+
* Work's answer: its value when it's done at once, or an Effect when it has I/O to wait on. A
|
|
4
|
+
* plain value is always a success, and a failure is always an Effect, so a caller awaits only an
|
|
5
|
+
* Effect, and work done at once costs it no Effect step. `A` is never an Effect itself, nor a
|
|
6
|
+
* tagged error, which is one: `Effect.isEffect` would read it as the step to await.
|
|
7
|
+
*/
|
|
8
|
+
export type Step<A, E = never, R = never> = A | Effect.Effect<A, E, R>;
|
|
9
|
+
/** A step as an Effect, for code that stays one: its own Effect, or one that succeeds with its value. */
|
|
10
|
+
export declare const stepEffect: <A, E = never, R = never>(step: Step<A, E, R>) => Effect.Effect<A, E, R>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
// src/protocol/packs/step.ts
|
|
3
|
+
/** Whether a step is an Effect to await, rather than a value. */
|
|
4
|
+
const isEffectStep = (step) => Effect.isEffect(step);
|
|
5
|
+
/** A step as an Effect, for code that stays one: its own Effect, or one that succeeds with its value. */
|
|
6
|
+
const stepEffect = (step) => isEffectStep(step) ? step : Effect.succeed(step);
|
|
7
|
+
/**
|
|
8
|
+
* A step, then the step its value leads to: a value at once when both are, and one Effect when
|
|
9
|
+
* either is. The package's own, not exported from `@ref0/git/protocol`.
|
|
10
|
+
*/
|
|
11
|
+
const stepFlatMap = (step, then) => isEffectStep(step) ? Effect.flatMap(step, (value) => stepEffect(then(value))) : then(step);
|
|
12
|
+
export { stepEffect, stepFlatMap };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "effect/Effect";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
/** Why a pack wasn't written, named. */
|
|
4
|
+
export declare const PackWriteFault: Schema.Literals<readonly ["count", "kind", "oid", "size", "duplicate", "length", "hash", "too big", "time", "cancelled"]>;
|
|
5
|
+
export type PackWriteFault = typeof PackWriteFault.Type;
|
|
6
|
+
declare const PackWriteError_base: Schema.Class<PackWriteError, Schema.TaggedStruct<"PackWriteError", {
|
|
7
|
+
readonly fault: Schema.Literals<readonly ["count", "kind", "oid", "size", "duplicate", "length", "hash", "too big", "time", "cancelled"]>;
|
|
8
|
+
readonly message: Schema.String;
|
|
9
|
+
}>, import("effect/Cause").YieldableError>;
|
|
10
|
+
/** A pack the writer refused to write, or to go on writing, for its `fault`. */
|
|
11
|
+
export declare class PackWriteError extends PackWriteError_base {}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
// src/protocol/packs/write-error.ts
|
|
4
|
+
/** Why a pack wasn't written, named. */
|
|
5
|
+
const PackWriteFault = Schema.Literals([
|
|
6
|
+
"count",
|
|
7
|
+
"kind",
|
|
8
|
+
"oid",
|
|
9
|
+
"size",
|
|
10
|
+
"duplicate",
|
|
11
|
+
"length",
|
|
12
|
+
"hash",
|
|
13
|
+
"too big",
|
|
14
|
+
"time",
|
|
15
|
+
"cancelled"
|
|
16
|
+
]);
|
|
17
|
+
/** A pack the writer refused to write, or to go on writing, for its `fault`. */
|
|
18
|
+
var PackWriteError = class extends Schema.TaggedError()("PackWriteError", {
|
|
19
|
+
fault: PackWriteFault,
|
|
20
|
+
message: Schema.String
|
|
21
|
+
}) {};
|
|
22
|
+
/** A writing refused for `fault`. */
|
|
23
|
+
const refuseWrite = (fault, message) => Effect.fail(new PackWriteError({
|
|
24
|
+
fault,
|
|
25
|
+
message
|
|
26
|
+
}));
|
|
27
|
+
export { PackWriteError, PackWriteFault, refuseWrite };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { ObjectType } from "../../contracts/objects.mjs";
|
|
2
|
+
import { Oid } from "../../contracts/ids.mjs";
|
|
3
|
+
import { BufferError, BufferMeter } from "../bytes/buffers.mjs";
|
|
4
|
+
import { DeflateError } from "../bytes/deflate.mjs";
|
|
5
|
+
import { IndexedObject } from "./idx.mjs";
|
|
6
|
+
import { PackEnd, PackParts } from "./parts.mjs";
|
|
7
|
+
import { PackHasher } from "./reader.mjs";
|
|
8
|
+
import { PackWriteError } from "./write-error.mjs";
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
import * as Exit from "effect/Exit";
|
|
11
|
+
/**
|
|
12
|
+
* A Git pack written as it streams, never held whole: PACK version 2, its count, then each
|
|
13
|
+
* object whole, as Git's `gitformat-pack` defines an undeltified entry, its type and inflated
|
|
14
|
+
* size as a varint, then its own zlib member, and last a SHA-1 of every byte before it. No entry
|
|
15
|
+
* it writes itself is a delta, so none needs another of the pack as its base. Objects come from a source a
|
|
16
|
+
* page at a time, and each object's body a range at a time, so what the writer retains, counted
|
|
17
|
+
* by a `BufferMeter`, never grows with the pack's length, its count or its objects' sizes. An
|
|
18
|
+
* object up to `wholeObjectBytes` is read whole and deflated in one call, with nothing awaited; a
|
|
19
|
+
* larger one is deflated as it streams.
|
|
20
|
+
*
|
|
21
|
+
* Every object written whole is hashed as Git names it as it goes, and the trailer is written only
|
|
22
|
+
* once every object matched its ID and length: a pack whose source lied ends with no trailer, so
|
|
23
|
+
* no receiver takes it. Each entry's offset and CRC-32 are handed out as it ends, so a caller can
|
|
24
|
+
* write the pack's `.idx`, `.rev` and `.pos` with `writePackIndex` without reading it again. The writer
|
|
25
|
+
* never retries; a caller that tries again starts at byte zero.
|
|
26
|
+
*
|
|
27
|
+
* A source may hand an object's stored entry instead, through `copy`, as Git's pack-objects reuses
|
|
28
|
+
* one: its bytes go out as they are, its header and its zlib member or delta with them, neither
|
|
29
|
+
* inflated nor deflated, so the writer can't hash it. Checking a copied entry is the source's: it
|
|
30
|
+
* fails a read rather than hand over bytes it hasn't checked, and the trailer is never written.
|
|
31
|
+
*/
|
|
32
|
+
/** One object a pack holds: its ID, its kind and its body's length. */
|
|
33
|
+
export interface PackObject {
|
|
34
|
+
readonly oid: Oid;
|
|
35
|
+
readonly kind: ObjectType;
|
|
36
|
+
readonly size: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* An object's entry as another pack stores it, `bytes` long from its header to its member's end,
|
|
40
|
+
* copied a range at a time. A delta's base must be an object the same pack sends before it.
|
|
41
|
+
*/
|
|
42
|
+
export interface PackCopy<E, R> {
|
|
43
|
+
readonly bytes: number;
|
|
44
|
+
/**
|
|
45
|
+
* The entry's bytes from `at`: at least one, and none past `bytes`. Each is counted on the meter
|
|
46
|
+
* by its whole buffer until the next, as an object's body is.
|
|
47
|
+
*/
|
|
48
|
+
readonly read: (at: number) => Effect.Effect<Uint8Array<ArrayBuffer>, E, R>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Where a pack's objects come from: exactly `count` of them, in order, a page at a time, and each
|
|
52
|
+
* object's body a range at a time. Both are repeatable: a second write of the same source reads
|
|
53
|
+
* the same objects in the same order and the same bytes. Uniqueness is the source's: a page with
|
|
54
|
+
* an ID twice, or an ID of the page before, is refused, but no set of every ID is kept.
|
|
55
|
+
*/
|
|
56
|
+
export interface PackObjects<E, R> {
|
|
57
|
+
readonly count: number;
|
|
58
|
+
/**
|
|
59
|
+
* At most `most` objects from the `from`th: fewer only at the end. Asked once more from `count`
|
|
60
|
+
* when the last is written, which a source of exactly `count` answers with none.
|
|
61
|
+
*/
|
|
62
|
+
readonly page: (from: number, most: number) => Effect.Effect<ReadonlyArray<PackObject>, E, R>;
|
|
63
|
+
/**
|
|
64
|
+
* Bytes of `object`'s body from `at`: at least one, and none past its size. Each is counted on
|
|
65
|
+
* the meter by its whole buffer until the next, so a small view of a large one may not fit.
|
|
66
|
+
*/
|
|
67
|
+
readonly read: (object: PackObject, at: number) => Effect.Effect<Uint8Array<ArrayBuffer>, E, R>;
|
|
68
|
+
/** Asked once every object is written and checked, before the trailer: fails to withhold it. */
|
|
69
|
+
readonly end: Effect.Effect<void, E, R>;
|
|
70
|
+
/**
|
|
71
|
+
* The entry to copy for `object` as it's reached, or `undefined` to write it whole from `read`.
|
|
72
|
+
* Asked once per object; a source that answers checks the entry's bytes as it reads them.
|
|
73
|
+
*/
|
|
74
|
+
readonly copy?: (object: PackObject) => PackCopy<E, R> | undefined;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Where a pack's bytes go, each write awaited before the next, so a slow output slows the write.
|
|
78
|
+
* A piece is the writer's own buffer, good only until the call returns: an output that keeps it
|
|
79
|
+
* copies it.
|
|
80
|
+
*/
|
|
81
|
+
export interface PackOutput<E, R> {
|
|
82
|
+
readonly write: (bytes: Uint8Array) => Effect.Effect<void, E, R>;
|
|
83
|
+
}
|
|
84
|
+
/** A SHA-1 of its own, and its letting go at once after a failure: one per pack, one per object. */
|
|
85
|
+
export interface PackDigest<E, R> {
|
|
86
|
+
readonly hasher: PackHasher<E, R>;
|
|
87
|
+
readonly abort: () => void;
|
|
88
|
+
}
|
|
89
|
+
/** A pack's limits: its bytes, header to trailer, one object's body, and the time it may take. */
|
|
90
|
+
export interface PackWriteLimits {
|
|
91
|
+
readonly packBytes: number;
|
|
92
|
+
/** The largest body written whole: a copied entry's is never inflated, so has no such bound. */
|
|
93
|
+
readonly objectBytes: number;
|
|
94
|
+
readonly elapsedMillis: number;
|
|
95
|
+
/**
|
|
96
|
+
* The bound a refusal for time names, when `elapsedMillis` is what's left of a larger one, such
|
|
97
|
+
* as a fetch's past its plan; `elapsedMillis` when absent.
|
|
98
|
+
*/
|
|
99
|
+
readonly namedMillis?: number;
|
|
100
|
+
}
|
|
101
|
+
/** What a written pack came to. */
|
|
102
|
+
export interface PackWritten {
|
|
103
|
+
readonly count: number;
|
|
104
|
+
/** Its bytes, header to trailer. */
|
|
105
|
+
readonly bytes: number;
|
|
106
|
+
/** Its trailer, as hex. */
|
|
107
|
+
readonly checksum: Oid;
|
|
108
|
+
/** Its objects' bodies' bytes, before compression. */
|
|
109
|
+
readonly bodyBytes: number;
|
|
110
|
+
/** The source's reads: pages and ranges. */
|
|
111
|
+
readonly pages: number;
|
|
112
|
+
readonly ranges: number;
|
|
113
|
+
/** The most bytes its writing retained at once, as the meter counted them. */
|
|
114
|
+
readonly retainedMost: number;
|
|
115
|
+
}
|
|
116
|
+
/** The writer's output buffer, and the most bytes it hands its compressor at once. */
|
|
117
|
+
export declare const packPieceBytes: number;
|
|
118
|
+
/** Objects a page asks of its source at a time. */
|
|
119
|
+
export declare const packPageObjects = 64;
|
|
120
|
+
/** What one object of a page is counted as holding: its ID, kind and size, with room to spare. */
|
|
121
|
+
export declare const packObjectBytes = 512;
|
|
122
|
+
/**
|
|
123
|
+
* An undeltified entry's header: its type in bits 4 to 6 of the first byte, its size's low four
|
|
124
|
+
* bits below them, then the rest of its size seven bits a byte, low first, each byte but the
|
|
125
|
+
* last with its top bit set. Sizes past 32 bits are split by arithmetic, never by `>>>`.
|
|
126
|
+
*/
|
|
127
|
+
export declare const entryHeader: (kind: ObjectType, size: number) => Uint8Array<ArrayBuffer>;
|
|
128
|
+
/**
|
|
129
|
+
* Writes the pack of `objects` to `output`, hashing every byte before it's written, each object
|
|
130
|
+
* checked against its ID as it goes, within `limits` and the meter's ceiling. Each object's
|
|
131
|
+
* compressor and digest is let go before the next starts, and every one on any failure or
|
|
132
|
+
* interruption, without waiting on any of them. `placed`, if given, is told each object once its
|
|
133
|
+
* entry is written and its ID checked, with its offset in the pack and its entry's CRC-32, so the
|
|
134
|
+
* caller can index it. `parts`, if given, counts where its time goes, and what it had written and
|
|
135
|
+
* how it ended however it ends.
|
|
136
|
+
*/
|
|
137
|
+
export declare const writePack: <SE, SR, OE, OR, HE, HR>(objects: PackObjects<SE, SR>, output: PackOutput<OE, OR>, digest: () => PackDigest<HE, HR>, limits: PackWriteLimits, meter: BufferMeter, placed?: (object: IndexedObject) => void, parts?: PackParts) => Effect.Effect<PackWritten, PackWriteError | BufferError | DeflateError | SE | OE | HE, SR | OR | HR>;
|
|
138
|
+
/**
|
|
139
|
+
* How a writing ended, as its parts keep it: `written`, the writer's fault, `failed` for any other
|
|
140
|
+
* failure, or `interrupted`.
|
|
141
|
+
*/
|
|
142
|
+
export declare const packEnd: (exit: Exit.Exit<unknown, unknown>) => PackEnd;
|
|
143
|
+
/** A pack's bytes as a stream, and what its writing came to once the stream is closed. */
|
|
144
|
+
export interface PackStream<A, E> {
|
|
145
|
+
readonly stream: ReadableStream<Uint8Array>;
|
|
146
|
+
readonly done: Effect.Effect<A, E | PackWriteError>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* A pack's bytes as a stream someone pulls, such as a push's body: `write` runs in a fiber of
|
|
150
|
+
* its own, each piece copied and queued only once the stream asks for one, so at most one piece
|
|
151
|
+
* waits in its queue and one in the writer. Cancelling the stream interrupts the writing, its
|
|
152
|
+
* pending reads and finalizers with it. `done` answers what the writing came to once the last
|
|
153
|
+
* byte is queued and the stream closed, or how it failed; an interrupted writing fails as
|
|
154
|
+
* `cancelled`. The fiber outlives the effect that made the stream, so a caller can hand the
|
|
155
|
+
* stream on and await `done` later; one nobody reads stops at `write`'s own time bound.
|
|
156
|
+
*/
|
|
157
|
+
export declare const packStream: <A, E, R>(write: (output: PackOutput<never, never>) => Effect.Effect<A, E, R>, meter: BufferMeter) => Effect.Effect<PackStream<A, E>, BufferError, R>;
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { allotOrFail, allotScoped, capacityOf } from "../bytes/buffers.mjs";
|
|
2
|
+
import { crc32Update } from "../bytes/crc32.mjs";
|
|
3
|
+
import { deflateWhole, deflatedMost, deflaterBytes, memberDeflater } from "../bytes/deflate.mjs";
|
|
4
|
+
import { hexOf } from "../bytes/hex.mjs";
|
|
5
|
+
import { isOid } from "../bytes/text.mjs";
|
|
6
|
+
import { isObjectType, objectHeader } from "../objects/object.mjs";
|
|
7
|
+
import { PackParts } from "./parts.mjs";
|
|
8
|
+
import { PackWriteError, refuseWrite } from "./write-error.mjs";
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
import * as Option from "effect/Option";
|
|
11
|
+
import * as Cause from "effect/Cause";
|
|
12
|
+
import * as Exit from "effect/Exit";
|
|
13
|
+
import * as Hex from "effect/encoding/Hex";
|
|
14
|
+
import * as Clock from "effect/Clock";
|
|
15
|
+
import * as Fiber from "effect/Fiber";
|
|
16
|
+
import * as Scheduler from "effect/Scheduler";
|
|
17
|
+
// src/protocol/packs/writer.ts
|
|
18
|
+
/** The writer's output buffer, and the most bytes it hands its compressor at once. */
|
|
19
|
+
const packPieceBytes = 65536;
|
|
20
|
+
/**
|
|
21
|
+
* The steps taken between turns of the event loop, each a timer's, so an interruption gets a turn,
|
|
22
|
+
* and between looks at the clock against the writer's time bound: a step is an object begun, or a
|
|
23
|
+
* piece of at most `packPieceBytes` of its body read or deflated, so both come at least every MiB
|
|
24
|
+
* and every 16 objects, however small. An object deflated whole waits on no compressor, only on
|
|
25
|
+
* its source and digest, which resume as microtasks, so among such objects the turn is the only
|
|
26
|
+
* one a timer gets. The writing's own steps resume as microtasks, never timers: in workerd a
|
|
27
|
+
* timer's turn costs milliseconds, which at one a piece held a pack to 3 MB/s. A timer for the
|
|
28
|
+
* bound alone isn't enough: in workerd one never fired while 1,500 tiny objects were written, the
|
|
29
|
+
* writing always ready to go on, so the writer looks at the clock itself.
|
|
30
|
+
*/
|
|
31
|
+
const turnSteps = 16;
|
|
32
|
+
/** Objects a page asks of its source at a time. */
|
|
33
|
+
const packPageObjects = 64;
|
|
34
|
+
/** What one object of a page is counted as holding: its ID, kind and size, with room to spare. */
|
|
35
|
+
const packObjectBytes = 512;
|
|
36
|
+
/** A PACK's count is four bytes. */
|
|
37
|
+
const mostCount = 2 ** 32 - 1;
|
|
38
|
+
/** Each kind's type number in an entry's header. */
|
|
39
|
+
const typeNumbers = {
|
|
40
|
+
commit: 1,
|
|
41
|
+
tree: 2,
|
|
42
|
+
blob: 3,
|
|
43
|
+
tag: 4
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* An undeltified entry's header: its type in bits 4 to 6 of the first byte, its size's low four
|
|
47
|
+
* bits below them, then the rest of its size seven bits a byte, low first, each byte but the
|
|
48
|
+
* last with its top bit set. Sizes past 32 bits are split by arithmetic, never by `>>>`.
|
|
49
|
+
*/
|
|
50
|
+
const entryHeader = (kind, size) => {
|
|
51
|
+
const bytes = [];
|
|
52
|
+
let rest = Math.floor(size / 16);
|
|
53
|
+
let byte = typeNumbers[kind] << 4 | size % 16;
|
|
54
|
+
while (rest > 0) {
|
|
55
|
+
bytes.push(byte | 128);
|
|
56
|
+
byte = rest % 128;
|
|
57
|
+
rest = Math.floor(rest / 128);
|
|
58
|
+
}
|
|
59
|
+
bytes.push(byte);
|
|
60
|
+
return Uint8Array.from(bytes);
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* `object`'s ID, kind and size, checked before its entry is written; its size against
|
|
64
|
+
* `objectBytes` only when it's written whole, since a copied entry's body is never inflated.
|
|
65
|
+
*/
|
|
66
|
+
const checkObject = (object, limits, copying) => {
|
|
67
|
+
if (!isOid(object.oid)) return refuseWrite("oid", `${object.oid} isn't a SHA-1 ID`);
|
|
68
|
+
if (!isObjectType(object.kind)) return refuseWrite("kind", `${object.oid} is a ${String(object.kind)}`);
|
|
69
|
+
if (!Number.isSafeInteger(object.size) || object.size < 0) return refuseWrite("size", `${object.oid}'s size ${object.size} isn't a byte count`);
|
|
70
|
+
if (!copying && object.size > limits.objectBytes) return refuseWrite("too big", `${object.oid} is ${object.size} bytes, past ${limits.objectBytes}`);
|
|
71
|
+
return Effect.void;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Writes the pack of `objects` to `output`, hashing every byte before it's written, each object
|
|
75
|
+
* checked against its ID as it goes, within `limits` and the meter's ceiling. Each object's
|
|
76
|
+
* compressor and digest is let go before the next starts, and every one on any failure or
|
|
77
|
+
* interruption, without waiting on any of them. `placed`, if given, is told each object once its
|
|
78
|
+
* entry is written and its ID checked, with its offset in the pack and its entry's CRC-32, so the
|
|
79
|
+
* caller can index it. `parts`, if given, counts where its time goes, and what it had written and
|
|
80
|
+
* how it ended however it ends.
|
|
81
|
+
*/
|
|
82
|
+
const writePack = (objects, output, digest, limits, meter, placed, parts = new PackParts()) => {
|
|
83
|
+
const live = {
|
|
84
|
+
pack: void 0,
|
|
85
|
+
object: void 0
|
|
86
|
+
};
|
|
87
|
+
const letGo = Effect.sync(() => {
|
|
88
|
+
live.pack?.abort();
|
|
89
|
+
live.object?.abort();
|
|
90
|
+
meter.free("output");
|
|
91
|
+
meter.free("page");
|
|
92
|
+
});
|
|
93
|
+
return Effect.gen(function* () {
|
|
94
|
+
const count = objects.count;
|
|
95
|
+
if (!Number.isSafeInteger(count) || count < 0 || count > mostCount) return yield* refuseWrite("count", `a pack can't count ${count} objects`);
|
|
96
|
+
yield* allotOrFail(meter, "output", packPieceBytes);
|
|
97
|
+
yield* allotOrFail(meter, "page", 32768);
|
|
98
|
+
const pack = digest();
|
|
99
|
+
live.pack = pack;
|
|
100
|
+
const out = new Uint8Array(packPieceBytes);
|
|
101
|
+
let filled = 0;
|
|
102
|
+
let written = 0;
|
|
103
|
+
let crc = 0;
|
|
104
|
+
let bodyBytes = 0;
|
|
105
|
+
let pages = 0;
|
|
106
|
+
let ranges = 0;
|
|
107
|
+
let sinceTurn = 0;
|
|
108
|
+
const deadline = (yield* Clock.currentTimeMillis) + limits.elapsedMillis;
|
|
109
|
+
/** One step taken; once `turnSteps` are, the time bound checked and a timer's turn taken. */
|
|
110
|
+
const stepped = Effect.suspend(() => {
|
|
111
|
+
sinceTurn += 1;
|
|
112
|
+
if (sinceTurn < turnSteps) return Effect.void;
|
|
113
|
+
sinceTurn = 0;
|
|
114
|
+
return Effect.flatMap(Clock.currentTimeMillis, (now) => now >= deadline ? refuseWrite("time", `the pack took past ${limits.namedMillis ?? limits.elapsedMillis} ms`) : parts.timed("turn", Effect.sleep(0)));
|
|
115
|
+
});
|
|
116
|
+
/** Hashes and writes what the buffer holds, refused if it and the trailer pass the bound. */
|
|
117
|
+
const flush = Effect.gen(function* () {
|
|
118
|
+
if (filled === 0) return;
|
|
119
|
+
if (written + filled + 20 > limits.packBytes) return yield* refuseWrite("too big", `the pack would pass ${limits.packBytes} bytes`);
|
|
120
|
+
const bytes = out.subarray(0, filled);
|
|
121
|
+
yield* parts.timed("pack_hash", pack.hasher.write(bytes));
|
|
122
|
+
yield* parts.timed("output", output.write(bytes));
|
|
123
|
+
written += filled;
|
|
124
|
+
parts.bytes += filled;
|
|
125
|
+
filled = 0;
|
|
126
|
+
});
|
|
127
|
+
/** Buffers `bytes`, folded into the open entry's CRC-32, writing each buffer as it fills. */
|
|
128
|
+
const put = (bytes) => Effect.gen(function* () {
|
|
129
|
+
crc = crc32Update(crc, bytes);
|
|
130
|
+
for (let at = 0; at < bytes.byteLength;) {
|
|
131
|
+
const take = Math.min(packPieceBytes - filled, bytes.byteLength - at);
|
|
132
|
+
out.set(bytes.subarray(at, at + take), filled);
|
|
133
|
+
filled += take;
|
|
134
|
+
at += take;
|
|
135
|
+
if (filled === 65536) yield* flush;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
/** A stored entry's bytes put as they are, each range refused past its length. */
|
|
139
|
+
const copied = (object, copy) => Effect.scoped(Effect.gen(function* () {
|
|
140
|
+
if (!Number.isSafeInteger(copy.bytes) || copy.bytes < 1) return yield* refuseWrite("length", `${object.oid}'s copy is ${copy.bytes} bytes`);
|
|
141
|
+
yield* allotScoped(meter, "range", 0);
|
|
142
|
+
yield* stepped;
|
|
143
|
+
for (let at = 0; at < copy.bytes;) {
|
|
144
|
+
const bytes = yield* parts.timed("body", copy.read(at));
|
|
145
|
+
ranges += 1;
|
|
146
|
+
if (bytes.byteLength === 0 || bytes.byteLength > copy.bytes - at) return yield* refuseWrite("length", `${object.oid}'s copy gave ${bytes.byteLength} bytes at ${at} of ${copy.bytes}`);
|
|
147
|
+
yield* allotOrFail(meter, "range", capacityOf(bytes));
|
|
148
|
+
yield* put(bytes);
|
|
149
|
+
at += bytes.byteLength;
|
|
150
|
+
for (let from = 0; from < bytes.byteLength; from += packPieceBytes) yield* stepped;
|
|
151
|
+
}
|
|
152
|
+
}));
|
|
153
|
+
const head = /* @__PURE__ */ new Uint8Array(12);
|
|
154
|
+
head.set([
|
|
155
|
+
80,
|
|
156
|
+
65,
|
|
157
|
+
67,
|
|
158
|
+
75,
|
|
159
|
+
0,
|
|
160
|
+
0,
|
|
161
|
+
0,
|
|
162
|
+
2
|
|
163
|
+
]);
|
|
164
|
+
new DataView(head.buffer).setUint32(8, count);
|
|
165
|
+
yield* put(head);
|
|
166
|
+
let page = [];
|
|
167
|
+
let before = /* @__PURE__ */ new Set();
|
|
168
|
+
let pageAt = 0;
|
|
169
|
+
for (let index = 0; index < count; index += 1) {
|
|
170
|
+
if (index - pageAt >= page.length) {
|
|
171
|
+
const from = index;
|
|
172
|
+
const most = Math.min(64, count - from);
|
|
173
|
+
const next = yield* parts.timed("page", objects.page(from, most));
|
|
174
|
+
pages += 1;
|
|
175
|
+
if (next.length === 0 || next.length < most && from + next.length < count) return yield* refuseWrite("count", `the source ended at ${from + next.length} of ${count}`);
|
|
176
|
+
if (next.length > most) return yield* refuseWrite("count", `the source gave ${next.length} of ${most} asked`);
|
|
177
|
+
const seen = /* @__PURE__ */ new Set();
|
|
178
|
+
for (const object of next) {
|
|
179
|
+
if (seen.has(object.oid) || before.has(object.oid)) return yield* refuseWrite("duplicate", `${object.oid} is in the pack twice`);
|
|
180
|
+
seen.add(object.oid);
|
|
181
|
+
}
|
|
182
|
+
before = seen;
|
|
183
|
+
page = next;
|
|
184
|
+
pageAt = from;
|
|
185
|
+
}
|
|
186
|
+
const object = page[index - pageAt];
|
|
187
|
+
if (object === void 0) return yield* refuseWrite("count", `no object at ${index}`);
|
|
188
|
+
const copy = objects.copy?.(object);
|
|
189
|
+
yield* checkObject(object, limits, copy !== void 0);
|
|
190
|
+
const offset = written + filled;
|
|
191
|
+
crc = 0;
|
|
192
|
+
if (copy !== void 0) {
|
|
193
|
+
yield* copied(object, copy);
|
|
194
|
+
placed?.({
|
|
195
|
+
oid: object.oid,
|
|
196
|
+
offset,
|
|
197
|
+
crc32: crc
|
|
198
|
+
});
|
|
199
|
+
bodyBytes += object.size;
|
|
200
|
+
parts.objects += 1;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
yield* put(entryHeader(object.kind, object.size));
|
|
204
|
+
yield* stepped;
|
|
205
|
+
const named = digest();
|
|
206
|
+
live.object = named;
|
|
207
|
+
yield* parts.timed("object_hash", named.hasher.write(objectHeader(object.kind, object.size)));
|
|
208
|
+
/**
|
|
209
|
+
* The body's range at `at`, refused past its length, hashed as Git names the object. It's
|
|
210
|
+
* counted as `range`, its whole buffer, until the next replaces it or the object ends.
|
|
211
|
+
*/
|
|
212
|
+
const range = (at) => Effect.gen(function* () {
|
|
213
|
+
const bytes = yield* parts.timed("body", objects.read(object, at));
|
|
214
|
+
ranges += 1;
|
|
215
|
+
if (bytes.byteLength === 0 || bytes.byteLength > object.size - at) return yield* refuseWrite("length", `${object.oid}'s source gave ${bytes.byteLength} bytes at ${at} of ${object.size}`);
|
|
216
|
+
yield* allotOrFail(meter, "range", capacityOf(bytes));
|
|
217
|
+
yield* parts.timed("object_hash", named.hasher.write(bytes));
|
|
218
|
+
return bytes;
|
|
219
|
+
});
|
|
220
|
+
if (object.size <= 262144) yield* Effect.scoped(Effect.gen(function* () {
|
|
221
|
+
yield* allotScoped(meter, "range", 0);
|
|
222
|
+
yield* allotScoped(meter, "deflater", deflaterBytes);
|
|
223
|
+
yield* allotScoped(meter, "whole", object.size + deflatedMost(object.size));
|
|
224
|
+
const body = new Uint8Array(object.size);
|
|
225
|
+
for (let at = 0; at < object.size;) {
|
|
226
|
+
const bytes = yield* range(at);
|
|
227
|
+
body.set(bytes, at);
|
|
228
|
+
at += bytes.byteLength;
|
|
229
|
+
for (let from = 0; from < bytes.byteLength; from += packPieceBytes) yield* stepped;
|
|
230
|
+
}
|
|
231
|
+
yield* put(yield* parts.timed("deflate", deflateWhole(body)));
|
|
232
|
+
}));
|
|
233
|
+
else yield* Effect.scoped(Effect.gen(function* () {
|
|
234
|
+
yield* allotScoped(meter, "range", 0);
|
|
235
|
+
const member = yield* memberDeflater(meter, put);
|
|
236
|
+
for (let at = 0; at < object.size;) {
|
|
237
|
+
const bytes = yield* range(at);
|
|
238
|
+
for (let from = 0; from < bytes.byteLength; from += packPieceBytes) {
|
|
239
|
+
yield* parts.timed("deflate", member.write(bytes.subarray(from, from + packPieceBytes)));
|
|
240
|
+
yield* stepped;
|
|
241
|
+
}
|
|
242
|
+
at += bytes.byteLength;
|
|
243
|
+
}
|
|
244
|
+
yield* parts.timed("deflate_end", member.finish);
|
|
245
|
+
}));
|
|
246
|
+
const sum = hexOf(yield* parts.timed("object_digest", named.hasher.digest));
|
|
247
|
+
live.object = void 0;
|
|
248
|
+
if (sum !== object.oid) return yield* refuseWrite("hash", `${object.oid}'s bytes hash to ${sum}`);
|
|
249
|
+
placed?.({
|
|
250
|
+
oid: object.oid,
|
|
251
|
+
offset,
|
|
252
|
+
crc32: crc
|
|
253
|
+
});
|
|
254
|
+
bodyBytes += object.size;
|
|
255
|
+
parts.objects += 1;
|
|
256
|
+
}
|
|
257
|
+
const extra = yield* parts.timed("page", objects.page(count, 1));
|
|
258
|
+
pages += 1;
|
|
259
|
+
if (extra.length > 0) return yield* refuseWrite("count", `the source holds more than ${count} objects`);
|
|
260
|
+
yield* objects.end;
|
|
261
|
+
yield* flush;
|
|
262
|
+
const trailer = yield* parts.timed("pack_hash", pack.hasher.digest);
|
|
263
|
+
live.pack = void 0;
|
|
264
|
+
if (written + 20 > limits.packBytes) return yield* refuseWrite("too big", `the pack would pass ${limits.packBytes} bytes`);
|
|
265
|
+
yield* parts.timed("output", output.write(trailer));
|
|
266
|
+
parts.bytes += 20;
|
|
267
|
+
return {
|
|
268
|
+
count,
|
|
269
|
+
bytes: written + 20,
|
|
270
|
+
checksum: Hex.encode(trailer),
|
|
271
|
+
bodyBytes,
|
|
272
|
+
pages,
|
|
273
|
+
ranges,
|
|
274
|
+
retainedMost: meter.most
|
|
275
|
+
};
|
|
276
|
+
}).pipe(Effect.provideService(Scheduler.Scheduler, new Scheduler.MixedScheduler("sync")), Effect.timeoutOrElse({
|
|
277
|
+
duration: limits.elapsedMillis,
|
|
278
|
+
orElse: () => refuseWrite("time", `the pack took past ${limits.namedMillis ?? limits.elapsedMillis} ms`)
|
|
279
|
+
}), Effect.onExit((exit) => Effect.sync(() => {
|
|
280
|
+
parts.ended = packEnd(exit);
|
|
281
|
+
})), Effect.ensuring(letGo));
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* How a writing ended, as its parts keep it: `written`, the writer's fault, `failed` for any other
|
|
285
|
+
* failure, or `interrupted`.
|
|
286
|
+
*/
|
|
287
|
+
const packEnd = (exit) => {
|
|
288
|
+
if (Exit.isSuccess(exit)) return "written";
|
|
289
|
+
const failure = Cause.findErrorOption(exit.cause);
|
|
290
|
+
if (Option.isNone(failure)) return "interrupted";
|
|
291
|
+
return failure.value instanceof PackWriteError ? failure.value.fault : "failed";
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* A pack's bytes as a stream someone pulls, such as a push's body: `write` runs in a fiber of
|
|
295
|
+
* its own, each piece copied and queued only once the stream asks for one, so at most one piece
|
|
296
|
+
* waits in its queue and one in the writer. Cancelling the stream interrupts the writing, its
|
|
297
|
+
* pending reads and finalizers with it. `done` answers what the writing came to once the last
|
|
298
|
+
* byte is queued and the stream closed, or how it failed; an interrupted writing fails as
|
|
299
|
+
* `cancelled`. The fiber outlives the effect that made the stream, so a caller can hand the
|
|
300
|
+
* stream on and await `done` later; one nobody reads stops at `write`'s own time bound.
|
|
301
|
+
*/
|
|
302
|
+
const packStream = (write, meter) => Effect.gen(function* () {
|
|
303
|
+
yield* allotOrFail(meter, "stream", 2 * packPieceBytes);
|
|
304
|
+
let controller;
|
|
305
|
+
let pulled;
|
|
306
|
+
let wake;
|
|
307
|
+
let fiber;
|
|
308
|
+
let cancelled = false;
|
|
309
|
+
const stream = new ReadableStream({
|
|
310
|
+
start: (each) => {
|
|
311
|
+
controller = each;
|
|
312
|
+
},
|
|
313
|
+
pull: () => new Promise((resolve) => {
|
|
314
|
+
pulled = resolve;
|
|
315
|
+
const waking = wake;
|
|
316
|
+
wake = void 0;
|
|
317
|
+
waking?.();
|
|
318
|
+
}),
|
|
319
|
+
cancel: async () => {
|
|
320
|
+
cancelled = true;
|
|
321
|
+
pulled?.();
|
|
322
|
+
if (fiber !== void 0) await Effect.runPromise(Fiber.interrupt(fiber));
|
|
323
|
+
}
|
|
324
|
+
}, { highWaterMark: 1 });
|
|
325
|
+
const demand = Effect.callback((resume) => {
|
|
326
|
+
if (pulled !== void 0) {
|
|
327
|
+
resume(Effect.void);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
wake = () => resume(Effect.void);
|
|
331
|
+
return Effect.sync(() => {
|
|
332
|
+
wake = void 0;
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
const running = yield* Effect.forkDetach(write({ write: (bytes) => Effect.gen(function* () {
|
|
336
|
+
const copy = bytes.slice();
|
|
337
|
+
yield* demand;
|
|
338
|
+
const answer = pulled;
|
|
339
|
+
pulled = void 0;
|
|
340
|
+
if (!cancelled) controller?.enqueue(copy);
|
|
341
|
+
answer?.();
|
|
342
|
+
}) }).pipe(Effect.tap(() => Effect.sync(() => {
|
|
343
|
+
if (!cancelled) controller?.close();
|
|
344
|
+
})), Effect.tapCause((cause) => Effect.sync(() => {
|
|
345
|
+
if (!cancelled) controller?.error(Cause.squash(cause));
|
|
346
|
+
})), Effect.ensuring(Effect.sync(() => meter.free("stream")))));
|
|
347
|
+
fiber = running;
|
|
348
|
+
return {
|
|
349
|
+
stream,
|
|
350
|
+
done: Effect.flatMap(Fiber.await(running), (exit) => Exit.isSuccess(exit) ? Effect.succeed(exit.value) : Cause.hasInterruptsOnly(exit.cause) ? refuseWrite("cancelled", "the pack's stream was cancelled") : Effect.failCause(exit.cause))
|
|
351
|
+
};
|
|
352
|
+
});
|
|
353
|
+
export { entryHeader, packEnd, packObjectBytes, packPageObjects, packPieceBytes, packStream, writePack };
|