@ref0/git 0.11.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access/private-refs.mjs +8 -7
- package/dist/auth/auth.d.mts +2 -2
- package/dist/auth/auth.mjs +3 -6
- package/dist/auth/authorize.mjs +1 -17
- package/dist/auth/helpers.mjs +3 -11
- package/dist/auth/host-services.mjs +11 -0
- package/dist/auth/policy.d.mts +27 -7
- package/dist/auth/policy.mjs +8 -4
- package/dist/auth/tokens-layer.d.mts +1 -2
- package/dist/auth/tokens-layer.mjs +2 -3
- package/dist/auth/tokens-public.d.mts +3 -3
- package/dist/auth/tokens.d.mts +1 -8
- package/dist/auth/tokens.mjs +1 -8
- package/dist/auth.d.mts +1 -4
- package/dist/auth.mjs +1 -3
- package/dist/client/git-http.mjs +18 -4
- package/dist/client/push-upload.mjs +33 -7
- package/dist/client/remote.mjs +94 -28
- package/dist/client/slice-push.d.mts +1 -1
- package/dist/contracts/access.d.mts +8 -8
- package/dist/contracts/actors.d.mts +2 -34
- package/dist/contracts/blobs.d.mts +2 -2
- package/dist/contracts/client.d.mts +8 -3
- package/dist/contracts/commits.d.mts +10 -2
- package/dist/contracts/commits.mjs +9 -1
- package/dist/contracts/files.d.mts +2 -2
- package/dist/contracts/forks.d.mts +14 -3
- package/dist/contracts/git.d.mts +41 -12
- package/dist/contracts/git.mjs +3 -2
- package/dist/contracts/lfs.d.mts +0 -7
- package/dist/contracts/objects.d.mts +80 -10
- package/dist/contracts/operations.d.mts +3 -0
- package/dist/contracts/operations.mjs +12 -2
- package/dist/contracts/push-uploads.d.mts +44 -5
- package/dist/contracts/push-uploads.mjs +7 -3
- package/dist/contracts/refs.d.mts +28 -6
- package/dist/contracts/remote.mjs +1 -3
- package/dist/contracts/repo-records.d.mts +1 -0
- package/dist/contracts/repos.d.mts +90 -2
- package/dist/contracts/repos.mjs +29 -2
- package/dist/contracts/result.d.mts +30 -23
- package/dist/contracts/result.mjs +24 -9
- package/dist/contracts/rules.d.mts +22 -22
- package/dist/contracts/server.d.mts +28 -77
- package/dist/contracts/signin.d.mts +1 -1
- package/dist/contracts/sync.d.mts +90 -19
- package/dist/contracts/sync.mjs +34 -10
- package/dist/contracts/tokens.d.mts +1 -6
- package/dist/contracts/tokens.mjs +1 -2
- package/dist/contracts/topics.d.mts +0 -5
- package/dist/contracts/work.d.mts +66 -2
- package/dist/contracts/work.mjs +8 -1
- package/dist/core/access.d.mts +1 -0
- package/dist/core/access.mjs +34 -13
- package/dist/core/ancestry.d.mts +9 -0
- package/dist/core/ancestry.mjs +6 -6
- package/dist/core/asked.mjs +68 -0
- package/dist/core/call-names.mjs +1 -0
- package/dist/core/call-services.mjs +2 -1
- package/dist/core/events/deliver.d.mts +1 -0
- package/dist/core/events/deliver.mjs +15 -3
- package/dist/core/forks.mjs +42 -16
- package/dist/core/imports.mjs +156 -13
- package/dist/core/index-job.mjs +9 -6
- package/dist/core/job-view.mjs +8 -9
- package/dist/core/mirror-rows.mjs +19 -4
- package/dist/core/objects/commits.mjs +16 -6
- package/dist/core/objects/reading.mjs +17 -9
- package/dist/core/parts.d.mts +8 -2
- package/dist/core/parts.mjs +1 -4
- package/dist/core/purge.mjs +76 -6
- package/dist/core/push-decide.mjs +1 -1
- package/dist/core/push-files.d.mts +12 -0
- package/dist/core/push-files.mjs +225 -0
- package/dist/core/push-repo.d.mts +8 -0
- package/dist/core/push-repo.mjs +56 -0
- package/dist/core/push.d.mts +17 -0
- package/dist/core/push.mjs +107 -32
- package/dist/core/receipts.mjs +26 -10
- package/dist/core/ref-view.mjs +59 -5
- package/dist/core/refs.mjs +18 -10
- package/dist/core/registered-rows.mjs +7 -5
- package/dist/core/repack.mjs +16 -11
- package/dist/core/repo-info.mjs +16 -9
- package/dist/core/repos.mjs +30 -14
- package/dist/core/saved-caller-views.d.mts +18 -0
- package/dist/core/saved-caller-views.mjs +17 -4
- package/dist/core/saved-callers-public.d.mts +3 -3
- package/dist/core/saved-callers-public.mjs +3 -2
- package/dist/core/saved-callers.d.mts +7 -0
- package/dist/core/seam.mjs +2 -2
- package/dist/core/view.d.mts +6 -0
- package/dist/core/view.mjs +45 -12
- package/dist/core/work.mjs +47 -22
- package/dist/effect.d.mts +3 -1
- package/dist/effect.mjs +3 -1
- package/dist/engine/reads.mjs +13 -6
- package/dist/engine/walk.mjs +4 -4
- package/dist/event-streams/event-streams.d.mts +1 -1
- package/dist/event-streams/event-streams.mjs +1 -1
- package/dist/event-streams/stream.d.mts +1 -1
- package/dist/event-streams/stream.mjs +1 -1
- package/dist/extend.d.mts +4 -3
- package/dist/extend.mjs +3 -2
- package/dist/http/answers.mjs +4 -2
- package/dist/http/core-parts.mjs +64 -15
- package/dist/http/handler.mjs +2 -2
- package/dist/http/node.mjs +5 -4
- package/dist/http/parts.d.mts +1 -0
- package/dist/http/push-upload-job.mjs +503 -0
- package/dist/http/push-uploads.d.mts +1 -0
- package/dist/http/push-uploads.mjs +120 -59
- package/dist/http/upload-pack.mjs +7 -6
- package/dist/index.d.mts +23 -24
- package/dist/index.mjs +4 -7
- package/dist/lfs/base.d.mts +7 -3
- package/dist/lfs/base.mjs +2 -1
- package/dist/lfs/copy.d.mts +46 -0
- package/dist/lfs/copy.mjs +26 -0
- package/dist/lfs/layer.mjs +4 -2
- package/dist/lfs/locks.mjs +14 -9
- package/dist/lfs/objects.d.mts +6 -0
- package/dist/lfs/objects.mjs +95 -61
- package/dist/lfs/rows.d.mts +13 -0
- package/dist/lfs/service.d.mts +1 -7
- package/dist/lfs/service.mjs +1 -9
- package/dist/lfs/upload-most.mjs +5 -5
- package/dist/node.d.mts +2 -2
- package/dist/protocol/bytes/sha256-hasher.d.mts +15 -0
- package/dist/protocol/bytes/sha256.d.mts +32 -0
- package/dist/protocol/bytes/sha256.mjs +105 -49
- package/dist/protocol/wire/advertisement.mjs +9 -4
- package/dist/protocol/wire/lines.d.mts +4 -2
- package/dist/protocol/wire/lines.mjs +11 -5
- package/dist/protocol/wire/push-uploads.mjs +13 -1
- package/dist/protocol/wire/v2.mjs +2 -2
- package/dist/protocol.d.mts +3 -1
- package/dist/protocol.mjs +3 -1
- package/dist/queue/advance.mjs +1 -1
- package/dist/queue/calls.mjs +21 -1
- package/dist/queue/host.d.mts +1 -7
- package/dist/queue/host.mjs +1 -7
- package/dist/queue/layer.mjs +1 -1
- package/dist/queue/trim.mjs +1 -1
- package/dist/rest/blobs.d.mts +16 -8
- package/dist/rest/blobs.mjs +1 -1
- package/dist/rest/caller.d.mts +49 -9
- package/dist/rest/caller.mjs +1 -1
- package/dist/rest/client.d.mts +10 -3
- package/dist/rest/client.mjs +4 -0
- package/dist/rest/commits.d.mts +272 -239
- package/dist/rest/errors.d.mts +24 -4
- package/dist/rest/events.d.mts +9 -6
- package/dist/rest/events.mjs +1 -2
- package/dist/rest/files.d.mts +112 -100
- package/dist/rest/forks.d.mts +146 -122
- package/dist/rest/handler.mjs +4 -57
- package/dist/rest/handlers.d.mts +1 -1
- package/dist/rest/handlers.mjs +18 -4
- package/dist/rest/layer.mjs +10 -2
- package/dist/rest/me.d.mts +8 -4
- package/dist/rest/merges.d.mts +8 -4
- package/dist/rest/paths.mjs +1 -0
- package/dist/rest/queue.d.mts +292 -236
- package/dist/rest/refs.d.mts +98 -69
- package/dist/rest/repos.d.mts +133 -105
- package/dist/rest/tags.d.mts +100 -88
- package/dist/rest/tokens.d.mts +192 -168
- package/dist/rest/topics.d.mts +154 -134
- package/dist/rest/trees.d.mts +32 -16
- package/dist/rest/work.d.mts +467 -20
- package/dist/rest/work.mjs +8 -0
- package/dist/server/edge-node.d.mts +9 -13
- package/dist/server/edge-node.mjs +9 -12
- package/dist/server/git-layer.d.mts +1 -6
- package/dist/server/git-layer.mjs +2 -2
- package/dist/server/git-namespace.d.mts +4 -4
- package/dist/server/joined.d.mts +15 -22
- package/dist/server/joined.mjs +5 -29
- package/dist/server/lifecycle.mjs +107 -23
- package/dist/server/registry.mjs +9 -1
- package/dist/server/server.mjs +139 -216
- package/dist/storage/budget.mjs +2 -2
- package/dist/storage/clean-up.mjs +13 -10
- package/dist/storage/fetch.mjs +13 -8
- package/dist/storage/file-limits.mjs +24 -0
- package/dist/storage/index-build.d.mts +1 -0
- package/dist/storage/index-build.mjs +106 -62
- package/dist/storage/index-fetch.mjs +16 -3
- package/dist/storage/index-reach.mjs +33 -5
- package/dist/storage/index-remap.mjs +8 -1
- package/dist/storage/index-shallow.mjs +5 -3
- package/dist/storage/largest-files.mjs +48 -0
- package/dist/storage/lfs-pointers.mjs +10 -1
- package/dist/storage/loose.mjs +3 -1
- package/dist/storage/memory-budget.mjs +154 -8
- package/dist/storage/merge-cut.mjs +5 -4
- package/dist/storage/pack-reads.mjs +246 -34
- package/dist/storage/pack-receive.mjs +83 -25
- package/dist/storage/packs.mjs +37 -21
- package/dist/storage/prune-keep.mjs +203 -34
- package/dist/storage/prune-seen.mjs +11 -6
- package/dist/storage/prune-walk.mjs +219 -81
- package/dist/storage/prune.mjs +629 -196
- package/dist/storage/push-uploads.mjs +36 -12
- package/dist/storage/quarantine.mjs +9 -7
- package/dist/storage/ready.mjs +47 -19
- package/dist/storage/receive-bounds.mjs +29 -8
- package/dist/storage/receive-state.mjs +8 -0
- package/dist/storage/receive-steps.mjs +71 -18
- package/dist/storage/repack.d.mts +1 -1
- package/dist/storage/repack.mjs +1 -8
- package/dist/storage/rows.mjs +12 -1
- package/dist/storage/shallow.d.mts +1 -0
- package/dist/storage/shallow.mjs +26 -4
- package/dist/storage/stream-whole.mjs +5 -2
- package/dist/storage/visible.mjs +29 -1
- package/dist/storage/walk.mjs +2 -1
- package/dist/store/catalogue.mjs +1 -0
- package/dist/store/cursor-seal-namespace.d.mts +2 -0
- package/dist/store/cursor-seal-public.d.mts +5 -0
- package/dist/store/cursor-seal-public.mjs +5 -0
- package/dist/store/cursor-seal.d.mts +16 -2
- package/dist/store/cursor-seal.mjs +26 -14
- package/dist/store/errors.mjs +9 -1
- package/dist/store/records.d.mts +2 -0
- package/dist/store/records.mjs +9 -6
- package/dist/store/repo-record.d.mts +27 -0
- package/dist/store/repo-record.mjs +141 -4
- package/dist/store/scopes.mjs +10 -2
- package/dist/sync/bound.d.mts +2 -0
- package/dist/sync/bound.mjs +11 -2
- package/dist/sync/github.d.mts +6 -1
- package/dist/sync/github.mjs +63 -42
- package/dist/sync/http.mjs +36 -1
- package/dist/sync/import.mjs +4 -2
- package/dist/sync/layer.mjs +6 -2
- package/dist/sync/lfs-batch.mjs +119 -0
- package/dist/sync/lfs-copy.mjs +251 -0
- package/dist/sync/mirror.mjs +227 -147
- package/dist/sync/said.mjs +204 -0
- package/dist/sync/smart-http.mjs +4 -2
- package/dist/sync/step.mjs +33 -13
- package/dist/sync/tries.mjs +71 -24
- package/dist/sync.d.mts +2 -2
- package/dist/topics/advance.mjs +10 -3
- package/dist/topics/host.mjs +1 -19
- package/dist/topics/layer.mjs +1 -1
- package/package.json +3 -8
- package/dist/auth/bridge.mjs +0 -30
- package/dist/auth/helpers.d.mts +0 -17
- package/dist/core/purge.d.mts +0 -8
- package/dist/core/registered-rows.d.mts +0 -4
- package/dist/core/repack.d.mts +0 -11
- package/dist/http/handler.d.mts +0 -2
- package/dist/rest/handler.d.mts +0 -21
- package/dist/rest.d.mts +0 -2
- package/dist/rest.mjs +0 -1
- package/dist/server/registry.d.mts +0 -16
- package/dist/server/server.d.mts +0 -36
- package/dist/storage/repack-job.d.mts +0 -3
- package/dist/topics/host.d.mts +0 -7
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import "../contracts/git.mjs";
|
|
2
|
+
import { InternalRepoId } from "../contracts/ids.mjs";
|
|
3
|
+
import "../contracts/objects.mjs";
|
|
4
|
+
import { GitError } from "../contracts/result.mjs";
|
|
5
|
+
import { LfsStaging } from "./objects.mjs";
|
|
6
|
+
import { ListedRow } from "./rows.mjs";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import { Key, Row } from "@ref0/infra";
|
|
9
|
+
import * as Stream from "effect/Stream";
|
|
10
|
+
/**
|
|
11
|
+
* What import's copy of a source's Git LFS objects goes through, once `Lfs.layer` attached
|
|
12
|
+
* (#2397): LFS's own rows and bucket, as a Worker upload uses them, so a copied object is listed
|
|
13
|
+
* as an uploaded one is, and bytes that never list are deleted by upkeep as theirs are.
|
|
14
|
+
*/
|
|
15
|
+
export interface LfsCopy {
|
|
16
|
+
/** Of `oids`, those `repo` lists, with their rows. */
|
|
17
|
+
readonly listed: (repo: InternalRepoId, oids: readonly string[]) => Effect.Effect<ReadonlyMap<string, ListedRow>, GitError>;
|
|
18
|
+
/**
|
|
19
|
+
* A staging key for each of `count` objects, each row added with upkeep's wake at its
|
|
20
|
+
* `removeAt`, `uploadGrace` from now: bytes put there that no commit lists are deleted then.
|
|
21
|
+
*/
|
|
22
|
+
readonly stage: (repo: InternalRepoId, count: number) => Effect.Effect<readonly LfsStaging[], GitError>;
|
|
23
|
+
/**
|
|
24
|
+
* `body`, `size` bytes whose SHA-256 is `oid`, put at `staging`'s key with nothing buffered, the
|
|
25
|
+
* bucket checking the SHA-256: other bytes fail `INVALID_ARGUMENT`, keeping nothing. No
|
|
26
|
+
* interrupt cuts it short, for the reason `bucketPut` gives, so `body` must end or fail of
|
|
27
|
+
* itself, as import's download does once its try's signal aborts.
|
|
28
|
+
*/
|
|
29
|
+
readonly put: (staging: LfsStaging, body: Stream.Stream<Uint8Array, GitError>, size: number, oid: string) => Effect.Effect<void, GitError>;
|
|
30
|
+
/**
|
|
31
|
+
* The writes that list each of `landed` at its staging key and drop its staging row, for the
|
|
32
|
+
* copy's own commit, which moves its cursor with them. A staged object that didn't land keeps
|
|
33
|
+
* its row: a put that failed may still have stored its bytes, so upkeep deletes them at
|
|
34
|
+
* `removeAt`.
|
|
35
|
+
*/
|
|
36
|
+
readonly listing: (landed: readonly LfsLanded[]) => {
|
|
37
|
+
readonly put: readonly Row[];
|
|
38
|
+
readonly delete: readonly Key[];
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** An object the copy put, checked, at its staging key. */
|
|
42
|
+
export interface LfsLanded {
|
|
43
|
+
readonly oid: string;
|
|
44
|
+
readonly size: number;
|
|
45
|
+
readonly staging: LfsStaging;
|
|
46
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { bucketDo } from "../storage/calls.mjs";
|
|
2
|
+
import { listedOf, stagedKeys } from "./objects.mjs";
|
|
3
|
+
import { listedKey, uploadGrace } from "./rows.mjs";
|
|
4
|
+
import * as Clock$1 from "effect/Clock";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
// src/lfs/copy.ts
|
|
7
|
+
/** The copy over LFS's registration's rows and its bucket. */
|
|
8
|
+
const lfsCopy = (rows, bucket) => ({
|
|
9
|
+
listed: (repo, oids) => listedOf(rows, repo, oids),
|
|
10
|
+
stage: (repo, count) => Effect.flatMap(Clock$1.currentTimeMillis, (now) => stagedKeys(rows, repo, now + uploadGrace, count)),
|
|
11
|
+
put: (staging, body, size, oid) => Effect.asVoid(Effect.uninterruptible(bucketDo(bucket.put(staging.key, body, {
|
|
12
|
+
size,
|
|
13
|
+
sha256: oid
|
|
14
|
+
})))),
|
|
15
|
+
listing: (landed) => ({
|
|
16
|
+
put: landed.map(({ oid, size, staging }) => ({
|
|
17
|
+
...listedKey(oid),
|
|
18
|
+
value: {
|
|
19
|
+
size,
|
|
20
|
+
key: staging.key
|
|
21
|
+
}
|
|
22
|
+
})),
|
|
23
|
+
delete: landed.map(({ staging }) => staging.row)
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
export { lfsCopy };
|
package/dist/lfs/layer.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { register } from "../contracts/git.mjs";
|
|
|
2
2
|
import { callerFor, resolvedAs } from "../core/access.mjs";
|
|
3
3
|
import { seenIn } from "../core/objects/reading.mjs";
|
|
4
4
|
import { LfsBase } from "./base.mjs";
|
|
5
|
+
import { lfsCopy } from "./copy.mjs";
|
|
5
6
|
import { objectOf } from "./objects.mjs";
|
|
6
7
|
import { pointerCheck } from "./pointers.mjs";
|
|
7
8
|
import { lfsPurge } from "./purge.mjs";
|
|
@@ -24,7 +25,7 @@ var Lfs = class extends (/* @__PURE__ */ Context.Service()("@ref0/git/Lfs")) {};
|
|
|
24
25
|
const lfsRegistration = /* @__PURE__ */ Effect.fnUntraced(function* (registration, options = {}) {
|
|
25
26
|
const base = yield* LfsBase;
|
|
26
27
|
const { needs, bucket, links, requestLimits } = base;
|
|
27
|
-
if (bucket === void 0) return yield* Effect.die(/* @__PURE__ */ new TypeError("
|
|
28
|
+
if (bucket === void 0) return yield* Effect.die(/* @__PURE__ */ new TypeError("Lfs.layer() keeps its objects in the host's bucket: provide Bucket.Bucket"));
|
|
28
29
|
const caps = {
|
|
29
30
|
bodyCap: options.bodyCap ?? requestLimits.bodyBytes,
|
|
30
31
|
cpuMs: options.cpuMs ?? requestLimits.cpuMs
|
|
@@ -51,7 +52,8 @@ const lfsRegistration = /* @__PURE__ */ Effect.fnUntraced(function* (registratio
|
|
|
51
52
|
seen: (blobs) => Effect.provideContext(Effect.flatMap(resolvedAs(input.repo, input.objects.repo), (resolved) => seenIn(input.caller, resolved, blobs)), needs)
|
|
52
53
|
})
|
|
53
54
|
},
|
|
54
|
-
read
|
|
55
|
+
read,
|
|
56
|
+
copy: lfsCopy(registration.rows, bucket)
|
|
55
57
|
});
|
|
56
58
|
yield* registration.addUpkeep(lfsUpkeep(registration.rows, bucket, links !== void 0));
|
|
57
59
|
yield* registration.addPurge(lfsPurge(registration.rows, bucket));
|
package/dist/lfs/locks.mjs
CHANGED
|
@@ -45,10 +45,11 @@ const ownerOf = (caller) => caller.actor.anonymous === true ? fail("UNAUTHENTICA
|
|
|
45
45
|
const createLock = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
|
|
46
46
|
const { path } = yield* bodyOf(call.request, LockCreate);
|
|
47
47
|
const owner = yield* ownerOf(call.caller);
|
|
48
|
-
const repo = yield* openFor(call.caller, call.repo, true);
|
|
48
|
+
const repo = yield* openFor(call.caller, call.repo, true, void 0, "first-read");
|
|
49
49
|
const id = pathRowId(path);
|
|
50
50
|
for (let tries = 0; tries < 5; tries += 1) {
|
|
51
|
-
const
|
|
51
|
+
const asked = tries === 0 ? repo : void 0;
|
|
52
|
+
const read = yield* parts.rows.readFenced(call.caller, repo, [lockRead(id)], asked);
|
|
52
53
|
const held = read.results[0]?.[0];
|
|
53
54
|
if (held !== void 0) return lfsAnswer(409, {
|
|
54
55
|
lock: yield* lockOf(held),
|
|
@@ -70,14 +71,17 @@ const createLock = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
|
|
|
70
71
|
}
|
|
71
72
|
return yield* contended();
|
|
72
73
|
});
|
|
73
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* One page of the repo's locks, after `cursor`, with the next page's cursor when there's one: the
|
|
76
|
+
* first read since the repo opened, so held to what was asked, as `asAsked` says.
|
|
77
|
+
*/
|
|
74
78
|
const pageOfLocks = /* @__PURE__ */ Effect.fnUntraced(function* (parts, repo, cursor, limit) {
|
|
75
79
|
const read = {
|
|
76
80
|
collection: lfsCollections.locks,
|
|
77
81
|
limit: limit + 1
|
|
78
82
|
};
|
|
79
83
|
if (cursor !== void 0) read.after = cursor;
|
|
80
|
-
const rows = (yield* parts.rows.read(repo.internalId, [read])).results[0] ?? [];
|
|
84
|
+
const rows = (yield* parts.rows.read(repo.internalId, [read], repo)).results[0] ?? [];
|
|
81
85
|
const locks = yield* Effect.forEach(rows.slice(0, limit), lockOf);
|
|
82
86
|
const last = rows[limit - 1];
|
|
83
87
|
return {
|
|
@@ -89,12 +93,12 @@ const pageOfLocks = /* @__PURE__ */ Effect.fnUntraced(function* (parts, repo, cu
|
|
|
89
93
|
const listLocks = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
|
|
90
94
|
const query = new URL(call.request.url).searchParams;
|
|
91
95
|
const { limit = 100 } = yield* queryOf(query);
|
|
92
|
-
const repo = yield* openFor(call.caller, call.repo, false);
|
|
96
|
+
const repo = yield* openFor(call.caller, call.repo, false, void 0, "first-read");
|
|
93
97
|
const path = query.get("path");
|
|
94
98
|
const id = query.get("id");
|
|
95
99
|
const wanted = id !== null ? lockIdParts(id) : path === null ? void 0 : { row: pathRowId(path) };
|
|
96
100
|
if (wanted !== void 0) {
|
|
97
|
-
const row = (yield* parts.rows.read(repo.internalId, [lockRead(wanted.row)])).results[0]?.[0];
|
|
101
|
+
const row = (yield* parts.rows.read(repo.internalId, [lockRead(wanted.row)], repo)).results[0]?.[0];
|
|
98
102
|
const lock = row === void 0 ? void 0 : yield* lockOf(row);
|
|
99
103
|
const named = lock !== void 0 && (id === null || lock.id === id);
|
|
100
104
|
return lfsAnswer(200, { locks: named ? [lock] : [] });
|
|
@@ -117,7 +121,7 @@ const verifyLocks = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
|
|
|
117
121
|
const body = yield* bodyOf(call.request, LockVerify);
|
|
118
122
|
const owner = yield* ownerOf(call.caller);
|
|
119
123
|
const limit = body.limit ?? 100;
|
|
120
|
-
const repo = yield* openFor(call.caller, call.repo, true);
|
|
124
|
+
const repo = yield* openFor(call.caller, call.repo, true, void 0, "first-read");
|
|
121
125
|
const page = yield* pageOfLocks(parts, repo, body.cursor, limit);
|
|
122
126
|
const ours = page.locks.filter((lock) => lock.owner.name === owner);
|
|
123
127
|
const theirs = page.locks.filter((lock) => lock.owner.name !== owner);
|
|
@@ -130,10 +134,11 @@ const verifyLocks = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
|
|
|
130
134
|
const unlock = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, id) {
|
|
131
135
|
const { force = false } = yield* bodyOf(call.request, Unlock);
|
|
132
136
|
const owner = yield* ownerOf(call.caller);
|
|
133
|
-
const repo = yield* openFor(call.caller, call.repo, true);
|
|
137
|
+
const repo = yield* openFor(call.caller, call.repo, true, void 0, "first-read");
|
|
134
138
|
const { row: rowId } = lockIdParts(id);
|
|
135
139
|
for (let tries = 0; tries < 5; tries += 1) {
|
|
136
|
-
const
|
|
140
|
+
const asked = tries === 0 ? repo : void 0;
|
|
141
|
+
const read = yield* parts.rows.readFenced(call.caller, repo, [lockRead(rowId)], asked);
|
|
137
142
|
const row = read.results[0]?.[0];
|
|
138
143
|
const lock = row === void 0 ? void 0 : yield* lockOf(row);
|
|
139
144
|
if (lock?.id !== id) return yield* fail("NOT_FOUND", "No such lock");
|
package/dist/lfs/objects.d.mts
CHANGED
|
@@ -5,6 +5,7 @@ import "../contracts/git.mjs";
|
|
|
5
5
|
import { InternalRepoId, RepoName } from "../contracts/ids.mjs";
|
|
6
6
|
import "../contracts/result.mjs";
|
|
7
7
|
import "effect/Effect";
|
|
8
|
+
import { Key } from "@ref0/infra";
|
|
8
9
|
/** One request to a repo's `info/lfs/`, from a caller `identify` answered. */
|
|
9
10
|
export interface LfsCall {
|
|
10
11
|
readonly caller: Caller;
|
|
@@ -13,6 +14,11 @@ export interface LfsCall {
|
|
|
13
14
|
/** The repo's URL as the client named it, which a Worker's links point under. */
|
|
14
15
|
readonly repoUrl: string;
|
|
15
16
|
}
|
|
17
|
+
/** An object's staging key in the bucket, and the row that has upkeep delete it unless listed. */
|
|
18
|
+
export interface LfsStaging {
|
|
19
|
+
readonly key: string;
|
|
20
|
+
readonly row: Key;
|
|
21
|
+
}
|
|
16
22
|
/** What `objectOf` reads: an object of `repo`'s, for `caller`, of `size` when it's given. */
|
|
17
23
|
export interface ObjectRead {
|
|
18
24
|
readonly caller: Caller;
|
package/dist/lfs/objects.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { nativeSha256Hasher } from "../protocol/bytes/sha256-hasher.mjs";
|
|
2
1
|
import { gathered } from "../protocol/bytes/streams.mjs";
|
|
3
2
|
import { contended, openFor } from "../core/access.mjs";
|
|
4
3
|
import { ownWriter } from "../core/own-writes.mjs";
|
|
@@ -19,6 +18,7 @@ import { fail, gitError, httpStatus } from "../contracts/result.mjs";
|
|
|
19
18
|
import * as Clock$1 from "effect/Clock";
|
|
20
19
|
import * as Effect from "effect/Effect";
|
|
21
20
|
import * as Option from "effect/Option";
|
|
21
|
+
import * as Result from "effect/Result";
|
|
22
22
|
import { Unavailable } from "@ref0/infra";
|
|
23
23
|
import * as Stream from "effect/Stream";
|
|
24
24
|
import * as DateTime from "effect/DateTime";
|
|
@@ -26,12 +26,13 @@ import * as DateTime from "effect/DateTime";
|
|
|
26
26
|
/**
|
|
27
27
|
* Each object's rows, read with the repo's record and the fence's rows at one version, the fence
|
|
28
28
|
* checked; `also`'s rows after them. An object's upload row is the caller's own, as `uploader`
|
|
29
|
-
* names it. A repo deleted since it opened is `NOT_FOUND
|
|
29
|
+
* names it. A repo deleted since it opened is `NOT_FOUND`, and with `asked`, one renamed or made
|
|
30
|
+
* public or private since too, as `RegisteredRows.read` says.
|
|
30
31
|
*/
|
|
31
|
-
const objectRows = /* @__PURE__ */ Effect.fnUntraced(function* (rows, caller, repo, oids, also = []) {
|
|
32
|
+
const objectRows = /* @__PURE__ */ Effect.fnUntraced(function* (rows, caller, repo, oids, { also = [], asked } = {}) {
|
|
32
33
|
const uploader = (yield* ownWriter(caller)) ?? "anonymous";
|
|
33
34
|
const own = oids.flatMap((oid) => [listedRead(oid), uploadRead(oid, uploader)]);
|
|
34
|
-
const { version, results } = yield* rows.readFenced(caller, repo, [...own, ...also]);
|
|
35
|
+
const { version, results } = yield* rows.readFenced(caller, repo, [...own, ...also], asked);
|
|
35
36
|
const found = /* @__PURE__ */ new Map();
|
|
36
37
|
for (const [at, oid] of oids.entries()) {
|
|
37
38
|
const [listedRows = [], uploadRows = []] = results.slice(at * 2, at * 2 + 2);
|
|
@@ -49,12 +50,12 @@ const objectRows = /* @__PURE__ */ Effect.fnUntraced(function* (rows, caller, re
|
|
|
49
50
|
});
|
|
50
51
|
const decodeListed = (row, oid) => decodeRow(ListedRow, row, `LFS object ${oid}`);
|
|
51
52
|
const decodeUpload = (row, oid) => decodeRow(UploadRow, row, `LFS object ${oid}'s upload`);
|
|
52
|
-
/** The repo's listed rows of `oids`, read in chunks. */
|
|
53
|
-
const listedOf = /* @__PURE__ */ Effect.fnUntraced(function* (rows, repo, oids) {
|
|
53
|
+
/** The repo's listed rows of `oids`, read in chunks, the first held to `asked` when it's given. */
|
|
54
|
+
const listedOf = /* @__PURE__ */ Effect.fnUntraced(function* (rows, repo, oids, asked) {
|
|
54
55
|
const listed = /* @__PURE__ */ new Map();
|
|
55
56
|
for (let at = 0; at < oids.length; at += 100) {
|
|
56
57
|
const chunk = oids.slice(at, at + 100);
|
|
57
|
-
const snapshot = yield* rows.read(repo, chunk.map(listedRead));
|
|
58
|
+
const snapshot = yield* rows.read(repo, chunk.map(listedRead), at === 0 ? asked : void 0);
|
|
58
59
|
for (const [index, oid] of chunk.entries()) {
|
|
59
60
|
const row = snapshot.results[index]?.[0];
|
|
60
61
|
if (row !== void 0) listed.set(oid, yield* decodeListed(row, oid));
|
|
@@ -68,12 +69,16 @@ const listedOf = /* @__PURE__ */ Effect.fnUntraced(function* (rows, repo, oids)
|
|
|
68
69
|
* upload shadows its source's. Each source's rows of every one of `oids` are read, found sooner or
|
|
69
70
|
* not, so the reads made are the same whichever of them are listed, as `unseenOf` needs. A deleted
|
|
70
71
|
* source's rows are read too: its LFS rows and bytes stay while a fork's row names it, since
|
|
71
|
-
* `git.purge` waits on one.
|
|
72
|
+
* `git.purge` waits on one. The first read, of none of `oids` when there are none, is the first
|
|
73
|
+
* since `repo` opened, so it's held to what was asked, as `asAsked` says.
|
|
72
74
|
*/
|
|
73
75
|
const chainListed = /* @__PURE__ */ Effect.fnUntraced(function* (rows, repo, oids) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
if (oids.length === 0) {
|
|
77
|
+
yield* rows.read(repo.internalId, [], repo);
|
|
78
|
+
return /* @__PURE__ */ new Map();
|
|
79
|
+
}
|
|
80
|
+
const listed = yield* listedOf(rows, repo.internalId, oids, repo);
|
|
81
|
+
let from = repo.internalId;
|
|
77
82
|
for (let read = 0; read < 16; read += 1) {
|
|
78
83
|
const source = yield* rows.source(from);
|
|
79
84
|
if (source === void 0) break;
|
|
@@ -148,7 +153,7 @@ const batch = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
|
|
|
148
153
|
if (body.transfers !== void 0 && !body.transfers.includes("basic")) return yield* fail("FAILED_PRECONDITION", "This server takes only the basic transfer");
|
|
149
154
|
if (body.objects.length > 1e3) return yield* fail("RESOURCE_EXHAUSTED", `A batch names at most ${batchMost} objects`);
|
|
150
155
|
const upload = body.operation === "upload";
|
|
151
|
-
const repo = yield* openFor(call.caller, call.repo, upload);
|
|
156
|
+
const repo = yield* openFor(call.caller, call.repo, upload, void 0, "first-read");
|
|
152
157
|
const most = upload && parts.signed === void 0 ? parts.uploadMost : void 0;
|
|
153
158
|
const refusalOf = (oid, size) => {
|
|
154
159
|
if (!isLfsOid(oid)) return "An oid is a SHA-256, as 64 lowercase hex digits";
|
|
@@ -188,7 +193,7 @@ const refusedOf = /* @__PURE__ */ Effect.fnUntraced(function* (call, listed) {
|
|
|
188
193
|
});
|
|
189
194
|
const downloads = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, repo, objects) {
|
|
190
195
|
const oids = objects.map(({ oid }) => oid);
|
|
191
|
-
const chained = yield* chainListed(parts.rows, repo
|
|
196
|
+
const chained = yield* chainListed(parts.rows, repo, oids);
|
|
192
197
|
const listed = yield* seenListed(call.caller, repo, oids, chained);
|
|
193
198
|
const refused = yield* refusedOf(call, listed);
|
|
194
199
|
const expiresAt = (yield* Clock$1.currentTimeMillis) + linkLife;
|
|
@@ -230,7 +235,8 @@ const uploads = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, repo,
|
|
|
230
235
|
const oids = objects.map(({ oid }) => oid);
|
|
231
236
|
for (let tries = 0; tries < 5; tries += 1) {
|
|
232
237
|
const at = yield* Clock$1.currentTimeMillis;
|
|
233
|
-
const
|
|
238
|
+
const asked = tries === 0 ? repo : void 0;
|
|
239
|
+
const read = yield* objectRows(parts.rows, call.caller, repo, oids, { asked });
|
|
234
240
|
const unseen = yield* unseenRows(call.caller, repo, oids, read.rows);
|
|
235
241
|
const expiresAt = at + linkLife;
|
|
236
242
|
const removeAt = expiresAt + uploadGrace;
|
|
@@ -298,11 +304,12 @@ const verify = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
|
|
|
298
304
|
const { oid, size } = yield* bodyOf(call.request, VerifyRequest);
|
|
299
305
|
if (!isLfsOid(oid)) return yield* fail("INVALID_ARGUMENT", "An oid is a SHA-256, as 64 lowercase hex digits");
|
|
300
306
|
const { rows: registered, signed } = parts;
|
|
301
|
-
const repo = yield* openFor(call.caller, call.repo, true);
|
|
307
|
+
const repo = yield* openFor(call.caller, call.repo, true, void 0, "first-read");
|
|
302
308
|
const writer = yield* ownWriter(call.caller);
|
|
303
309
|
for (let tries = 0; tries < 5; tries += 1) {
|
|
304
310
|
const at = yield* Clock$1.currentTimeMillis;
|
|
305
|
-
const
|
|
311
|
+
const asked = tries === 0 ? repo : void 0;
|
|
312
|
+
const read = yield* objectRows(registered, call.caller, repo, [oid], { asked });
|
|
306
313
|
const rows = read.rows.get(oid);
|
|
307
314
|
const unseen = (yield* unseenRows(call.caller, repo, [oid], read.rows)).has(oid);
|
|
308
315
|
if (rows?.listed !== void 0 && !unseen) return lfsAnswer(200, { message: "Verified" });
|
|
@@ -330,9 +337,11 @@ const verify = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call) {
|
|
|
330
337
|
return yield* contended();
|
|
331
338
|
});
|
|
332
339
|
/**
|
|
333
|
-
* `PUT objects/<oid>`, a Worker upload: streams the body to a staging key of its own
|
|
334
|
-
*
|
|
335
|
-
*
|
|
340
|
+
* `PUT objects/<oid>`, a Worker upload: streams the body to a staging key of its own, put with its
|
|
341
|
+
* oid as the SHA-256 the bucket checks, so the Worker never hashes it, and lists the object at that
|
|
342
|
+
* key once the bucket took it. A body that isn't its oid the bucket refuses, keeping nothing of it.
|
|
343
|
+
* Its staging row, added before a byte is written, has upkeep delete the bytes if they're never
|
|
344
|
+
* listed.
|
|
336
345
|
*/
|
|
337
346
|
const receive = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
|
|
338
347
|
if (!isLfsOid(oid)) return yield* fail("INVALID_ARGUMENT", "An oid is a SHA-256, as 64 lowercase hex digits");
|
|
@@ -340,56 +349,79 @@ const receive = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
|
|
|
340
349
|
if (length === void 0) return lfsAnswer(411, { message: noLength });
|
|
341
350
|
if (length > parts.uploadMost.bytes) return lfsAnswer(413, { message: pastMost(parts.uploadMost) });
|
|
342
351
|
const { rows: registered, bucket } = parts;
|
|
343
|
-
const repo = yield* openFor(call.caller, call.repo, true);
|
|
352
|
+
const repo = yield* openFor(call.caller, call.repo, true, void 0, "first-read");
|
|
344
353
|
const started = yield* Clock$1.currentTimeMillis;
|
|
345
|
-
const read = yield* objectRows(registered, call.caller, repo, [oid]);
|
|
354
|
+
const read = yield* objectRows(registered, call.caller, repo, [oid], { asked: repo });
|
|
346
355
|
const rows = read.rows.get(oid);
|
|
347
356
|
const unseen = (yield* unseenRows(call.caller, repo, [oid], read.rows)).has(oid);
|
|
348
357
|
if (rows?.listed !== void 0 && !unseen) return yield* answered(call.request);
|
|
349
358
|
const upload = rows?.upload;
|
|
350
359
|
if (upload === void 0 || upload.expiresAt < started) return yield* fail("FAILED_PRECONDITION", "No upload link for this object is live", { hint: "Ask the batch API again" });
|
|
351
360
|
if (upload.size > parts.uploadMost.bytes) return lfsAnswer(413, { message: pastMost(parts.uploadMost) });
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
});
|
|
366
|
-
const hashed = hashing(call.request.body, upload.size);
|
|
367
|
-
yield* Effect.uninterruptible(bucketDo(bucket.put(key, hashed.body, { size: upload.size }))).pipe(Effect.mapError((error) => hashed.past() ? pastSize(upload.size) : error));
|
|
368
|
-
if ((yield* hashed.hasher.hex) !== oid) {
|
|
369
|
-
yield* dropStaged(parts, repo.internalId, key, staged);
|
|
361
|
+
const [staging] = yield* stagedKeys(registered, repo.internalId, started + uploadGrace, 1);
|
|
362
|
+
if (staging === void 0) return yield* Effect.die(/* @__PURE__ */ new Error("One staging key asked, none made"));
|
|
363
|
+
const { key } = staging;
|
|
364
|
+
const sent = counted(call.request.body, upload.size);
|
|
365
|
+
const put = yield* Effect.result(Effect.uninterruptible(bucketDo(bucket.put(key, sent.body, {
|
|
366
|
+
size: upload.size,
|
|
367
|
+
sha256: oid
|
|
368
|
+
}))));
|
|
369
|
+
if (Result.isFailure(put)) {
|
|
370
|
+
if (sent.past()) return yield* Effect.fail(pastSize(upload.size));
|
|
371
|
+
if (sent.size() < upload.size) return yield* Effect.fail(shortSize(upload.size, sent.size()));
|
|
372
|
+
if (put.failure.code !== "INVALID_ARGUMENT") return yield* Effect.fail(put.failure);
|
|
373
|
+
yield* dropStaged(parts, repo.internalId, staging.row.id);
|
|
370
374
|
return yield* fail("INVALID_ARGUMENT", "The bytes' SHA-256 isn't the oid");
|
|
371
375
|
}
|
|
372
376
|
return yield* listStaged(registered, call.caller, repo, {
|
|
373
377
|
oid,
|
|
374
378
|
size: upload.size,
|
|
375
379
|
key,
|
|
376
|
-
staged,
|
|
380
|
+
staged: staging.row.id,
|
|
377
381
|
deadline: started + streamMost,
|
|
378
382
|
unseen
|
|
379
383
|
});
|
|
380
384
|
});
|
|
381
385
|
/**
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
386
|
+
* `count` staging keys in `repo`, each row added with upkeep's wake at `removeAt`: bytes put at a
|
|
387
|
+
* key that no commit lists by then are deleted, as `endStages` does. A Worker upload's staging and
|
|
388
|
+
* an import's copy's, one way (#2397).
|
|
385
389
|
*/
|
|
386
|
-
const
|
|
390
|
+
const stagedKeys = /* @__PURE__ */ Effect.fnUntraced(function* (rows, repo, removeAt, count) {
|
|
391
|
+
const staging = Array.from({ length: count }, () => {
|
|
392
|
+
const id = randomText(16);
|
|
393
|
+
return {
|
|
394
|
+
key: stagingKey(repo, id),
|
|
395
|
+
row: {
|
|
396
|
+
collection: lfsCollections.staging,
|
|
397
|
+
id: stagingId(removeAt, id)
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
});
|
|
401
|
+
if (staging.length === 0) return staging;
|
|
402
|
+
yield* rows.add(repo, {
|
|
403
|
+
put: staging.map(({ key, row }) => ({
|
|
404
|
+
...row,
|
|
405
|
+
value: {
|
|
406
|
+
key,
|
|
407
|
+
removeAt
|
|
408
|
+
}
|
|
409
|
+
})),
|
|
410
|
+
wake: removeAt
|
|
411
|
+
});
|
|
412
|
+
return staging;
|
|
413
|
+
});
|
|
414
|
+
/**
|
|
415
|
+
* Deletes the staging row of bytes the bucket refused, keeping none of them, at the version it's
|
|
416
|
+
* read at (#1940). A failure leaves the row, whose wake has upkeep delete its key at its removeAt,
|
|
417
|
+
* and is no reason to answer it in place of the refusal.
|
|
418
|
+
*/
|
|
419
|
+
const dropStaged = /* @__PURE__ */ Effect.fnUntraced(function* (parts, repo, staged) {
|
|
387
420
|
const row = {
|
|
388
421
|
collection: lfsCollections.staging,
|
|
389
422
|
id: staged
|
|
390
423
|
};
|
|
391
424
|
yield* bestEffort(Effect.gen(function* () {
|
|
392
|
-
yield* bucketDo(parts.bucket.remove(key));
|
|
393
425
|
const read = yield* parts.rows.read(repo, [row]);
|
|
394
426
|
yield* parts.rows.commit(repo, read.version, { delete: [row] });
|
|
395
427
|
}));
|
|
@@ -403,6 +435,7 @@ const lengthOf = (request) => {
|
|
|
403
435
|
return Number.isSafeInteger(length) ? length : void 0;
|
|
404
436
|
};
|
|
405
437
|
const pastSize = (size) => gitError("INVALID_ARGUMENT", `The bytes run past the ${size} the batch named`);
|
|
438
|
+
const shortSize = (size, sent) => gitError("INVALID_ARGUMENT", `The bytes end at ${sent}, short of the ${size} the batch named`);
|
|
406
439
|
/**
|
|
407
440
|
* An answer to a request whose body isn't needed: the body is let go first, and a cancel that
|
|
408
441
|
* rejects is no reason to fail an upload that's done.
|
|
@@ -412,13 +445,12 @@ const answered = (request) => Effect.promise(async () => {
|
|
|
412
445
|
return lfsAnswer(200, { message: "Already uploaded" });
|
|
413
446
|
});
|
|
414
447
|
/**
|
|
415
|
-
* `body` as it streams to the bucket, gathered into pieces of `uploadPieceBytes
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
448
|
+
* `body` as it streams to the bucket, gathered into pieces of `uploadPieceBytes` and counted,
|
|
449
|
+
* failing past `most` bytes, or at its end short of them, before the bucket checks its hash. No
|
|
450
|
+
* piece reaches more than one byte past what `most` leaves, so a body that runs past it is read no
|
|
451
|
+
* further than that byte's chunk.
|
|
419
452
|
*/
|
|
420
|
-
const
|
|
421
|
-
const hasher = nativeSha256Hasher();
|
|
453
|
+
const counted = (body, most) => {
|
|
422
454
|
let size = 0;
|
|
423
455
|
const read = Stream.fromReadableStream({
|
|
424
456
|
evaluate: () => body === null ? new ReadableStream({ start: (controller) => controller.close() }) : gathered(body, (given) => Math.min(uploadPieceBytes, Math.max(1, most - given + 1))),
|
|
@@ -427,14 +459,16 @@ const hashing = (body, most) => {
|
|
|
427
459
|
cause
|
|
428
460
|
})
|
|
429
461
|
});
|
|
462
|
+
const sized = Stream.mapEffect(read, (chunk) => {
|
|
463
|
+
size += chunk.length;
|
|
464
|
+
if (size > most) return Effect.fail(pastSize(most));
|
|
465
|
+
return Effect.succeed(chunk);
|
|
466
|
+
});
|
|
467
|
+
const ended = Stream.suspend(() => size < most ? Stream.fail(shortSize(most, size)) : Stream.empty);
|
|
430
468
|
return {
|
|
431
|
-
body: Stream.
|
|
432
|
-
size += chunk.length;
|
|
433
|
-
if (size > most) return Effect.fail(pastSize(most));
|
|
434
|
-
return Effect.as(hasher.write(chunk), chunk);
|
|
435
|
-
}),
|
|
469
|
+
body: Stream.concat(sized, ended),
|
|
436
470
|
past: () => size > most,
|
|
437
|
-
|
|
471
|
+
size: () => size
|
|
438
472
|
};
|
|
439
473
|
};
|
|
440
474
|
/** Lists a Worker upload's bytes at their staging key, in the commit that drops its staging row. */
|
|
@@ -443,7 +477,7 @@ const listStaged = /* @__PURE__ */ Effect.fnUntraced(function* (registered, call
|
|
|
443
477
|
for (let tries = 0; tries < 5; tries += 1) {
|
|
444
478
|
const at = yield* Clock$1.currentTimeMillis;
|
|
445
479
|
const own = writer === void 0 ? [] : [uploadedRow(writer, staged.oid, at)];
|
|
446
|
-
const read = yield* objectRows(registered, caller, repo, [staged.oid], [stagingRead(staged.staged)]);
|
|
480
|
+
const read = yield* objectRows(registered, caller, repo, [staged.oid], { also: [stagingRead(staged.staged)] });
|
|
447
481
|
if (read.rows.get(staged.oid)?.listed !== void 0) {
|
|
448
482
|
const answer = lfsAnswer(200, { message: staged.unseen ? "Uploaded" : "Already uploaded" });
|
|
449
483
|
if (own.length === 0) return answer;
|
|
@@ -480,8 +514,8 @@ const listStaged = /* @__PURE__ */ Effect.fnUntraced(function* (registered, call
|
|
|
480
514
|
const objectOf = /* @__PURE__ */ Effect.fnUntraced(function* (parts, read) {
|
|
481
515
|
const { oid, size, signal } = read;
|
|
482
516
|
if (!isLfsOid(oid)) return yield* fail("NOT_FOUND", "Object does not exist");
|
|
483
|
-
const repo = yield* openFor(read.caller, read.repo, false, read.internalId);
|
|
484
|
-
const chained = yield* chainListed(parts.rows, repo
|
|
517
|
+
const repo = yield* openFor(read.caller, read.repo, false, read.internalId, "first-read");
|
|
518
|
+
const chained = yield* chainListed(parts.rows, repo, [oid]);
|
|
485
519
|
const listed = (yield* seenListed(read.caller, repo, [oid], chained)).get(oid);
|
|
486
520
|
if (listed === void 0 || size !== void 0 && size !== listed.size) return yield* fail("NOT_FOUND", "Object does not exist");
|
|
487
521
|
yield* checkRead(read.repo, {
|
|
@@ -523,4 +557,4 @@ const send = /* @__PURE__ */ Effect.fnUntraced(function* (parts, call, oid) {
|
|
|
523
557
|
}
|
|
524
558
|
});
|
|
525
559
|
});
|
|
526
|
-
export { batch, listedOf, objectOf, receive, send, verify };
|
|
560
|
+
export { batch, listedOf, objectOf, receive, send, stagedKeys, verify };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "../contracts/ids.mjs";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
import { Key, Moment, Read } from "@ref0/infra";
|
|
4
|
+
/**
|
|
5
|
+
* A listed object: its bytes are at `key`, checked. A signed upload's are at its upload row's
|
|
6
|
+
* `objectKey`, and a Worker upload's stay at the staging key they streamed to, which only they
|
|
7
|
+
* were ever written to.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ListedRow: Schema.Struct<{
|
|
10
|
+
readonly size: Schema.Int;
|
|
11
|
+
readonly key: Schema.String;
|
|
12
|
+
}>;
|
|
13
|
+
export type ListedRow = typeof ListedRow.Type;
|
package/dist/lfs/service.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { LfsFeature, LfsOptions } from "../contracts/lfs.mjs";
|
|
2
1
|
import { GitError } from "../contracts/result.mjs";
|
|
3
2
|
import "../core/parts.mjs";
|
|
4
3
|
import { LfsCall } from "./objects.mjs";
|
|
@@ -9,9 +8,4 @@ export interface LfsRoute extends LfsCall {
|
|
|
9
8
|
readonly route: string;
|
|
10
9
|
}
|
|
11
10
|
/** Git LFS's API for a server's repos, its objects in `bucket`. */
|
|
12
|
-
export type LfsService = (call: LfsRoute) => Effect.Effect<Response, GitError>;
|
|
13
|
-
/**
|
|
14
|
-
* Turns on Git LFS, its objects in the adapter's bucket: a server without it has no LFS. `options`
|
|
15
|
-
* win over the adapter's `RequestLimits`, as `LfsOptions` says.
|
|
16
|
-
*/
|
|
17
|
-
export declare const lfs: (options?: LfsOptions) => LfsFeature;
|
|
11
|
+
export type LfsService = (call: LfsRoute) => Effect.Effect<Response, GitError>;
|
package/dist/lfs/service.mjs
CHANGED
|
@@ -4,14 +4,6 @@ import { batch, receive, send, verify } from "./objects.mjs";
|
|
|
4
4
|
import { lfsAnswer } from "./wire.mjs";
|
|
5
5
|
import * as Effect from "effect/Effect";
|
|
6
6
|
// src/lfs/service.ts
|
|
7
|
-
/**
|
|
8
|
-
* Turns on Git LFS, its objects in the adapter's bucket: a server without it has no LFS. `options`
|
|
9
|
-
* win over the adapter's `RequestLimits`, as `LfsOptions` says.
|
|
10
|
-
*/
|
|
11
|
-
const lfs = (options = {}) => ({
|
|
12
|
-
...options,
|
|
13
|
-
kind: "lfs"
|
|
14
|
-
});
|
|
15
7
|
const methodNotAllowed = (allow) => Effect.succeed(lfsAnswer(405, { message: "Method not allowed" }, { allow }));
|
|
16
8
|
/** LFS's routes over `parts`, provided `needs`, the server's services, which `openRepo` reads. */
|
|
17
9
|
const lfsService = (needs, parts) => (call) => Effect.provideContext(served(parts, call), needs);
|
|
@@ -35,4 +27,4 @@ const served = (parts, call) => {
|
|
|
35
27
|
if (unlocking !== void 0) return method === "POST" ? unlock(parts, call, unlocking) : methodNotAllowed("POST");
|
|
36
28
|
return fail("NOT_FOUND", "No such LFS route");
|
|
37
29
|
};
|
|
38
|
-
export {
|
|
30
|
+
export { lfsService };
|
package/dist/lfs/upload-most.mjs
CHANGED
|
@@ -3,18 +3,18 @@ import { largestObject } from "./rows.mjs";
|
|
|
3
3
|
/**
|
|
4
4
|
* The largest Git LFS upload through the server, `workerUploadMost`, for a bucket that signs no
|
|
5
5
|
* links: the least of what the platform's body cap passes on, what its CPU cap lets the upload
|
|
6
|
-
*
|
|
6
|
+
* stream to the bucket, and `largestObject`. A larger one is refused before a byte streams, at the
|
|
7
7
|
* batch, so git-lfs never starts it.
|
|
8
8
|
*/
|
|
9
9
|
/** The share of a request's CPU an upload may spend: the rest is its rows', its put's and the runtime's. */
|
|
10
10
|
const cpuShare = .8;
|
|
11
11
|
/**
|
|
12
12
|
* The bytes an upload through a Worker gathers from its body's chunks before each goes on to its
|
|
13
|
-
*
|
|
14
|
-
* paid for once over (run 46342279485, #2296): one piece an upload, held as it streams.
|
|
13
|
+
* put, which checks its SHA-256, since a client's body reaches a Worker in chunks of at most
|
|
14
|
+
* 4,096 B, each paid for once over (run 46342279485, #2296): one piece an upload, held as it streams.
|
|
15
15
|
*/
|
|
16
16
|
const uploadPieceBytes = 1024 ** 2;
|
|
17
|
-
/** The bytes `cpuMs` of CPU
|
|
17
|
+
/** The bytes `cpuMs` of CPU streams to a checked put, at `uploadMsPerMiB` within `cpuShare` of it. */
|
|
18
18
|
const cpuBytes = (cpuMs) => Math.floor(cpuShare * cpuMs / 22 * 1024 ** 2);
|
|
19
19
|
/** The largest upload `caps` let finish: `largestObject` where neither binds below it. */
|
|
20
20
|
const uploadMostOf = (caps) => {
|
|
@@ -39,7 +39,7 @@ const capsRefusal = (caps) => {
|
|
|
39
39
|
/** What each cap that sets the largest upload is, as a refusal names it. */
|
|
40
40
|
const setBy = {
|
|
41
41
|
body: "the largest body its platform passes on",
|
|
42
|
-
cpu: "what its CPU cap lets it
|
|
42
|
+
cpu: "what its CPU cap lets it stream to the bucket",
|
|
43
43
|
object: "R2's largest single put"
|
|
44
44
|
};
|
|
45
45
|
/** Why an upload of more than `most` is refused, and what takes it. */
|
package/dist/node.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toNodeHandler, toNodeMiddleware } from "./server/edge-node.mjs";
|
|
2
2
|
import { NodeHandler, NodeMiddleware, NodeNext, NodeRequest, NodeResponse } from "./http/node.mjs";
|
|
3
|
-
export { type
|
|
3
|
+
export { type NodeHandler, type NodeMiddleware, type NodeNext, type NodeRequest, type NodeResponse, toNodeHandler, toNodeMiddleware };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "./sha1-hasher.mjs";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
/**
|
|
4
|
+
* A SHA-256 written a piece at a time as an upload's body streams through, as `@ref0/github`'s
|
|
5
|
+
* release asset in one request is (#2452), through the runtime's own hash: workerd's
|
|
6
|
+
* `crypto.DigestStream`, or Node's `createHash`, and `Sha256` where a runtime has neither.
|
|
7
|
+
* `sha1-hasher.ts` does the same for a pack's SHA-1.
|
|
8
|
+
*/
|
|
9
|
+
/** A SHA-256 written a piece at a time, then its sum as 64 lowercase hex digits. */
|
|
10
|
+
export interface Sha256Hasher {
|
|
11
|
+
readonly write: (bytes: Uint8Array) => Effect.Effect<void>;
|
|
12
|
+
readonly hex: Effect.Effect<string>;
|
|
13
|
+
}
|
|
14
|
+
/** A `Sha256Hasher` through this runtime's own hash, or `Sha256` where it has none. */
|
|
15
|
+
export declare const nativeSha256Hasher: () => Sha256Hasher;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
/**
|
|
3
|
+
* A SHA-256's state between writes: its eight words, the bytes it took, and the bytes past its last
|
|
4
|
+
* whole 64-byte block, as lowercase hex, as many as `length` leaves past a block. Decode stored
|
|
5
|
+
* state through it, so a damaged one fails by name before a `Sha256` goes on from it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const Sha256State: Schema.Struct<{
|
|
8
|
+
readonly words: Schema.Tuple<readonly [Schema.Number, Schema.Number, Schema.Number, Schema.Number, Schema.Number, Schema.Number, Schema.Number, Schema.Number]>;
|
|
9
|
+
readonly length: Schema.Int;
|
|
10
|
+
readonly pending: Schema.String;
|
|
11
|
+
}>;
|
|
12
|
+
export type Sha256State = typeof Sha256State.Type;
|
|
13
|
+
/** A stored state, checked: a typed failure for one no `Sha256` could have written. */
|
|
14
|
+
export declare const decodeSha256State: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => import("effect/Effect").Effect<{
|
|
15
|
+
readonly words: readonly [number, number, number, number, number, number, number, number];
|
|
16
|
+
readonly length: number;
|
|
17
|
+
readonly pending: string;
|
|
18
|
+
}, Schema.SchemaError, never>;
|
|
19
|
+
export declare class Sha256 {
|
|
20
|
+
#private;
|
|
21
|
+
/**
|
|
22
|
+
* A hash from the start, or going on from `state`, which it trusts: one `decodeSha256State`
|
|
23
|
+
* hasn't checked and that holds a block or more of pending bytes throws a `RangeError`.
|
|
24
|
+
*/
|
|
25
|
+
constructor(state?: Sha256State);
|
|
26
|
+
/** Takes `bytes`, after every byte before them. */
|
|
27
|
+
update(bytes: Uint8Array): void;
|
|
28
|
+
/** The state to go on from, as plain data. */
|
|
29
|
+
state(): Sha256State;
|
|
30
|
+
/** The digest of every byte taken, as 64 lowercase hex digits; the hash takes no more after it. */
|
|
31
|
+
hex(): string;
|
|
32
|
+
}
|