@ref0/git 0.0.0 → 0.2.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 +51 -0
- package/dist/client/git-http.mjs +201 -0
- package/dist/client/helper-node.mjs +19 -0
- package/dist/client/local.mjs +160 -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 +150 -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 +10 -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 +63 -0
- package/dist/contracts/push-uploads.d.mts +44 -0
- package/dist/contracts/queue.d.mts +401 -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 +126 -0
- package/dist/contracts/result.mjs +34 -0
- package/dist/contracts/rules.d.mts +159 -0
- package/dist/contracts/server.d.mts +245 -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 +174 -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/clock.mjs +18 -0
- package/dist/core/events/deliver.mjs +468 -0
- package/dist/core/events/stream.d.mts +19 -0
- package/dist/core/events/stream.mjs +290 -0
- package/dist/core/forks.mjs +1027 -0
- package/dist/core/hooks/post-receive.mjs +204 -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 +46 -0
- package/dist/core/publish.mjs +142 -0
- package/dist/core/push-decide.mjs +206 -0
- package/dist/core/push.mjs +1069 -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 +24 -0
- package/dist/core/seam.mjs +41 -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 +3 -0
- package/dist/extend.mjs +1 -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 +1036 -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 +17 -0
- package/dist/rest/handler.mjs +106 -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 +14 -0
- package/dist/server/extension.mjs +85 -0
- package/dist/server/routes.d.mts +25 -0
- package/dist/server/routes.mjs +67 -0
- package/dist/server/server.d.mts +2 -0
- package/dist/server/server.mjs +439 -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/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 +13 -0
- package/dist/storage/fetch.mjs +792 -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 +1433 -0
- package/dist/storage/index-fetch.d.mts +9 -0
- package/dist/storage/index-fetch.mjs +756 -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 +120 -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 +779 -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 +990 -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 +600 -0
- package/dist/storage/prune.mjs +506 -0
- package/dist/storage/push-allotment.mjs +109 -0
- package/dist/storage/push-uploads.mjs +151 -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 +3 -0
- package/dist/storage/rows.mjs +71 -0
- package/dist/storage/shallow.d.mts +5 -0
- package/dist/storage/shallow.mjs +128 -0
- package/dist/storage/stream-whole.mjs +236 -0
- package/dist/storage/unpack.mjs +236 -0
- package/dist/storage/visible.mjs +137 -0
- package/dist/storage/walk.d.mts +7 -0
- package/dist/storage/walk.mjs +170 -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/crossing.mjs +66 -0
- package/dist/store/cursor-seal.d.mts +2 -0
- package/dist/store/cursor-seal.mjs +85 -0
- package/dist/store/errors.d.mts +12 -0
- package/dist/store/errors.mjs +129 -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 +295 -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 +29 -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 +80 -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 +554 -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 +126 -0
- package/package.json +86 -5
|
@@ -0,0 +1,1154 @@
|
|
|
1
|
+
import { callerFor, contended, keyedRecord, openKeyed, openRepo } from "../core/access.mjs";
|
|
2
|
+
import { grantNameOf } from "../auth/grants.mjs";
|
|
3
|
+
import { hostCall, rejectedError } from "../auth/host-function.mjs";
|
|
4
|
+
import { sightIn } from "../core/sight.mjs";
|
|
5
|
+
import { notFailed } from "../core/events/deliver.mjs";
|
|
6
|
+
import { openRead, readerOf } from "../core/objects/reading.mjs";
|
|
7
|
+
import { objectOfType } from "../core/objects/tree-edits.mjs";
|
|
8
|
+
import { changesOf } from "../core/rules/changes.mjs";
|
|
9
|
+
import { limitsOf } from "../engine/reads.mjs";
|
|
10
|
+
import { decodeRow, fail, storeCall, thrownError } from "../store/errors.mjs";
|
|
11
|
+
import { callScope } from "../store/call-count.mjs";
|
|
12
|
+
import { runIn } from "../store/crossing.mjs";
|
|
13
|
+
import { keptKey } from "../store/records.mjs";
|
|
14
|
+
import { readRecord } from "../store/repo-record.mjs";
|
|
15
|
+
import { refuseLive, reservedTarget, topicMember } from "../store/reservations.mjs";
|
|
16
|
+
import { collections, repoScope } from "../store/scopes.mjs";
|
|
17
|
+
import { checkBytes, queueFull, queueLimits } from "./limits.mjs";
|
|
18
|
+
import { fromReceipt, keptAnswer, queueWrite } from "./commit.mjs";
|
|
19
|
+
import { buildRow } from "../store/queue-jobs.mjs";
|
|
20
|
+
import { branchRef, queueIdParts, queueRef, shortTarget } from "./ids.mjs";
|
|
21
|
+
import { checkedLanes, isPinned } from "./lanes.mjs";
|
|
22
|
+
import { candidatePage, entryPage, holdPage } from "./pages.mjs";
|
|
23
|
+
import { CandidateRow, EntryRow, HoldRow } from "./rows.mjs";
|
|
24
|
+
import { QueuePlan, entryNotes, loadTarget, noQueue, openHolds, orderOf, readEntries, unknownId } from "./state.mjs";
|
|
25
|
+
import { addTargetHold, advanceAfter, aheadOf, candidateOf, closeAll, closeCandidate, endSearch, entryOf, held, holdOf, isOpen, joinedAt, keyHoldsOf, releaseHold, removeEntry, setChecking, supersede } from "./steps.mjs";
|
|
26
|
+
import * as Effect from "effect/Effect";
|
|
27
|
+
import * as Result from "effect/Result";
|
|
28
|
+
// src/queue/calls.ts
|
|
29
|
+
const idKinds = {
|
|
30
|
+
e: {
|
|
31
|
+
collection: collections.queueEntries,
|
|
32
|
+
schema: EntryRow,
|
|
33
|
+
what: "queue entry"
|
|
34
|
+
},
|
|
35
|
+
c: {
|
|
36
|
+
collection: collections.queueCandidates,
|
|
37
|
+
schema: CandidateRow,
|
|
38
|
+
what: "candidate"
|
|
39
|
+
},
|
|
40
|
+
h: {
|
|
41
|
+
collection: collections.queueHolds,
|
|
42
|
+
schema: HoldRow,
|
|
43
|
+
what: "hold"
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
/** A repo `caller` may do `operation` to, with its queue: `NOT_FOUND`, `no-queue`, for none. */
|
|
47
|
+
const openQueue = Effect.fnUntraced(function* (host, caller, operation, target, internalId) {
|
|
48
|
+
const resolved = yield* openRepo(host.core, caller, operation, [], internalId);
|
|
49
|
+
const options = yield* host.options(resolved.name);
|
|
50
|
+
if (options === void 0) return yield* noQueue(resolved.name, target);
|
|
51
|
+
return {
|
|
52
|
+
name: resolved.name,
|
|
53
|
+
internalId: resolved.internalId,
|
|
54
|
+
public: resolved.record.public,
|
|
55
|
+
options
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Whether `caller` sees the queue's candidates: each one's ref is under `refs/queue/`, which holds
|
|
60
|
+
* whatever its entries hold, so only a caller who sees every ref does, as `RefSight` says (Q749).
|
|
61
|
+
*/
|
|
62
|
+
const seesCandidates = (host, caller, opened) => Effect.map(sightIn(host.core, caller, {
|
|
63
|
+
id: opened.name,
|
|
64
|
+
...opened
|
|
65
|
+
}), (sight) => sight.whole);
|
|
66
|
+
/**
|
|
67
|
+
* `openQueue` for a call by the repo's name with `key`: sent again, it answers from its receipt in
|
|
68
|
+
* the repo it wrote, as `keyedRecord` finds it through the name's catalogue entry, even once that
|
|
69
|
+
* repo was renamed and another took the name, whose queue it never touches.
|
|
70
|
+
*/
|
|
71
|
+
const openKeyedQueue = Effect.fnUntraced(function* (host, caller, operation, target, key, pin) {
|
|
72
|
+
const authorize = (repo) => host.core.authorize({
|
|
73
|
+
caller,
|
|
74
|
+
operation: {
|
|
75
|
+
...operation,
|
|
76
|
+
repo: repo.id
|
|
77
|
+
},
|
|
78
|
+
repo
|
|
79
|
+
});
|
|
80
|
+
for (let attempt = 0; attempt < 5; attempt += 1) {
|
|
81
|
+
const keyed = yield* keyedRecord(host.core.store, operation.repo, key, authorize, pin);
|
|
82
|
+
if (keyed?.kind === "answered") return {
|
|
83
|
+
kind: "answered",
|
|
84
|
+
answer: yield* fromReceipt(keyed.receipt)
|
|
85
|
+
};
|
|
86
|
+
const resolved = yield* openKeyed(host.core, caller, operation, [], keyed, pin);
|
|
87
|
+
if (resolved === void 0) continue;
|
|
88
|
+
const options = yield* host.options(resolved.name);
|
|
89
|
+
if (options === void 0) return yield* noQueue(resolved.name, target);
|
|
90
|
+
const { name, internalId } = resolved;
|
|
91
|
+
return {
|
|
92
|
+
kind: "opened",
|
|
93
|
+
name,
|
|
94
|
+
internalId,
|
|
95
|
+
options
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return yield* contended();
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* The repo, row and queue an entry's, candidate's or hold's ID names, once `caller` may do the
|
|
102
|
+
* operation on its repo. An ID whose repo the caller can't read is as one that names nothing.
|
|
103
|
+
*/
|
|
104
|
+
const openId = Effect.fnUntraced(function* (host, caller, kind, id, operationOf) {
|
|
105
|
+
const { collection, schema, what } = idKinds[kind];
|
|
106
|
+
const parts = queueIdParts(kind, id);
|
|
107
|
+
if (parts === void 0) return yield* unknownId(what, id);
|
|
108
|
+
const read = {
|
|
109
|
+
collection,
|
|
110
|
+
id
|
|
111
|
+
};
|
|
112
|
+
const { record, snapshot } = yield* readRecord(host.core.store, parts.internalId, [read]);
|
|
113
|
+
const [found] = snapshot.results[1] ?? [];
|
|
114
|
+
if (record === void 0 || record.deleted === true || found === void 0) return yield* unknownId(what, id);
|
|
115
|
+
const row = yield* decodeRow(schema, found, `The ${what} '${id}'`);
|
|
116
|
+
const opened = yield* openQueue(host, caller, operationOf(record.name, row)).pipe(Effect.catch((error) => error.code === "NOT_FOUND" && error.context?.reason !== "no-queue" ? unknownId(what, id) : Effect.fail(error)));
|
|
117
|
+
if (opened.internalId !== parts.internalId) return yield* unknownId(what, id);
|
|
118
|
+
return {
|
|
119
|
+
...opened,
|
|
120
|
+
row
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
const keyOf = (caller, input, parts, at) => keptKey(caller, input.key, parts, at);
|
|
124
|
+
/**
|
|
125
|
+
* The branch `target` names, as `main` or `refs/heads/main`: `INVALID_ARGUMENT` for any other ref,
|
|
126
|
+
* or for a name past `queueLimits.nameBytes`.
|
|
127
|
+
*/
|
|
128
|
+
const targetOf = (target) => {
|
|
129
|
+
const branch = branchRef(target);
|
|
130
|
+
if (!branch.startsWith("refs/heads/") || branch.length === 11) return fail("INVALID_ARGUMENT", `A queue's target is a branch, as main: not '${target}'`);
|
|
131
|
+
return Effect.as(checkBytes("target", branch, queueLimits.nameBytes), branch);
|
|
132
|
+
};
|
|
133
|
+
/** What an entry keeps of its caller and input, each within `queueLimits`. */
|
|
134
|
+
const checkEntry = (caller, actor, input) => {
|
|
135
|
+
const grant = grantNameOf(caller);
|
|
136
|
+
return Effect.all([
|
|
137
|
+
checkBytes("key", input.key, queueLimits.nameBytes),
|
|
138
|
+
checkBytes("source", input.source, queueLimits.nameBytes),
|
|
139
|
+
checkBytes("meta", input.meta, queueLimits.metaBytes),
|
|
140
|
+
checkBytes("actor", actor, queueLimits.nameBytes),
|
|
141
|
+
checkBytes("subject", caller.subject?.id, queueLimits.nameBytes),
|
|
142
|
+
checkBytes("grant resolver", grant?.resolver, queueLimits.nameBytes),
|
|
143
|
+
checkBytes("grant id", grant?.id, queueLimits.nameBytes)
|
|
144
|
+
]);
|
|
145
|
+
};
|
|
146
|
+
/** The entries of `rows` as answered, each with its `meta` and report. */
|
|
147
|
+
const answered = Effect.fnUntraced(function* (host, repo, rows) {
|
|
148
|
+
const notes = yield* entryNotes(host.core.store, repo.internalId, rows);
|
|
149
|
+
return rows.map(([id, row]) => entryOf(repo.name, id, row, notes.get(id) ?? {}));
|
|
150
|
+
});
|
|
151
|
+
/** The entry `answered` gives for `id`'s row. */
|
|
152
|
+
const answeredOne = (host, repo, id, row) => Effect.map(answered(host, repo, [[id, row]]), ([entry]) => entry ?? entryOf(repo.name, id, row, {}));
|
|
153
|
+
/** The fields of an entry `join` and `lanes` see. */
|
|
154
|
+
const entryFieldsOf = (input) => {
|
|
155
|
+
const entry = {
|
|
156
|
+
target: input.target,
|
|
157
|
+
source: input.source,
|
|
158
|
+
head: input.head,
|
|
159
|
+
key: input.key
|
|
160
|
+
};
|
|
161
|
+
if (input.priority !== void 0) entry.priority = input.priority;
|
|
162
|
+
if (input.meta !== void 0) entry.meta = input.meta;
|
|
163
|
+
return entry;
|
|
164
|
+
};
|
|
165
|
+
/** Asks the host's `join` whether the entry may join: its `Reject` refuses the add. */
|
|
166
|
+
const askJoin = (host, options, repo, caller, input) => {
|
|
167
|
+
const { join } = options;
|
|
168
|
+
if (join === void 0) return Effect.void;
|
|
169
|
+
const entry = entryFieldsOf(input);
|
|
170
|
+
const about = {
|
|
171
|
+
repo,
|
|
172
|
+
operation: {
|
|
173
|
+
kind: "queue.add",
|
|
174
|
+
repo,
|
|
175
|
+
entry
|
|
176
|
+
},
|
|
177
|
+
actor: caller.actor
|
|
178
|
+
};
|
|
179
|
+
return Effect.flatMap(hostCall(host.core.checks.reports, "join", about, (signal) => join({
|
|
180
|
+
repo,
|
|
181
|
+
entry,
|
|
182
|
+
actor: caller.actor,
|
|
183
|
+
signal
|
|
184
|
+
}), { timeout: 3e4 }), (answer) => answer.kind === "reject" ? Effect.fail(rejectedError(answer)) : Effect.void);
|
|
185
|
+
};
|
|
186
|
+
/** The write a call makes as `caller` over the core that skips `authorize`, once it's authorized. */
|
|
187
|
+
const writeAs = (host, caller, name, plan) => ({
|
|
188
|
+
kind: "write",
|
|
189
|
+
core: host.hostCore,
|
|
190
|
+
caller,
|
|
191
|
+
repo: name,
|
|
192
|
+
plan
|
|
193
|
+
});
|
|
194
|
+
/**
|
|
195
|
+
* Whether `caller` may add `input` to `repo`'s queue: a signed-in actor, a branch for its target, a
|
|
196
|
+
* finite priority, `queue.add` authorized and the host's `join`. An add asks it before it writes,
|
|
197
|
+
* and `git push -o queue` before its push lands, so a refused entry lands no branch.
|
|
198
|
+
*/
|
|
199
|
+
/**
|
|
200
|
+
* An add's entry checked and its queue opened, as `admitEntry` does, but without asking `join`:
|
|
201
|
+
* for work that `join` already admitted, which Git never asks again.
|
|
202
|
+
*/
|
|
203
|
+
const openEntry = Effect.fnUntraced(function* (host, caller, repo, input) {
|
|
204
|
+
const { actor } = caller;
|
|
205
|
+
if (actor.anonymous === true) return yield* fail("UNAUTHENTICATED", "A queue entry needs an actor: its merge is pushed as it");
|
|
206
|
+
const target = yield* targetOf(input.target);
|
|
207
|
+
if (input.priority !== void 0 && !Number.isFinite(input.priority)) return yield* fail("INVALID_ARGUMENT", "An entry’s priority is a finite number");
|
|
208
|
+
yield* checkEntry(caller, actor.id, input);
|
|
209
|
+
const entry = {
|
|
210
|
+
...input,
|
|
211
|
+
target
|
|
212
|
+
};
|
|
213
|
+
const operation = {
|
|
214
|
+
kind: "queue.add",
|
|
215
|
+
repo,
|
|
216
|
+
entry: {
|
|
217
|
+
target,
|
|
218
|
+
source: input.source,
|
|
219
|
+
head: input.head,
|
|
220
|
+
key: input.key
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
return {
|
|
224
|
+
...yield* openQueue(host, caller, operation, target, input.internalId),
|
|
225
|
+
actor,
|
|
226
|
+
input: entry
|
|
227
|
+
};
|
|
228
|
+
});
|
|
229
|
+
const admitEntry = Effect.fnUntraced(function* (host, caller, repo, input) {
|
|
230
|
+
const opened = yield* openEntry(host, caller, repo, input);
|
|
231
|
+
yield* askJoin(host, opened.options, opened.name, caller, opened.input);
|
|
232
|
+
return opened;
|
|
233
|
+
});
|
|
234
|
+
/**
|
|
235
|
+
* `input` added to the queue `admitEntry` let it into. The key names the entry: the same key and
|
|
236
|
+
* head answer its open entry again, or the entry that key merged last with that head, so an add
|
|
237
|
+
* sent again after its first answer was lost never queues a head its key merged (Q412). A new
|
|
238
|
+
* head replaces the key's open entry; after a failure or a removal, the add queues a new one.
|
|
239
|
+
* A target holding `queueLimits.openEntries` takes no new key: `queue-full`. A head that names no
|
|
240
|
+
* commit, such as a blob, is `INVALID_ARGUMENT`: nothing could link it onto the target.
|
|
241
|
+
*/
|
|
242
|
+
const addAdmitted = Effect.fnUntraced(function* (host, caller, opened, topic) {
|
|
243
|
+
let laned;
|
|
244
|
+
for (;;) {
|
|
245
|
+
const added = yield* addWrite(host, caller, opened, laned, topic);
|
|
246
|
+
if (!("unasked" in added)) return added;
|
|
247
|
+
laned = yield* lanesFor(host, caller, opened);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
/** An add that lost its race to the key's entry fails with what its `lanes` threw, if it threw. */
|
|
251
|
+
const lostRace = (laned) => laned !== void 0 && "error" in laned ? Effect.fail(laned.thrown) : Effect.void;
|
|
252
|
+
/**
|
|
253
|
+
* The lanes of an entry whose head must name a commit, read as the queue reads to build it: what
|
|
254
|
+
* the host's `lanes` answers, checked, with `changes()` the head's tree against the target's tip,
|
|
255
|
+
* diffed once when asked. A throw, a run past 30 seconds or an answer `checkedLanes` refuses fails
|
|
256
|
+
* the entry `host-error`, as Q479 says. With no `lanes`, every entry is in the one line.
|
|
257
|
+
*/
|
|
258
|
+
const lanesFor = Effect.fnUntraced(function* (host, caller, opened) {
|
|
259
|
+
const repo = yield* openRead(host.hostCore, host.caller, opened.name);
|
|
260
|
+
const { reader } = yield* readerOf(repo, yield* limitsOf(), "walk-limit");
|
|
261
|
+
const scope = yield* callScope;
|
|
262
|
+
yield* objectOfType(reader, opened.input.head, "commit");
|
|
263
|
+
const { lanes } = opened.options;
|
|
264
|
+
if (lanes === void 0) return { lanes: [] };
|
|
265
|
+
const { input, name } = opened;
|
|
266
|
+
const { tip } = yield* loadTarget(host.core.store, opened.internalId, input.target, {}, "row");
|
|
267
|
+
const entry = entryFieldsOf(input);
|
|
268
|
+
const about = {
|
|
269
|
+
repo: name,
|
|
270
|
+
operation: {
|
|
271
|
+
kind: "queue.add",
|
|
272
|
+
repo: name,
|
|
273
|
+
entry
|
|
274
|
+
},
|
|
275
|
+
actor: caller.actor
|
|
276
|
+
};
|
|
277
|
+
const updates = [{
|
|
278
|
+
ref: input.target,
|
|
279
|
+
from: tip,
|
|
280
|
+
to: input.head,
|
|
281
|
+
kind: tip === null ? "create" : "force"
|
|
282
|
+
}];
|
|
283
|
+
return yield* hostCall(host.core.checks.reports, "queue.lanes", about, async (signal) => {
|
|
284
|
+
let diffed;
|
|
285
|
+
const changes = async () => {
|
|
286
|
+
diffed ??= runIn(Effect.result(changesOf(repo.read, updates, signal)), scope);
|
|
287
|
+
const result = await diffed;
|
|
288
|
+
if (Result.isSuccess(result)) return result.success;
|
|
289
|
+
throw thrownError(result.failure);
|
|
290
|
+
};
|
|
291
|
+
return checkedLanes(await lanes({
|
|
292
|
+
repo: name,
|
|
293
|
+
entry,
|
|
294
|
+
actor: caller.actor,
|
|
295
|
+
signal,
|
|
296
|
+
changes
|
|
297
|
+
}));
|
|
298
|
+
}, { timeout: 3e4 }).pipe(Effect.map((named) => ({ lanes: named })), Effect.catch((error) => {
|
|
299
|
+
return error.code === "UNAVAILABLE" || error.code === "DEADLINE_EXCEEDED" ? Effect.succeed({
|
|
300
|
+
error: error.context?.id ?? "",
|
|
301
|
+
thrown: error
|
|
302
|
+
}) : Effect.fail(error);
|
|
303
|
+
}));
|
|
304
|
+
});
|
|
305
|
+
/**
|
|
306
|
+
* Refuses an add that would take `row`, the entry its key found, from its owner: an add for a
|
|
307
|
+
* topic takes no entry outside it, and only its topic writes over a live topic's member. Whether
|
|
308
|
+
* the add, naming `row`'s head when `same`, answers `row` as it is.
|
|
309
|
+
*/
|
|
310
|
+
const ownedBy = Effect.fnUntraced(function* (host, id, row, topic, same) {
|
|
311
|
+
const held = row.topic;
|
|
312
|
+
const own = held?.topic === topic?.topic;
|
|
313
|
+
if (same && topic !== void 0 && !own) {
|
|
314
|
+
if (held !== void 0) yield* notMember(host, id, held);
|
|
315
|
+
const message = `${id} is queued already, outside topic ${topic.topic}`;
|
|
316
|
+
const hint = isOpen(row) ? `Remove ${id} with queue.remove, then add the topic again` : `Add the member under a new entry key: ${id} is ${row.state}`;
|
|
317
|
+
return yield* fail("FAILED_PRECONDITION", message, { hint });
|
|
318
|
+
}
|
|
319
|
+
if (held !== void 0 && !own) yield* notMember(host, id, held);
|
|
320
|
+
return same && own;
|
|
321
|
+
});
|
|
322
|
+
/** Refuses a write to `entry` while `topic`, the topic it's a member of, is live. */
|
|
323
|
+
const notMember = (host, entry, topic) => refuseLive(host.core.store, topic, (held, state) => topicMember(entry, held, state));
|
|
324
|
+
/** A write that closes or stops `target`'s candidates: refused while `reserved` holds it. */
|
|
325
|
+
const unreserved = (host, target, reserved) => refuseLive(host.core.store, reserved, (held, state) => reservedTarget(target, held, state));
|
|
326
|
+
/**
|
|
327
|
+
* `addAdmitted`'s write: the key's entry answered or moved, or, once its head is a commit and its
|
|
328
|
+
* lanes are asked, a new entry. Unasked, a new entry answers `Unasked`. An add that asked and lost
|
|
329
|
+
* a race to the key's entry answers what `lanes` threw, if it threw: its redelivery, the repeat.
|
|
330
|
+
*/
|
|
331
|
+
const addWrite = (host, caller, opened, laned, topic) => queueWrite(Effect.gen(function* () {
|
|
332
|
+
const { input } = opened;
|
|
333
|
+
const state = yield* loadTarget(host.core.store, opened.internalId, input.target, { keys: [input.key] });
|
|
334
|
+
if (input.jump === true) yield* unreserved(host, input.target, state.row.reserved);
|
|
335
|
+
const merged = state.keys.get(input.key);
|
|
336
|
+
if (merged?.head === input.head) {
|
|
337
|
+
const row = (yield* readEntries(host.core.store, opened.internalId, [merged.entry])).get(merged.entry);
|
|
338
|
+
if (row !== void 0) {
|
|
339
|
+
yield* ownedBy(host, merged.entry, row, topic, true);
|
|
340
|
+
yield* lostRace(laned);
|
|
341
|
+
return {
|
|
342
|
+
kind: "done",
|
|
343
|
+
answer: {
|
|
344
|
+
entry: yield* answeredOne(host, opened, merged.entry, row),
|
|
345
|
+
ahead: 0,
|
|
346
|
+
revision: state.revision,
|
|
347
|
+
repeat: true
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const plan = new QueuePlan(state, yield* host.core.now);
|
|
353
|
+
const place = state.row.order.find((open) => open.key === input.key);
|
|
354
|
+
const before = place === void 0 ? void 0 : state.entries.get(place.entry);
|
|
355
|
+
const priority = input.priority ?? 0;
|
|
356
|
+
const answers = place !== void 0 && before !== void 0 && (yield* ownedBy(host, place.entry, before, topic, before.head === input.head));
|
|
357
|
+
if (place !== void 0 && before !== void 0 && answers) {
|
|
358
|
+
yield* lostRace(laned);
|
|
359
|
+
if (place.priority === priority && input.jump !== true) return {
|
|
360
|
+
kind: "done",
|
|
361
|
+
answer: {
|
|
362
|
+
entry: yield* answeredOne(host, opened, place.entry, before),
|
|
363
|
+
ahead: aheadOf(plan, place.entry),
|
|
364
|
+
revision: state.revision,
|
|
365
|
+
repeat: true
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
const moved = {
|
|
369
|
+
...place,
|
|
370
|
+
priority
|
|
371
|
+
};
|
|
372
|
+
if (input.jump === true) moved.jumped = joinedAt(plan);
|
|
373
|
+
const changed = { ...before };
|
|
374
|
+
if (input.priority === void 0) delete changed.priority;
|
|
375
|
+
else changed.priority = input.priority;
|
|
376
|
+
plan.setEntry(place.entry, changed);
|
|
377
|
+
plan.setTarget({
|
|
378
|
+
...plan.row,
|
|
379
|
+
order: plan.row.order.map((open) => open.entry === place.entry ? moved : open)
|
|
380
|
+
});
|
|
381
|
+
if (input.jump === true) closeAll(plan, "superseded");
|
|
382
|
+
advanceAfter(plan);
|
|
383
|
+
const row = plan.entries.get(place.entry) ?? changed;
|
|
384
|
+
const answer = {
|
|
385
|
+
entry: yield* answeredOne(host, opened, place.entry, row),
|
|
386
|
+
ahead: aheadOf(plan, place.entry),
|
|
387
|
+
revision: 0,
|
|
388
|
+
repeat: false
|
|
389
|
+
};
|
|
390
|
+
return {
|
|
391
|
+
...writeAs(host, caller, opened.name, plan),
|
|
392
|
+
answer
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
if (place === void 0 && state.row.order.length >= queueLimits.openEntries) return yield* queueFull("open entries", queueLimits.openEntries);
|
|
396
|
+
if (laned === void 0) return {
|
|
397
|
+
kind: "done",
|
|
398
|
+
answer: { unasked: true }
|
|
399
|
+
};
|
|
400
|
+
if (place !== void 0) removeEntry(plan, place.entry, { reason: "replaced" });
|
|
401
|
+
const id = plan.id("e");
|
|
402
|
+
const row = {
|
|
403
|
+
target: input.target,
|
|
404
|
+
source: input.source,
|
|
405
|
+
head: input.head,
|
|
406
|
+
key: input.key,
|
|
407
|
+
actor: opened.actor.id,
|
|
408
|
+
state: "waiting",
|
|
409
|
+
lanes: "lanes" in laned ? laned.lanes : []
|
|
410
|
+
};
|
|
411
|
+
if (input.priority !== void 0) row.priority = input.priority;
|
|
412
|
+
if (topic !== void 0) row.topic = topic;
|
|
413
|
+
if (input.meta !== void 0) {
|
|
414
|
+
row.meta = true;
|
|
415
|
+
plan.setMeta(id, input.meta);
|
|
416
|
+
}
|
|
417
|
+
if (caller.subject !== void 0) row.subject = caller.subject.id;
|
|
418
|
+
if (caller.token !== void 0) row.token = caller.token.id;
|
|
419
|
+
const grant = grantNameOf(caller);
|
|
420
|
+
if (grant !== void 0) row.grant = grant;
|
|
421
|
+
if ("error" in laned) {
|
|
422
|
+
row.state = "failed";
|
|
423
|
+
row.failure = "host-error";
|
|
424
|
+
} else if (held(plan, row)) row.state = "held";
|
|
425
|
+
plan.setEntry(id, row);
|
|
426
|
+
const joins = () => plan.event((envelope) => {
|
|
427
|
+
const added = {
|
|
428
|
+
type: "queue.entry.added",
|
|
429
|
+
...envelope,
|
|
430
|
+
entry: id,
|
|
431
|
+
key: input.key,
|
|
432
|
+
target: input.target,
|
|
433
|
+
source: input.source,
|
|
434
|
+
head: input.head
|
|
435
|
+
};
|
|
436
|
+
if (input.priority !== void 0) added.priority = input.priority;
|
|
437
|
+
return added;
|
|
438
|
+
});
|
|
439
|
+
const answer = {
|
|
440
|
+
entry: entryOf(opened.name, id, row, input.meta === void 0 ? {} : { meta: input.meta }),
|
|
441
|
+
ahead: 0,
|
|
442
|
+
revision: 0,
|
|
443
|
+
repeat: false
|
|
444
|
+
};
|
|
445
|
+
if (place !== void 0) answer.replaced = place.entry;
|
|
446
|
+
if ("error" in laned) {
|
|
447
|
+
joins();
|
|
448
|
+
plan.event((envelope) => ({
|
|
449
|
+
type: "queue.entry.failed",
|
|
450
|
+
...envelope,
|
|
451
|
+
entry: id,
|
|
452
|
+
reason: "host-error",
|
|
453
|
+
error: laned.error
|
|
454
|
+
}));
|
|
455
|
+
if (place !== void 0) advanceAfter(plan);
|
|
456
|
+
return {
|
|
457
|
+
...writeAs(host, caller, opened.name, plan),
|
|
458
|
+
answer
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
const joined = joinedAt(plan);
|
|
462
|
+
const joining = {
|
|
463
|
+
entry: id,
|
|
464
|
+
key: input.key,
|
|
465
|
+
priority,
|
|
466
|
+
joined,
|
|
467
|
+
since: plan.now
|
|
468
|
+
};
|
|
469
|
+
if (input.jump === true) joining.jumped = joined;
|
|
470
|
+
plan.setTarget({
|
|
471
|
+
...plan.row,
|
|
472
|
+
order: [...plan.row.order, joining]
|
|
473
|
+
});
|
|
474
|
+
if (plan.row.tip === void 0) plan.setTarget({
|
|
475
|
+
...plan.row,
|
|
476
|
+
tip: state.tip
|
|
477
|
+
});
|
|
478
|
+
if (input.jump === true) closeAll(plan, "superseded");
|
|
479
|
+
plan.edits.push({
|
|
480
|
+
ref: queueRef(input.target, id),
|
|
481
|
+
from: null,
|
|
482
|
+
to: input.head
|
|
483
|
+
});
|
|
484
|
+
joins();
|
|
485
|
+
advanceAfter(plan);
|
|
486
|
+
answer.ahead = aheadOf(plan, id);
|
|
487
|
+
return {
|
|
488
|
+
...writeAs(host, caller, opened.name, plan),
|
|
489
|
+
answer
|
|
490
|
+
};
|
|
491
|
+
}));
|
|
492
|
+
/** The merge queue's calls over `host`, deciding for `bound`, as `callerFor` says. */
|
|
493
|
+
const queueCalls = (host, bound) => {
|
|
494
|
+
const callerOf = callerFor(bound);
|
|
495
|
+
/**
|
|
496
|
+
* A call's write, answered from its receipt when its key committed already: read first, and
|
|
497
|
+
* again when the write fails or plans nothing, since the same call sent alongside may commit
|
|
498
|
+
* after the first read and the queue move on, so this one's plan refuses or repeats what that one
|
|
499
|
+
* did, at a later revision. The receipt commits with that write, so a plan that saw the write
|
|
500
|
+
* finds its receipt after.
|
|
501
|
+
*/
|
|
502
|
+
const write = (step, internalId, key) => {
|
|
503
|
+
const kept = keptAnswer(host.core.store, internalId, key);
|
|
504
|
+
const checked = key === void 0 ? step : Effect.flatMap(step, (planned) => planned.kind === "write" ? Effect.succeed(planned) : Effect.map(kept, (late) => late === void 0 ? planned : {
|
|
505
|
+
kind: "done",
|
|
506
|
+
answer: late
|
|
507
|
+
}));
|
|
508
|
+
const written = Effect.catch(queueWrite(checked), (error) => key === void 0 ? Effect.fail(error) : Effect.flatMap(kept, (late) => late === void 0 ? Effect.fail(error) : Effect.succeed(late)));
|
|
509
|
+
return Effect.flatMap(kept, (first) => first === void 0 ? written : Effect.succeed(first));
|
|
510
|
+
};
|
|
511
|
+
const writing = (caller, name, plan) => writeAs(host, caller, name, plan);
|
|
512
|
+
const add = Effect.fnUntraced(function* (repo, input) {
|
|
513
|
+
const caller = callerOf(input);
|
|
514
|
+
const opened = yield* admitEntry(host, caller, repo, input);
|
|
515
|
+
return yield* addAdmitted(host, caller, opened);
|
|
516
|
+
});
|
|
517
|
+
const remove = Effect.fnUntraced(function* (entry, input) {
|
|
518
|
+
const caller = callerOf(input);
|
|
519
|
+
const opened = yield* openId(host, caller, "e", entry, (repo) => ({
|
|
520
|
+
kind: "queue.remove",
|
|
521
|
+
repo,
|
|
522
|
+
entry
|
|
523
|
+
}));
|
|
524
|
+
const key = yield* keyOf(caller, input, ["queue.remove", entry], yield* host.core.now);
|
|
525
|
+
return yield* write(Effect.gen(function* () {
|
|
526
|
+
const state = yield* loadTarget(host.core.store, opened.internalId, opened.row.target, { entries: [entry] });
|
|
527
|
+
const row = state.entries.get(entry) ?? opened.row;
|
|
528
|
+
if (row.state === "removed") return {
|
|
529
|
+
kind: "done",
|
|
530
|
+
answer: {
|
|
531
|
+
entry,
|
|
532
|
+
revision: state.revision,
|
|
533
|
+
repeat: true
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
if (!isOpen(row)) return yield* entryGone(entry, row.state);
|
|
537
|
+
yield* notMember(host, entry, row.topic);
|
|
538
|
+
const plan = new QueuePlan(state, yield* host.core.now);
|
|
539
|
+
removeEntry(plan, entry, { reason: "removed" });
|
|
540
|
+
advanceAfter(plan);
|
|
541
|
+
const answer = {
|
|
542
|
+
entry,
|
|
543
|
+
revision: 0,
|
|
544
|
+
repeat: false
|
|
545
|
+
};
|
|
546
|
+
return {
|
|
547
|
+
...writing(caller, opened.name, plan),
|
|
548
|
+
answer,
|
|
549
|
+
...withKey(key)
|
|
550
|
+
};
|
|
551
|
+
}), opened.internalId, key);
|
|
552
|
+
});
|
|
553
|
+
const holdTarget = Effect.fnUntraced(function* (repo, input) {
|
|
554
|
+
const caller = callerOf(input);
|
|
555
|
+
const target = yield* targetOf(input.target);
|
|
556
|
+
yield* checkBytes("reason", input.reason, queueLimits.reasonBytes);
|
|
557
|
+
const operation = {
|
|
558
|
+
kind: "queue.hold",
|
|
559
|
+
repo,
|
|
560
|
+
target
|
|
561
|
+
};
|
|
562
|
+
const key = yield* keyOf(caller, input, [
|
|
563
|
+
"queue.hold",
|
|
564
|
+
target,
|
|
565
|
+
input.reason
|
|
566
|
+
], yield* host.core.now);
|
|
567
|
+
const opened = yield* openKeyedQueue(host, caller, operation, target, key, input.internalId);
|
|
568
|
+
if (opened.kind === "answered") return opened.answer;
|
|
569
|
+
return yield* write(Effect.gen(function* () {
|
|
570
|
+
const state = yield* loadTarget(host.core.store, opened.internalId, target);
|
|
571
|
+
yield* unreserved(host, target, state.row.reserved);
|
|
572
|
+
yield* holdsLeft(state.row);
|
|
573
|
+
const plan = new QueuePlan(state, yield* host.core.now);
|
|
574
|
+
const answer = {
|
|
575
|
+
hold: {
|
|
576
|
+
id: addTargetHold(plan, input.reason),
|
|
577
|
+
repo: opened.name,
|
|
578
|
+
reason: input.reason,
|
|
579
|
+
target
|
|
580
|
+
},
|
|
581
|
+
revision: 0,
|
|
582
|
+
repeat: false
|
|
583
|
+
};
|
|
584
|
+
return {
|
|
585
|
+
...writing(caller, opened.name, plan),
|
|
586
|
+
answer,
|
|
587
|
+
...withKey(key)
|
|
588
|
+
};
|
|
589
|
+
}), opened.internalId, key);
|
|
590
|
+
});
|
|
591
|
+
const holdEntry = Effect.fnUntraced(function* (entry, input) {
|
|
592
|
+
const caller = callerOf(input);
|
|
593
|
+
yield* checkBytes("reason", input.reason, queueLimits.reasonBytes);
|
|
594
|
+
const opened = yield* openId(host, caller, "e", entry, (repo, row) => ({
|
|
595
|
+
kind: "queue.hold",
|
|
596
|
+
repo,
|
|
597
|
+
target: row.target,
|
|
598
|
+
entry
|
|
599
|
+
}));
|
|
600
|
+
const key = yield* keyOf(caller, input, [
|
|
601
|
+
"queue.hold",
|
|
602
|
+
entry,
|
|
603
|
+
input.reason
|
|
604
|
+
], yield* host.core.now);
|
|
605
|
+
return yield* write(Effect.gen(function* () {
|
|
606
|
+
const { target } = opened.row;
|
|
607
|
+
const state = yield* loadTarget(host.core.store, opened.internalId, target, { entries: [entry] });
|
|
608
|
+
const row = state.entries.get(entry) ?? opened.row;
|
|
609
|
+
if (!isOpen(row)) return yield* entryGone(entry, row.state);
|
|
610
|
+
yield* notMember(host, entry, row.topic);
|
|
611
|
+
yield* holdsLeft(state.row);
|
|
612
|
+
const plan = new QueuePlan(state, yield* host.core.now);
|
|
613
|
+
const id = plan.id("h");
|
|
614
|
+
if (row.state === "checking") supersede(plan, entry);
|
|
615
|
+
plan.setEntry(entry, {
|
|
616
|
+
...plan.entries.get(entry) ?? row,
|
|
617
|
+
state: "held"
|
|
618
|
+
});
|
|
619
|
+
plan.setHold(id, {
|
|
620
|
+
target,
|
|
621
|
+
reason: input.reason,
|
|
622
|
+
entry,
|
|
623
|
+
key: row.key
|
|
624
|
+
});
|
|
625
|
+
plan.setTarget({
|
|
626
|
+
...plan.row,
|
|
627
|
+
keyHolds: {
|
|
628
|
+
...plan.row.keyHolds,
|
|
629
|
+
[row.key]: [...keyHoldsOf(plan.row, row.key), id]
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
plan.event((envelope) => ({
|
|
633
|
+
type: "queue.hold.created",
|
|
634
|
+
...envelope,
|
|
635
|
+
hold: id,
|
|
636
|
+
reason: input.reason,
|
|
637
|
+
entry
|
|
638
|
+
}));
|
|
639
|
+
advanceAfter(plan);
|
|
640
|
+
const answer = {
|
|
641
|
+
hold: {
|
|
642
|
+
id,
|
|
643
|
+
repo: opened.name,
|
|
644
|
+
reason: input.reason,
|
|
645
|
+
entry
|
|
646
|
+
},
|
|
647
|
+
revision: 0,
|
|
648
|
+
repeat: false
|
|
649
|
+
};
|
|
650
|
+
return {
|
|
651
|
+
...writing(caller, opened.name, plan),
|
|
652
|
+
answer,
|
|
653
|
+
...withKey(key)
|
|
654
|
+
};
|
|
655
|
+
}), opened.internalId, key);
|
|
656
|
+
});
|
|
657
|
+
const release = Effect.fnUntraced(function* (hold, input) {
|
|
658
|
+
const caller = callerOf(input);
|
|
659
|
+
const opened = yield* openId(host, caller, "h", hold, (repo) => ({
|
|
660
|
+
kind: "queue.release",
|
|
661
|
+
repo,
|
|
662
|
+
hold
|
|
663
|
+
}));
|
|
664
|
+
const key = yield* keyOf(caller, input, ["queue.release", hold], yield* host.core.now);
|
|
665
|
+
const { work } = opened.row;
|
|
666
|
+
if (work !== void 0 && opened.row.released !== true) {
|
|
667
|
+
const scope = repoScope(opened.internalId);
|
|
668
|
+
const job = {
|
|
669
|
+
name: work.name,
|
|
670
|
+
key: work.key
|
|
671
|
+
};
|
|
672
|
+
const retry = storeCall(() => host.core.jobs.retry(scope, job));
|
|
673
|
+
const again = Effect.andThen(running(host, scope, work, hold), retry);
|
|
674
|
+
yield* retry.pipe(Effect.catchIf(notFailed, () => again.pipe(Effect.catchIf(notFailed, () => Effect.void))));
|
|
675
|
+
}
|
|
676
|
+
return yield* write(Effect.gen(function* () {
|
|
677
|
+
const state = yield* loadTarget(host.core.store, opened.internalId, opened.row.target, { holds: [hold] });
|
|
678
|
+
const row = state.holds.get(hold) ?? opened.row;
|
|
679
|
+
const answered = { hold };
|
|
680
|
+
if (row.entry !== void 0) answered.entry = row.entry;
|
|
681
|
+
if (row.released === true) return {
|
|
682
|
+
kind: "done",
|
|
683
|
+
answer: {
|
|
684
|
+
...answered,
|
|
685
|
+
revision: state.revision,
|
|
686
|
+
repeat: true
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
if (row.work?.claim !== work?.claim) return yield* failedAgain(hold);
|
|
690
|
+
const plan = new QueuePlan(state, yield* host.core.now);
|
|
691
|
+
releaseHold(plan, hold, row);
|
|
692
|
+
advanceAfter(plan);
|
|
693
|
+
const answer = {
|
|
694
|
+
...answered,
|
|
695
|
+
revision: 0,
|
|
696
|
+
repeat: false
|
|
697
|
+
};
|
|
698
|
+
return {
|
|
699
|
+
...writing(caller, opened.name, plan),
|
|
700
|
+
answer,
|
|
701
|
+
...withKey(key)
|
|
702
|
+
};
|
|
703
|
+
}), opened.internalId, key);
|
|
704
|
+
});
|
|
705
|
+
const report = Effect.fnUntraced(function* (candidate, input) {
|
|
706
|
+
const caller = callerOf(input);
|
|
707
|
+
if (input.summary !== void 0 && input.summary.length > queueLimits.summary) return yield* fail("INVALID_ARGUMENT", `A report's summary holds ${queueLimits.summary} characters at most`, { context: { field: "summary" } });
|
|
708
|
+
yield* checkBytes("url", input.url, queueLimits.urlBytes);
|
|
709
|
+
yield* checkBytes("meta", input.meta, queueLimits.metaBytes);
|
|
710
|
+
if (input.blame !== void 0 && input.verdict !== "fail") return yield* fail("INVALID_ARGUMENT", "Only a failing report blames entries", { context: { field: "blame" } });
|
|
711
|
+
const opened = yield* openId(host, caller, "c", candidate, (repo) => ({
|
|
712
|
+
kind: "queue.report",
|
|
713
|
+
repo,
|
|
714
|
+
candidate
|
|
715
|
+
}));
|
|
716
|
+
const blame = [...new Set(input.blame)];
|
|
717
|
+
const stray = blame.find((entry) => !opened.row.entries.includes(entry));
|
|
718
|
+
if (stray !== void 0) return yield* fail("INVALID_ARGUMENT", `'${stray}' isn't one of ${candidate}'s entries`, { context: { field: "blame" } });
|
|
719
|
+
const reportRow = { verdict: input.verdict };
|
|
720
|
+
if (input.summary !== void 0) reportRow.summary = input.summary;
|
|
721
|
+
if (input.url !== void 0) reportRow.url = input.url;
|
|
722
|
+
if (input.meta !== void 0) reportRow.meta = input.meta;
|
|
723
|
+
return yield* write(Effect.gen(function* () {
|
|
724
|
+
const state = yield* loadTarget(host.core.store, opened.internalId, opened.row.target, { candidates: [candidate] });
|
|
725
|
+
const row = state.candidates.get(candidate) ?? opened.row;
|
|
726
|
+
if (row.retried === true || row.reason === "superseded" || row.reason === "restarted") return yield* closedCandidate(candidate, row);
|
|
727
|
+
if (row.report !== void 0) {
|
|
728
|
+
if (row.report.verdict === input.verdict) return {
|
|
729
|
+
kind: "done",
|
|
730
|
+
answer: { repeat: true }
|
|
731
|
+
};
|
|
732
|
+
if (row.report.verdict === "cancel") return yield* closedCandidate(candidate, row);
|
|
733
|
+
return yield* fail("ALREADY_EXISTS", `${candidate} was reported '${row.report.verdict}' already`, { context: { verdict: row.report.verdict } });
|
|
734
|
+
}
|
|
735
|
+
if (row.state === "closed") return yield* closedCandidate(candidate, row);
|
|
736
|
+
if (row.state === "building") return yield* fail("FAILED_PRECONDITION", `${candidate} is still being built: report once it's opened`);
|
|
737
|
+
const plan = new QueuePlan(state, yield* host.core.now);
|
|
738
|
+
const reported = {
|
|
739
|
+
...row,
|
|
740
|
+
report: reportRow
|
|
741
|
+
};
|
|
742
|
+
if (blame.length > 0) reported.blame = blame;
|
|
743
|
+
plan.setCandidate(candidate, reported);
|
|
744
|
+
plan.setReport(candidate, reportRow);
|
|
745
|
+
plan.event((envelope) => {
|
|
746
|
+
const body = {
|
|
747
|
+
type: "queue.candidate.reported",
|
|
748
|
+
...envelope,
|
|
749
|
+
candidate,
|
|
750
|
+
...reportRow
|
|
751
|
+
};
|
|
752
|
+
if (reported.blame !== void 0) body.blame = reported.blame;
|
|
753
|
+
return body;
|
|
754
|
+
});
|
|
755
|
+
for (const entry of row.entries) {
|
|
756
|
+
const entryRow = plan.entries.get(entry);
|
|
757
|
+
if (entryRow !== void 0) plan.setEntry(entry, {
|
|
758
|
+
...entryRow,
|
|
759
|
+
judged: candidate
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
if (input.verdict === "cancel") {
|
|
763
|
+
closeCandidate(plan, candidate, "cancelled", { report: reportRow });
|
|
764
|
+
plan.setTarget({
|
|
765
|
+
...plan.row,
|
|
766
|
+
stalled: true
|
|
767
|
+
});
|
|
768
|
+
} else advanceAfter(plan);
|
|
769
|
+
return {
|
|
770
|
+
...writing(caller, opened.name, plan),
|
|
771
|
+
answer: { repeat: false }
|
|
772
|
+
};
|
|
773
|
+
}), opened.internalId, void 0);
|
|
774
|
+
});
|
|
775
|
+
const retry = Effect.fnUntraced(function* (candidate, input) {
|
|
776
|
+
const caller = callerOf(input);
|
|
777
|
+
const opened = yield* openId(host, caller, "c", candidate, (repo) => ({
|
|
778
|
+
kind: "queue.retry",
|
|
779
|
+
repo,
|
|
780
|
+
candidate
|
|
781
|
+
}));
|
|
782
|
+
const key = yield* keyOf(caller, input, ["queue.retry", candidate], yield* host.core.now);
|
|
783
|
+
return yield* write(Effect.gen(function* () {
|
|
784
|
+
const also = {
|
|
785
|
+
candidates: [candidate],
|
|
786
|
+
entries: opened.row.entries
|
|
787
|
+
};
|
|
788
|
+
const first = yield* loadTarget(host.core.store, opened.internalId, opened.row.target, also);
|
|
789
|
+
const keys = revivable(first, candidate).map(([, entryRow]) => entryRow.key);
|
|
790
|
+
const state = keys.length === 0 ? first : yield* loadTarget(host.core.store, opened.internalId, opened.row.target, {
|
|
791
|
+
...also,
|
|
792
|
+
keys
|
|
793
|
+
});
|
|
794
|
+
const row = state.candidates.get(candidate) ?? opened.row;
|
|
795
|
+
if (row.retried === true) return {
|
|
796
|
+
kind: "done",
|
|
797
|
+
answer: {
|
|
798
|
+
candidate,
|
|
799
|
+
revision: state.revision,
|
|
800
|
+
repeat: true
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
if (row.reason === "merged") return yield* closedCandidate(candidate, row);
|
|
804
|
+
const hadCommit = state.row.deleted === true || (state.row.tip ?? null) !== null;
|
|
805
|
+
if (state.tip === null && hadCommit) return yield* fail("FAILED_PRECONDITION", `${shortTarget(opened.row.target)} has no commit to retry onto`);
|
|
806
|
+
const member = opened.row.entries.map((one) => state.entries.get(one)?.topic).find(Boolean);
|
|
807
|
+
yield* notMember(host, candidate, member);
|
|
808
|
+
const plan = new QueuePlan(state, yield* host.core.now);
|
|
809
|
+
closeCandidate(plan, candidate, "superseded");
|
|
810
|
+
endSearch(plan, candidate);
|
|
811
|
+
const revived = yield* reviveEntries(plan, candidate);
|
|
812
|
+
if (!row.entries.some((entry) => {
|
|
813
|
+
const now = plan.entries.get(entry)?.state;
|
|
814
|
+
return now === "waiting" || now === "held";
|
|
815
|
+
})) return yield* closedCandidate(candidate, row);
|
|
816
|
+
retriedEvents(plan, revived, candidate);
|
|
817
|
+
plan.setCandidate(candidate, {
|
|
818
|
+
...plan.candidates.get(candidate) ?? row,
|
|
819
|
+
retried: true
|
|
820
|
+
});
|
|
821
|
+
const { stalled: _stalled, ...going } = plan.row;
|
|
822
|
+
plan.setTarget(going);
|
|
823
|
+
advanceAfter(plan);
|
|
824
|
+
const answer = {
|
|
825
|
+
candidate,
|
|
826
|
+
revision: 0,
|
|
827
|
+
repeat: false
|
|
828
|
+
};
|
|
829
|
+
return {
|
|
830
|
+
...writing(caller, opened.name, plan),
|
|
831
|
+
answer,
|
|
832
|
+
...withKey(key)
|
|
833
|
+
};
|
|
834
|
+
}), opened.internalId, key);
|
|
835
|
+
});
|
|
836
|
+
const restart = Effect.fnUntraced(function* (repo, input) {
|
|
837
|
+
const caller = callerOf(input);
|
|
838
|
+
const target = yield* targetOf(input.target);
|
|
839
|
+
const operation = {
|
|
840
|
+
kind: "queue.restart",
|
|
841
|
+
repo,
|
|
842
|
+
target
|
|
843
|
+
};
|
|
844
|
+
const key = yield* keyOf(caller, input, ["queue.restart", target], yield* host.core.now);
|
|
845
|
+
const opened = yield* openKeyedQueue(host, caller, operation, target, key, input.internalId);
|
|
846
|
+
if (opened.kind === "answered") return opened.answer;
|
|
847
|
+
return yield* write(Effect.gen(function* () {
|
|
848
|
+
const state = yield* loadTarget(host.core.store, opened.internalId, target);
|
|
849
|
+
const head = state.tip;
|
|
850
|
+
if (head === null) return yield* fail("FAILED_PRECONDITION", `${shortTarget(target)} has no commit to restart from`);
|
|
851
|
+
yield* unreserved(host, target, state.row.reserved);
|
|
852
|
+
const plan = new QueuePlan(state, yield* host.core.now);
|
|
853
|
+
restartTarget(plan, head);
|
|
854
|
+
const answer = {
|
|
855
|
+
target,
|
|
856
|
+
head,
|
|
857
|
+
revision: 0,
|
|
858
|
+
repeat: false
|
|
859
|
+
};
|
|
860
|
+
return {
|
|
861
|
+
...writing(caller, opened.name, plan),
|
|
862
|
+
answer,
|
|
863
|
+
...withKey(key)
|
|
864
|
+
};
|
|
865
|
+
}), opened.internalId, key);
|
|
866
|
+
});
|
|
867
|
+
const get = Effect.fnUntraced(function* (entry, input) {
|
|
868
|
+
const caller = callerOf(input);
|
|
869
|
+
const opened = yield* openId(host, caller, "e", entry, (repo) => ({
|
|
870
|
+
kind: "read",
|
|
871
|
+
repo
|
|
872
|
+
}));
|
|
873
|
+
return yield* answeredOne(host, opened, entry, opened.row);
|
|
874
|
+
});
|
|
875
|
+
const list = Effect.fnUntraced(function* (repo, input) {
|
|
876
|
+
const caller = callerOf(input);
|
|
877
|
+
const opened = yield* openQueue(host, caller, {
|
|
878
|
+
kind: "read",
|
|
879
|
+
repo
|
|
880
|
+
}, input.target, input.internalId);
|
|
881
|
+
const target = yield* targetOf(input.target ?? opened.options.target);
|
|
882
|
+
const read = (ids) => loadTarget(host.core.store, opened.internalId, target, { entries: ids }, "row");
|
|
883
|
+
const pageList = {
|
|
884
|
+
internalId: opened.internalId,
|
|
885
|
+
scope: target
|
|
886
|
+
};
|
|
887
|
+
const page = yield* entryPage(pageList, (yield* read([])).row.order, input.page);
|
|
888
|
+
const fresh = yield* read(page.ids);
|
|
889
|
+
const found = orderOf(fresh.row.order).flatMap(({ entry }) => {
|
|
890
|
+
const row = page.ids.includes(entry) ? fresh.entries.get(entry) : void 0;
|
|
891
|
+
return row === void 0 ? [] : [[entry, row]];
|
|
892
|
+
});
|
|
893
|
+
return listing(yield* answered(host, opened, found), page.next);
|
|
894
|
+
});
|
|
895
|
+
const repoHolds = Effect.fnUntraced(function* (repo, input) {
|
|
896
|
+
const caller = callerOf(input);
|
|
897
|
+
const opened = yield* openQueue(host, caller, {
|
|
898
|
+
kind: "read",
|
|
899
|
+
repo
|
|
900
|
+
}, input.target, input.internalId);
|
|
901
|
+
const target = yield* targetOf(input.target ?? opened.options.target);
|
|
902
|
+
const read = (ids) => loadTarget(host.core.store, opened.internalId, target, { holds: ids }, "row");
|
|
903
|
+
const pageList = {
|
|
904
|
+
internalId: opened.internalId,
|
|
905
|
+
scope: target
|
|
906
|
+
};
|
|
907
|
+
const page = yield* holdPage(pageList, openHolds((yield* read([])).row), input.page);
|
|
908
|
+
const fresh = yield* read(page.ids);
|
|
909
|
+
return listing(holdsIn(opened.name, fresh, page.ids, openHolds(fresh.row)), page.next);
|
|
910
|
+
});
|
|
911
|
+
const entryHolds = Effect.fnUntraced(function* (entry, input) {
|
|
912
|
+
const caller = callerOf(input);
|
|
913
|
+
const opened = yield* openId(host, caller, "e", entry, (repo) => ({
|
|
914
|
+
kind: "read",
|
|
915
|
+
repo
|
|
916
|
+
}));
|
|
917
|
+
const { key, target } = opened.row;
|
|
918
|
+
const isCurrent = (row) => row.order.some((place) => place.key === key && place.entry === entry);
|
|
919
|
+
const read = (ids) => loadTarget(host.core.store, opened.internalId, target, { holds: ids }, "row");
|
|
920
|
+
const pageList = {
|
|
921
|
+
internalId: opened.internalId,
|
|
922
|
+
scope: entry
|
|
923
|
+
};
|
|
924
|
+
const first = yield* read([]);
|
|
925
|
+
const keyHolds = keyHoldsOf(first.row, key);
|
|
926
|
+
if (isCurrent(first.row)) {
|
|
927
|
+
const page = yield* holdPage(pageList, keyHolds, input.page);
|
|
928
|
+
const fresh = yield* read(page.ids);
|
|
929
|
+
const own = (id) => isCurrent(fresh.row) || fresh.holds.get(id)?.entry === entry;
|
|
930
|
+
const open = keyHoldsOf(fresh.row, key).filter(own);
|
|
931
|
+
return listing(holdsIn(opened.name, fresh, page.ids, open), page.next);
|
|
932
|
+
}
|
|
933
|
+
const fresh = yield* read(keyHolds);
|
|
934
|
+
const open = keyHoldsOf(fresh.row, key).filter((id) => fresh.holds.get(id)?.entry === entry);
|
|
935
|
+
const page = yield* holdPage(pageList, open, input.page);
|
|
936
|
+
return listing(holdsIn(opened.name, fresh, page.ids, open), page.next);
|
|
937
|
+
});
|
|
938
|
+
return {
|
|
939
|
+
add,
|
|
940
|
+
remove,
|
|
941
|
+
hold: (...args) => queueIdParts("e", args[0]) === void 0 ? holdTarget(args[0], args[1]) : holdEntry(args[0], args[1]),
|
|
942
|
+
release,
|
|
943
|
+
report,
|
|
944
|
+
retry,
|
|
945
|
+
restart,
|
|
946
|
+
get,
|
|
947
|
+
list,
|
|
948
|
+
holds: (...args) => queueIdParts("e", args[0]) === void 0 ? repoHolds(args[0], args[1]) : entryHolds(args[0], args[1]),
|
|
949
|
+
candidates: Effect.fnUntraced(function* (repo, input) {
|
|
950
|
+
const caller = callerOf(input);
|
|
951
|
+
const opened = yield* openQueue(host, caller, {
|
|
952
|
+
kind: "read",
|
|
953
|
+
repo
|
|
954
|
+
}, input.target, input.internalId);
|
|
955
|
+
const target = yield* targetOf(input.target ?? opened.options.target);
|
|
956
|
+
if (!(yield* seesCandidates(host, caller, opened))) return listing([], void 0);
|
|
957
|
+
const read = (ids) => loadTarget(host.core.store, opened.internalId, target, { candidates: ids }, "row");
|
|
958
|
+
const pageList = {
|
|
959
|
+
internalId: opened.internalId,
|
|
960
|
+
scope: target
|
|
961
|
+
};
|
|
962
|
+
const page = yield* candidatePage(pageList, (yield* read([])).row.open, input.page);
|
|
963
|
+
const fresh = yield* read(page.ids);
|
|
964
|
+
const found = page.ids.flatMap((id) => {
|
|
965
|
+
const row = fresh.row.open.includes(id) ? fresh.candidates.get(id) : void 0;
|
|
966
|
+
return row === void 0 ? [] : [candidateOf(opened.name, id, row)];
|
|
967
|
+
});
|
|
968
|
+
return listing(found, page.next);
|
|
969
|
+
}),
|
|
970
|
+
candidate: Effect.fnUntraced(function* (id, input) {
|
|
971
|
+
const caller = callerOf(input);
|
|
972
|
+
const opened = yield* openId(host, caller, "c", id, (repo) => ({
|
|
973
|
+
kind: "read",
|
|
974
|
+
repo
|
|
975
|
+
}));
|
|
976
|
+
if (!(yield* seesCandidates(host, caller, opened))) return yield* unknownId("candidate", id);
|
|
977
|
+
return candidateOf(opened.name, id, opened.row);
|
|
978
|
+
})
|
|
979
|
+
};
|
|
980
|
+
};
|
|
981
|
+
/** The receipt a keyed call commits with its write, so the same call sent again answers it. */
|
|
982
|
+
const withKey = (key) => key === void 0 ? {} : { key };
|
|
983
|
+
/** An entry the queue is done with: merged, failed or removed. */
|
|
984
|
+
const entryGone = (entry, state) => fail("FAILED_PRECONDITION", `${entry} is ${state}: it left the queue`, { context: { reason: "entry-gone" } });
|
|
985
|
+
/** A report or a retry for a candidate that closed, with the reason its closing gives. */
|
|
986
|
+
const closedCandidate = (candidate, row) => {
|
|
987
|
+
const { reason } = row;
|
|
988
|
+
if (row.retried === true) return fail("FAILED_PRECONDITION", `${candidate} was retried: its report is stale`, { context: { reason: "candidate-superseded" } });
|
|
989
|
+
if (reason === "superseded" || reason === "restarted") return fail("FAILED_PRECONDITION", `${candidate} was ${reason}: its report is stale`, { context: { reason: "candidate-superseded" } });
|
|
990
|
+
if (reason === "cancelled" || reason === "timeout") return fail("FAILED_PRECONDITION", `${candidate} was cancelled`, { context: { reason: "candidate-cancelled" } });
|
|
991
|
+
return fail("FAILED_PRECONDITION", `${candidate}'s entries left the queue`, { context: { reason: "entry-gone" } });
|
|
992
|
+
};
|
|
993
|
+
/**
|
|
994
|
+
* Opens a candidate over `entries`, each waiting, for `git.queue.build` to build at `place`: its
|
|
995
|
+
* ID, which the entries name as checking. It builds on the tip, on the commit of the one candidate
|
|
996
|
+
* it stacks on, or on the tip carrying the entries of those it's built over. `previous`: the
|
|
997
|
+
* smallest `concurrency` among its lanes, which the target keeps.
|
|
998
|
+
*/
|
|
999
|
+
const openCandidate = (plan, entries, place, previous) => {
|
|
1000
|
+
const id = plan.id("c");
|
|
1001
|
+
const { tip, target } = plan.state;
|
|
1002
|
+
const row = {
|
|
1003
|
+
target,
|
|
1004
|
+
base: place.at === "stack" ? place.commit : tip,
|
|
1005
|
+
entries,
|
|
1006
|
+
state: "building"
|
|
1007
|
+
};
|
|
1008
|
+
if (place.at === "stack") row.over = [place.on];
|
|
1009
|
+
if (place.at === "carry") {
|
|
1010
|
+
row.over = place.over;
|
|
1011
|
+
row.carried = place.carried;
|
|
1012
|
+
}
|
|
1013
|
+
plan.setCandidate(id, row);
|
|
1014
|
+
plan.setTarget({
|
|
1015
|
+
...plan.row,
|
|
1016
|
+
open: [...plan.row.open, id],
|
|
1017
|
+
tip,
|
|
1018
|
+
previous
|
|
1019
|
+
});
|
|
1020
|
+
for (const entry of entries) {
|
|
1021
|
+
const entryRow = plan.entries.get(entry);
|
|
1022
|
+
if (entryRow === void 0) continue;
|
|
1023
|
+
plan.setEntry(entry, {
|
|
1024
|
+
...entryRow,
|
|
1025
|
+
state: "checking",
|
|
1026
|
+
candidate: id
|
|
1027
|
+
});
|
|
1028
|
+
setChecking(plan, entry, true);
|
|
1029
|
+
}
|
|
1030
|
+
plan.jobs.push(buildRow(id));
|
|
1031
|
+
return id;
|
|
1032
|
+
};
|
|
1033
|
+
/**
|
|
1034
|
+
* The entries `candidate`'s report failed, judged by it, `reported` or `interaction`, with their
|
|
1035
|
+
* rows: each one a `retry` of it brings back.
|
|
1036
|
+
*/
|
|
1037
|
+
const revivable = (queue, candidate) => [...queue.entries].filter(([, row]) => row.state === "failed" && row.judged === candidate && (row.failure === "reported" || row.failure === "interaction"));
|
|
1038
|
+
/**
|
|
1039
|
+
* Brings back each entry `candidate`'s report failed to the place it had, its ref made again,
|
|
1040
|
+
* unless its key has an open entry since or merged a newer one: the IDs it brought back.
|
|
1041
|
+
*/
|
|
1042
|
+
const reviveEntries = Effect.fnUntraced(function* (plan, candidate) {
|
|
1043
|
+
const revived = [];
|
|
1044
|
+
for (const [id, row] of revivable(plan, candidate)) {
|
|
1045
|
+
const open = plan.row.order.some((place) => place.key === row.key);
|
|
1046
|
+
const merged = plan.state.keys.get(row.key)?.entry;
|
|
1047
|
+
const newer = merged !== void 0 && (queueIdParts("e", merged)?.n ?? 0) > (queueIdParts("e", id)?.n ?? 0);
|
|
1048
|
+
if (open || newer) continue;
|
|
1049
|
+
if (plan.row.order.length >= queueLimits.openEntries) return yield* queueFull("open entries", queueLimits.openEntries);
|
|
1050
|
+
const { failure: _failure, place: kept, ...rest } = row;
|
|
1051
|
+
const place = {
|
|
1052
|
+
entry: id,
|
|
1053
|
+
key: row.key,
|
|
1054
|
+
priority: row.priority ?? 0,
|
|
1055
|
+
joined: kept?.joined ?? joinedAt(plan),
|
|
1056
|
+
since: kept?.since ?? plan.now
|
|
1057
|
+
};
|
|
1058
|
+
if (kept?.jumped !== void 0) place.jumped = kept.jumped;
|
|
1059
|
+
plan.setEntry(id, {
|
|
1060
|
+
...rest,
|
|
1061
|
+
state: held(plan, row) ? "held" : "waiting"
|
|
1062
|
+
});
|
|
1063
|
+
plan.setTarget({
|
|
1064
|
+
...plan.row,
|
|
1065
|
+
order: [...plan.row.order, place]
|
|
1066
|
+
});
|
|
1067
|
+
plan.edits.push({
|
|
1068
|
+
ref: queueRef(row.target, id),
|
|
1069
|
+
from: null,
|
|
1070
|
+
to: row.head
|
|
1071
|
+
});
|
|
1072
|
+
revived.push(id);
|
|
1073
|
+
}
|
|
1074
|
+
return revived;
|
|
1075
|
+
});
|
|
1076
|
+
/** The one place `queue.entry.retried` is made: each entry a retry of `candidate` brought back. */
|
|
1077
|
+
const retriedEvents = (plan, revived, candidate) => {
|
|
1078
|
+
for (const entry of revived) {
|
|
1079
|
+
plan.event((envelope) => {
|
|
1080
|
+
return {
|
|
1081
|
+
type: "queue.entry.retried",
|
|
1082
|
+
...envelope,
|
|
1083
|
+
entry,
|
|
1084
|
+
candidate
|
|
1085
|
+
};
|
|
1086
|
+
});
|
|
1087
|
+
const row = plan.entries.get(entry);
|
|
1088
|
+
if (row !== void 0 && isPinned(row)) pinnedEvent(plan, entry);
|
|
1089
|
+
}
|
|
1090
|
+
};
|
|
1091
|
+
/**
|
|
1092
|
+
* `queue.entry.pinned`: `entry` enters the order pinned, its hold begun, at the land conflict of
|
|
1093
|
+
* `candidate` that brought it to `landRestarts`, or by a retry that brought it back.
|
|
1094
|
+
*/
|
|
1095
|
+
const pinnedEvent = (plan, entry, candidate) => plan.event((envelope) => {
|
|
1096
|
+
const body = {
|
|
1097
|
+
type: "queue.entry.pinned",
|
|
1098
|
+
...envelope,
|
|
1099
|
+
entry
|
|
1100
|
+
};
|
|
1101
|
+
if (candidate !== void 0) body.candidate = candidate;
|
|
1102
|
+
return body;
|
|
1103
|
+
});
|
|
1104
|
+
/** Closes the target's open candidates, `restarted`, and rechecks from `head`. */
|
|
1105
|
+
const restartTarget = (plan, head) => {
|
|
1106
|
+
closeAll(plan, "restarted");
|
|
1107
|
+
const { stalled: _stalled, deleted: _deleted, ...going } = plan.row;
|
|
1108
|
+
plan.setTarget({
|
|
1109
|
+
...going,
|
|
1110
|
+
tip: head
|
|
1111
|
+
});
|
|
1112
|
+
plan.event((envelope, seq) => ({
|
|
1113
|
+
type: "queue.restarted",
|
|
1114
|
+
...envelope,
|
|
1115
|
+
target: plan.state.target,
|
|
1116
|
+
revision: seq,
|
|
1117
|
+
head
|
|
1118
|
+
}));
|
|
1119
|
+
advanceAfter(plan);
|
|
1120
|
+
};
|
|
1121
|
+
/** `UNAVAILABLE` for a release of `hold` whose job failed again since it was read. */
|
|
1122
|
+
const failedAgain = (hold) => fail("UNAVAILABLE", `${hold}'s job failed again since its release read it`, { hint: "Release it again" });
|
|
1123
|
+
/**
|
|
1124
|
+
* `UNAVAILABLE` while `work`'s job runs under any claim, its failure perhaps not yet settled, which
|
|
1125
|
+
* a release retries once it has.
|
|
1126
|
+
*/
|
|
1127
|
+
const running = Effect.fnUntraced(function* (host, scope, work, hold) {
|
|
1128
|
+
let after;
|
|
1129
|
+
do {
|
|
1130
|
+
const page = after === void 0 ? {} : { page: { after } };
|
|
1131
|
+
const listed = yield* storeCall(() => host.core.jobs.list(scope, {
|
|
1132
|
+
state: "running",
|
|
1133
|
+
...page
|
|
1134
|
+
}));
|
|
1135
|
+
if (listed.items.some((job) => job.name === work.name && job.key === work.key)) {
|
|
1136
|
+
const message = `${hold}'s job is running, so its release waits for it to settle`;
|
|
1137
|
+
return yield* fail("UNAVAILABLE", message, { hint: "Release it again" });
|
|
1138
|
+
}
|
|
1139
|
+
after = listed.next;
|
|
1140
|
+
} while (after !== void 0);
|
|
1141
|
+
});
|
|
1142
|
+
/** A page of `items`, with `next` while one is left. */
|
|
1143
|
+
const listing = (items, next) => next === void 0 ? { items } : {
|
|
1144
|
+
items,
|
|
1145
|
+
next
|
|
1146
|
+
};
|
|
1147
|
+
/** The holds of a page's `ids` that `fresh` read and still names in `open`. */
|
|
1148
|
+
const holdsIn = (repo, fresh, ids, open) => ids.flatMap((id) => {
|
|
1149
|
+
const row = open.includes(id) ? fresh.holds.get(id) : void 0;
|
|
1150
|
+
return row === void 0 ? [] : [holdOf(repo, id, row)];
|
|
1151
|
+
});
|
|
1152
|
+
/** `queue-full` once a target holds `queueLimits.holds` open holds, its own and its keys'. */
|
|
1153
|
+
const holdsLeft = (row) => openHolds(row).length >= queueLimits.holds ? queueFull("holds", queueLimits.holds) : Effect.void;
|
|
1154
|
+
export { addAdmitted, admitEntry, openCandidate, openEntry, openQueue, pinnedEvent, queueCalls, restartTarget };
|