@ref0/git 0.7.0 → 0.8.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 +0 -2
- package/dist/auth/authorize.mjs +31 -24
- package/dist/auth/bridge.mjs +8 -8
- package/dist/auth/fences.d.mts +0 -1
- package/dist/auth/fences.mjs +1 -1
- package/dist/auth/grants.d.mts +0 -1
- package/dist/auth/grants.mjs +2 -2
- package/dist/auth/host-function.d.mts +1 -7
- package/dist/auth/host-function.mjs +38 -38
- package/dist/auth/identify.d.mts +0 -1
- package/dist/auth/identify.mjs +1 -1
- package/dist/auth/policy.d.mts +7 -4
- package/dist/auth/policy.mjs +13 -10
- package/dist/auth/token-rows.mjs +2 -5
- package/dist/auth/tokens-layer.d.mts +0 -2
- package/dist/auth/tokens-public.d.mts +3 -3
- package/dist/auth/tokens-public.mjs +4 -2
- package/dist/auth/tokens.d.mts +6 -1
- package/dist/auth/tokens.mjs +7 -1
- package/dist/client/client.d.mts +22 -15
- package/dist/client/client.mjs +31 -27
- package/dist/client/git-http.mjs +22 -5
- package/dist/client/local.mjs +1 -1
- package/dist/client/namespace.d.mts +2 -0
- package/dist/client/push-upload.d.mts +1 -0
- package/dist/client/push-upload.mjs +169 -2
- package/dist/client/remote-helper.mjs +2 -4
- package/dist/client/remote.mjs +37 -15
- package/dist/client/run-remote-helper.mjs +4 -4
- package/dist/client/transport.mjs +26 -19
- package/dist/contracts/actors.d.mts +57 -28
- package/dist/contracts/actors.mjs +38 -2
- package/dist/contracts/authorize.d.mts +21 -15
- package/dist/contracts/callers.mjs +40 -0
- package/dist/contracts/client.d.mts +16 -9
- package/dist/contracts/events.d.mts +12 -10
- package/dist/contracts/events.mjs +8 -6
- package/dist/contracts/files.d.mts +42 -42
- package/dist/contracts/forks.d.mts +0 -24
- package/dist/contracts/git-hooks.d.mts +217 -0
- package/dist/contracts/git-hooks.mjs +3 -1
- package/dist/contracts/grants.d.mts +46 -27
- package/dist/contracts/lfs.d.mts +17 -4
- package/dist/contracts/merges.d.mts +7 -7
- package/dist/contracts/objects.d.mts +20 -4
- package/dist/contracts/opaque.mjs +19 -1
- package/dist/contracts/operations.d.mts +8 -1
- package/dist/contracts/operations.mjs +209 -0
- package/dist/contracts/queue.d.mts +3 -3
- package/dist/contracts/queue.mjs +5 -18
- package/dist/contracts/remote.d.mts +13 -4
- package/dist/contracts/remote.mjs +3 -3
- package/dist/contracts/repos.d.mts +11 -40
- package/dist/contracts/repos.mjs +11 -10
- package/dist/contracts/result.d.mts +28 -11
- package/dist/contracts/result.mjs +32 -2
- package/dist/contracts/rules.d.mts +706 -46
- package/dist/contracts/rules.mjs +81 -2
- package/dist/contracts/server.d.mts +5 -275
- package/dist/contracts/services.d.mts +0 -3
- package/dist/contracts/services.mjs +1 -3
- package/dist/contracts/signin.d.mts +2 -2
- package/dist/contracts/signin.mjs +4 -5
- package/dist/contracts/sync.d.mts +1 -4
- package/dist/contracts/tokens.d.mts +29 -17
- package/dist/contracts/tokens.mjs +14 -3
- package/dist/contracts/topics.d.mts +38 -11
- package/dist/contracts/topics.mjs +8 -2
- package/dist/core/access.d.mts +0 -2
- package/dist/core/access.mjs +15 -4
- package/dist/core/events/deliver.mjs +19 -1
- package/dist/core/forks.mjs +30 -11
- package/dist/core/hooks/groups.d.mts +0 -1
- package/dist/core/hooks/groups.mjs +8 -9
- package/dist/core/loose-tally.mjs +46 -0
- package/dist/core/objects/writing.mjs +1 -0
- package/dist/core/promise.mjs +1 -15
- package/dist/core/purge.mjs +14 -9
- package/dist/core/push.mjs +13 -6
- package/dist/core/ref-view.mjs +14 -6
- package/dist/core/repack.mjs +19 -14
- package/dist/core/repo-info.mjs +8 -6
- package/dist/core/repos.mjs +1 -0
- package/dist/core/rules/check.mjs +10 -10
- package/dist/core/rules/context.d.mts +3 -1
- package/dist/core/rules/context.mjs +16 -13
- package/dist/core/rules/fetch.mjs +17 -23
- package/dist/core/tokens.mjs +2 -1
- package/dist/effect.d.mts +2 -4
- package/dist/effect.mjs +2 -4
- package/dist/engine/commits.mjs +19 -47
- package/dist/engine/failures.d.mts +1 -2
- package/dist/engine/failures.mjs +1 -3
- package/dist/engine/merge-base-walk.mjs +57 -142
- package/dist/engine/merge-bases.mjs +5 -5
- package/dist/engine/merge.mjs +16 -14
- package/dist/extend.d.mts +1 -2
- package/dist/extend.mjs +1 -2
- package/dist/http/core-parts.mjs +1 -2
- package/dist/http/handler.mjs +11 -31
- package/dist/http/parts.d.mts +0 -1
- package/dist/index.d.mts +28 -21
- package/dist/index.mjs +5 -2
- package/dist/lfs/base.d.mts +6 -3
- package/dist/lfs/base.mjs +2 -1
- package/dist/lfs/layer.d.mts +4 -3
- package/dist/lfs/layer.mjs +23 -9
- package/dist/lfs/objects.mjs +90 -41
- package/dist/lfs/pointers.mjs +69 -18
- package/dist/lfs/purge.mjs +6 -2
- package/dist/lfs/rows.mjs +24 -7
- package/dist/lfs/service.d.mts +6 -3
- package/dist/lfs/service.mjs +8 -2
- package/dist/lfs/upkeep.mjs +44 -26
- package/dist/lfs/upload-most.mjs +41 -0
- package/dist/lfs/uploaded.mjs +59 -0
- package/dist/protocol/bytes/sha256-hasher.mjs +51 -0
- package/dist/protocol/bytes/text.mjs +6 -1
- package/dist/protocol/objects/fsck.mjs +6 -3
- package/dist/queue/advance.mjs +38 -8
- package/dist/queue/calls.mjs +4 -14
- package/dist/queue/lanes.mjs +1 -1
- package/dist/queue/rows.mjs +8 -0
- package/dist/queue/schedule.mjs +1 -1
- package/dist/queue/search.mjs +3 -4
- package/dist/rest/client-namespace.d.mts +2 -0
- package/dist/rest/client.d.mts +32 -8
- package/dist/rest/client.mjs +308 -382
- package/dist/rest/commits.d.mts +240 -240
- package/dist/rest/files.d.mts +18 -18
- package/dist/rest/forks.d.mts +45 -57
- package/dist/rest/handlers.mjs +2 -1
- package/dist/rest/listen.d.mts +8 -6
- package/dist/rest/listen.mjs +31 -75
- package/dist/rest/me.d.mts +2 -2
- package/dist/rest/merges.d.mts +7 -7
- package/dist/rest/refs.d.mts +139 -139
- package/dist/rest/repos.d.mts +54 -66
- package/dist/rest/tokens.d.mts +12 -12
- package/dist/rest/topics.d.mts +110 -110
- package/dist/rest/trees.d.mts +66 -66
- package/dist/rest/wire.d.mts +1 -1
- package/dist/rest.d.mts +1 -7
- package/dist/rest.mjs +1 -5
- package/dist/server/git-layer.d.mts +10 -2
- package/dist/server/git-layer.mjs +29 -10
- package/dist/server/joined.d.mts +1 -1
- package/dist/server/server.d.mts +0 -1
- package/dist/server/server.mjs +26 -45
- package/dist/signin/context.d.mts +0 -1
- package/dist/signin/context.mjs +5 -9
- package/dist/storage/clean-up.mjs +3 -1
- package/dist/storage/fsck.mjs +12 -2
- package/dist/storage/graph-rebuild.mjs +262 -0
- package/dist/storage/index-build.mjs +100 -12
- package/dist/storage/lfs-pointers.d.mts +5 -5
- package/dist/storage/lfs-pointers.mjs +37 -11
- package/dist/storage/loose.mjs +4 -1
- package/dist/storage/memory-budget.mjs +1 -1
- package/dist/storage/merge-fence.mjs +81 -19
- package/dist/storage/merge-most.mjs +1 -0
- package/dist/storage/merge-row.mjs +16 -4
- package/dist/storage/merge-stream.mjs +9 -6
- package/dist/storage/object-rows.mjs +17 -1
- package/dist/storage/pack-receive.mjs +10 -6
- package/dist/storage/packs.mjs +58 -27
- package/dist/storage/prune.mjs +68 -40
- package/dist/storage/ready.d.mts +1 -1
- package/dist/storage/ready.mjs +12 -3
- package/dist/storage/receive-state.mjs +1 -1
- package/dist/storage/repack-contained.mjs +22 -14
- package/dist/storage/repack.d.mts +1 -1
- package/dist/storage/repack.mjs +3 -2
- package/dist/storage/unpack.mjs +7 -0
- package/dist/store/call-count.d.mts +23 -3
- package/dist/store/call-count.mjs +36 -13
- package/dist/store/records.mjs +10 -4
- package/dist/store/repo-record.mjs +29 -12
- package/dist/store/scopes.mjs +6 -1
- package/dist/sync/import.mjs +14 -2
- package/dist/sync/layer.d.mts +5 -1
- package/dist/sync/layer.mjs +7 -2
- package/dist/sync/step.mjs +15 -15
- package/dist/topics/advance.mjs +7 -6
- package/dist/topics/members.mjs +38 -9
- package/package.json +3 -3
- package/dist/engine/merge-base-walk.d.mts +0 -3
- package/dist/server/routes.d.mts +0 -32
- package/dist/server/routes.mjs +0 -69
- package/dist/sync/bridge.d.mts +0 -6
- package/dist/sync/bridge.mjs +0 -29
package/dist/lfs/pointers.mjs
CHANGED
|
@@ -2,18 +2,28 @@ import { gitError } from "../contracts/result.mjs";
|
|
|
2
2
|
import { bytesOf } from "../storage/wants.mjs";
|
|
3
3
|
import { deadlineOf, timed, within } from "../engine/reads.mjs";
|
|
4
4
|
import { decodeCommit } from "../protocol/objects/commit.mjs";
|
|
5
|
-
import { isTreeMode } from "../protocol/objects/object.mjs";
|
|
5
|
+
import { isTreeMode, objectId } from "../protocol/objects/object.mjs";
|
|
6
6
|
import { parseTreeBytes } from "../protocol/objects/tree.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import { ownWriter } from "../core/own-writes.mjs";
|
|
8
|
+
import { utf8 } from "../protocol/bytes/text.mjs";
|
|
9
|
+
import { lfsPointerText } from "../protocol/objects/lfs-pointer.mjs";
|
|
10
|
+
import { lfsOidAt, lfsSizeAt, pointersOfBlob } from "../storage/lfs-pointers.mjs";
|
|
8
11
|
import { listedOf } from "./objects.mjs";
|
|
12
|
+
import { uploadedOf } from "./uploaded.mjs";
|
|
13
|
+
import * as Clock$1 from "effect/Clock";
|
|
9
14
|
import * as Effect from "effect/Effect";
|
|
10
15
|
// src/lfs/pointers.ts
|
|
11
16
|
/**
|
|
12
17
|
* LFS's push rule: a ref whose new tip holds, in a tree the push carries, a Git LFS pointer the
|
|
13
|
-
* push carries to an object the repo
|
|
14
|
-
* can't download.
|
|
15
|
-
* the
|
|
16
|
-
*
|
|
18
|
+
* push carries to an object the repo doesn't hold for the pusher is refused, so a clone never
|
|
19
|
+
* meets a pointer it can't download. The repo holds it for the pusher when it lists the object at
|
|
20
|
+
* the size the pointer names, and, for a pusher whose view is narrowed, as under `access` one who
|
|
21
|
+
* doesn't read every pattern is, when a ref it sees reaches the object's pointer or it sent the
|
|
22
|
+
* object's bytes within `uploadedKept` (#1943). So a hidden object's oid and size alone push no
|
|
23
|
+
* pointer to it, and the refusal is the one an unlisted object gets, telling nothing of it. It
|
|
24
|
+
* starts from the pointers the receive found among the push's blobs, and reads the listed rows of
|
|
25
|
+
* the oids they name. Only when one is refused does it walk each new tip's trees, the push's own
|
|
26
|
+
* alone, for where that pointer sits.
|
|
17
27
|
*/
|
|
18
28
|
/**
|
|
19
29
|
* How long the walk for an unlisted pointer may take, across every ref of one push. A push's
|
|
@@ -27,7 +37,10 @@ const pushCheckMilliseconds = 6e4;
|
|
|
27
37
|
const fileModes = /* @__PURE__ */ new Set(["100644", "100755"]);
|
|
28
38
|
/**
|
|
29
39
|
* The check, over the repo's listed rows in LFS's registration's `rows`: each ref it refuses, with why.
|
|
30
|
-
* It answers only for the refs it's asked of, and may be asked twice.
|
|
40
|
+
* It answers only for the refs it's asked of, and may be asked twice. It checks every push,
|
|
41
|
+
* whatever the repo's `.gitattributes` say: one can come in the same push, sit on another ref or in
|
|
42
|
+
* a folder, so none says which files are pointers. Its cost is bounded already, as the receive
|
|
43
|
+
* reads only the push's new blobs of at most 1,024 bytes for pointers, in its own pass.
|
|
31
44
|
*/
|
|
32
45
|
const pointerCheck = /* @__PURE__ */ Effect.fnUntraced(function* (rows, input) {
|
|
33
46
|
const refused = /* @__PURE__ */ new Map();
|
|
@@ -40,7 +53,7 @@ const pointerCheck = /* @__PURE__ */ Effect.fnUntraced(function* (rows, input) {
|
|
|
40
53
|
}
|
|
41
54
|
const { lfsPointers } = input.objects;
|
|
42
55
|
if (lfsPointers.count === 0 || tips.size === 0) return refused;
|
|
43
|
-
const unlisted = yield* unlistedOf(rows, input
|
|
56
|
+
const unlisted = yield* unlistedOf(rows, input);
|
|
44
57
|
if (unlisted === void 0) return refused;
|
|
45
58
|
const deadline = yield* deadlineOf(pushCheckMilliseconds, "walk-limit");
|
|
46
59
|
const walk = Effect.forEach(tips, ([ref, tip]) => Effect.map(missingAt(input, unlisted, tip, deadline), (missing) => [ref, missing]));
|
|
@@ -49,28 +62,66 @@ const pointerCheck = /* @__PURE__ */ Effect.fnUntraced(function* (rows, input) {
|
|
|
49
62
|
return refused;
|
|
50
63
|
});
|
|
51
64
|
/**
|
|
52
|
-
* Which of
|
|
53
|
-
*
|
|
54
|
-
*
|
|
65
|
+
* Which of the push's pointers name an object the repo doesn't hold for the pusher, one bit an
|
|
66
|
+
* entry, or `undefined` when it holds every one: unlisted, or listed at another size, then, of the
|
|
67
|
+
* rest, those `unprovenOf` leaves. It reads a chunk of entries at a time, so it keeps no more than
|
|
68
|
+
* one read's rows beside the bits and the entries left to prove.
|
|
55
69
|
*/
|
|
56
|
-
const unlistedOf = /* @__PURE__ */ Effect.fnUntraced(function* (rows,
|
|
70
|
+
const unlistedOf = /* @__PURE__ */ Effect.fnUntraced(function* (rows, input) {
|
|
71
|
+
const pointers = input.objects.lfsPointers;
|
|
57
72
|
const unlisted = new Uint8Array(Math.ceil(pointers.count / 8));
|
|
73
|
+
const listedAt = [];
|
|
58
74
|
let any = false;
|
|
75
|
+
const refuse = (at) => {
|
|
76
|
+
unlisted[at >>> 3] = (unlisted[at >>> 3] ?? 0) | 1 << (at & 7);
|
|
77
|
+
any = true;
|
|
78
|
+
};
|
|
59
79
|
for (let from = 0; from < pointers.count; from += 100) {
|
|
60
80
|
const to = Math.min(from + 100, pointers.count);
|
|
61
81
|
const oids = Array.from({ length: to - from }, (_, at) => lfsOidAt(pointers, from + at));
|
|
62
|
-
const listed = yield* listedOf(rows, repo, [...new Set(oids)]);
|
|
63
|
-
for (const [at, oid] of oids.entries())
|
|
64
|
-
|
|
65
|
-
unlisted[from + at >>> 3] = (unlisted[from + at >>> 3] ?? 0) | 1 << (from + at & 7);
|
|
66
|
-
any = true;
|
|
67
|
-
}
|
|
82
|
+
const listed = yield* listedOf(rows, input.objects.repo, [...new Set(oids)]);
|
|
83
|
+
for (const [at, oid] of oids.entries()) if (listed.get(oid)?.size === lfsSizeAt(pointers, from + at)) listedAt.push(from + at);
|
|
84
|
+
else refuse(from + at);
|
|
68
85
|
}
|
|
86
|
+
const unproven = yield* unprovenOf(rows, input, listedAt);
|
|
87
|
+
for (const at of listedAt) if (unproven.has(lfsOidAt(pointers, at))) refuse(at);
|
|
69
88
|
return any ? {
|
|
70
89
|
pointers,
|
|
71
90
|
unlisted
|
|
72
91
|
} : void 0;
|
|
73
92
|
});
|
|
93
|
+
/**
|
|
94
|
+
* The oids of `entries`, each listed at its pointer's size, that the pusher hasn't shown it holds:
|
|
95
|
+
* none for a pusher whose view isn't narrowed. Else those whose pointer, as git-lfs writes it, no
|
|
96
|
+
* ref the pusher sees reaches, as `seenIn` asks of every one at once, less those the pusher
|
|
97
|
+
* uploaded within `uploadedKept`.
|
|
98
|
+
*/
|
|
99
|
+
const unprovenOf = /* @__PURE__ */ Effect.fnUntraced(function* (rows, input, entries) {
|
|
100
|
+
const { lfsPointers: pointers, repo } = input.objects;
|
|
101
|
+
const unproven = /* @__PURE__ */ new Set();
|
|
102
|
+
if (entries.length === 0) return unproven;
|
|
103
|
+
const blobs = /* @__PURE__ */ new Map();
|
|
104
|
+
const sized = new Map(entries.map((at) => [lfsOidAt(pointers, at), lfsSizeAt(pointers, at)]));
|
|
105
|
+
for (const [oid, size] of sized) {
|
|
106
|
+
const text = lfsPointerText({
|
|
107
|
+
oid,
|
|
108
|
+
size
|
|
109
|
+
});
|
|
110
|
+
blobs.set(yield* objectId({
|
|
111
|
+
type: "blob",
|
|
112
|
+
bytes: utf8(text)
|
|
113
|
+
}), oid);
|
|
114
|
+
}
|
|
115
|
+
const seen = yield* input.seen([...blobs.keys()]);
|
|
116
|
+
if (seen === void 0) return unproven;
|
|
117
|
+
const unseen = [...blobs].flatMap(([blob, oid]) => seen.has(blob) ? [] : [oid]);
|
|
118
|
+
if (unseen.length === 0) return unproven;
|
|
119
|
+
const writer = yield* ownWriter(input.caller);
|
|
120
|
+
const at = yield* Clock$1.currentTimeMillis;
|
|
121
|
+
const own = writer === void 0 ? /* @__PURE__ */ new Set() : yield* uploadedOf(rows, repo, writer, unseen, at);
|
|
122
|
+
for (const oid of unseen) if (!own.has(oid)) unproven.add(oid);
|
|
123
|
+
return unproven;
|
|
124
|
+
});
|
|
74
125
|
/** The unlisted LFS oids the pointers of the blob `blob` name, if any. */
|
|
75
126
|
const unlistedNamed = ({ pointers, unlisted }, blob) => {
|
|
76
127
|
const { from, to } = pointersOfBlob(pointers, blob);
|
package/dist/lfs/purge.mjs
CHANGED
|
@@ -24,11 +24,15 @@ const lfsPurge = (rows, bucket) => /* @__PURE__ */ Effect.fnUntraced(function* (
|
|
|
24
24
|
{
|
|
25
25
|
collection: lfsCollections.locks,
|
|
26
26
|
limit: 500
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
collection: lfsCollections.uploaded,
|
|
30
|
+
limit: 500
|
|
27
31
|
}
|
|
28
32
|
]);
|
|
29
|
-
const [uploads = [], staging = [], ending = [], listed = [], locks = []] = snapshot.results;
|
|
33
|
+
const [uploads = [], staging = [], ending = [], listed = [], locks = [], uploaded = []] = snapshot.results;
|
|
30
34
|
if (uploads.length + staging.length + ending.length > 0) return "waits";
|
|
31
|
-
const found = listed.length > 0 ? listed : locks;
|
|
35
|
+
const found = listed.length > 0 ? listed : locks.length > 0 ? locks : uploaded;
|
|
32
36
|
if (found.length === 0) return "done";
|
|
33
37
|
const keys = yield* Effect.forEach(listed, (row) => Effect.map(decodeRow(ListedRow, row, `LFS object ${row.id}`), (object) => object.key));
|
|
34
38
|
yield* Effect.forEach(keys, (key) => bucketDo(bucket.remove(key)), {
|
package/dist/lfs/rows.mjs
CHANGED
|
@@ -11,14 +11,16 @@ import * as Schema from "effect/Schema";
|
|
|
11
11
|
const lfsCollections = {
|
|
12
12
|
/** Each LFS object the repo lists, by its oid. Only a deleted repo unlists. */
|
|
13
13
|
objects: "lfs/objects",
|
|
14
|
-
/** Each LFS object an upload link was given for, by its oid, until listed. */
|
|
14
|
+
/** Each LFS object an upload link was given for, by its oid and its uploader, until listed. */
|
|
15
15
|
uploads: "lfs/uploads",
|
|
16
16
|
/** A Worker upload's staging key, by its due `removeAt` and its ID. */
|
|
17
17
|
staging: "lfs/staging",
|
|
18
18
|
/** An LFS object upkeep is deleting, by its oid, which no verify lists. */
|
|
19
19
|
ending: "lfs/ending",
|
|
20
20
|
/** Each LFS lock, by its path's SHA-256. */
|
|
21
|
-
locks: "lfs/locks"
|
|
21
|
+
locks: "lfs/locks",
|
|
22
|
+
/** Each object a caller sent bytes for, by the day, the caller's writer and the oid. */
|
|
23
|
+
uploaded: "lfs/uploaded"
|
|
22
24
|
};
|
|
23
25
|
/**
|
|
24
26
|
* The largest object LFS takes: R2's largest put in one request, 5 GiB less 5 MiB, since a
|
|
@@ -33,6 +35,11 @@ const linkLife = /* @__PURE__ */ millis("15 minutes");
|
|
|
33
35
|
*/
|
|
34
36
|
const uploadGrace = /* @__PURE__ */ millis("1 day");
|
|
35
37
|
/**
|
|
38
|
+
* How long a caller's upload counts as its own, for the pointer rule: a day from its verified
|
|
39
|
+
* bytes, so a pointer it pushes to them passes though no ref it sees reaches them yet.
|
|
40
|
+
*/
|
|
41
|
+
const uploadedKept = /* @__PURE__ */ millis("1 day");
|
|
42
|
+
/**
|
|
36
43
|
* A listed object: its bytes are at `key`, checked. A signed upload's are at its upload row's
|
|
37
44
|
* `objectKey`, and a Worker upload's stay at the staging key they streamed to, which only they
|
|
38
45
|
* were ever written to.
|
|
@@ -86,10 +93,20 @@ const listedKey = (oid) => ({
|
|
|
86
93
|
collection: lfsCollections.objects,
|
|
87
94
|
id: oid
|
|
88
95
|
});
|
|
89
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Who an upload row is for: `ownWriter`'s SHA-256 of the caller's actor ID, or this for a caller
|
|
98
|
+
* with none. Each uploader's row has its own generation, so its signed links write a key no other
|
|
99
|
+
* caller's links write, and a verify heads only the caller's own: bytes another caller sent prove
|
|
100
|
+
* nothing of this one (#1943).
|
|
101
|
+
*/
|
|
102
|
+
const anonymousUploader = "anonymous";
|
|
103
|
+
const uploadId = (oid, uploader) => `${oid}.${uploader}`;
|
|
104
|
+
const uploadKey = (oid, uploader) => ({
|
|
90
105
|
collection: lfsCollections.uploads,
|
|
91
|
-
id: oid
|
|
106
|
+
id: uploadId(oid, uploader)
|
|
92
107
|
});
|
|
108
|
+
/** The oid an upload row's ID names, before its uploader. */
|
|
109
|
+
const uploadOid = (id) => id.slice(0, id.indexOf("."));
|
|
93
110
|
/** An ending row's key: its upload's oid and generation, so two generations' rows never meet. */
|
|
94
111
|
const endingKey = (oid, generation) => ({
|
|
95
112
|
collection: lfsCollections.ending,
|
|
@@ -113,8 +130,8 @@ const listedRead = (oid) => ({
|
|
|
113
130
|
collection: lfsCollections.objects,
|
|
114
131
|
id: oid
|
|
115
132
|
});
|
|
116
|
-
const uploadRead = (oid) => ({
|
|
133
|
+
const uploadRead = (oid, uploader) => ({
|
|
117
134
|
collection: lfsCollections.uploads,
|
|
118
|
-
id: oid
|
|
135
|
+
id: uploadId(oid, uploader)
|
|
119
136
|
});
|
|
120
|
-
export { EndingRow, ListedRow, LockRow, StagingRow, UploadRow, endingKey, largestObject, lfsCollections, linkLife, listedKey, listedRead, lockKey, lockRead, objectKey, stagingId, stagingKey, stagingRead, streamMost, uploadGrace, uploadKey, uploadRead };
|
|
137
|
+
export { EndingRow, ListedRow, LockRow, StagingRow, UploadRow, anonymousUploader, endingKey, largestObject, lfsCollections, linkLife, listedKey, listedRead, lockKey, lockRead, objectKey, stagingId, stagingKey, stagingRead, streamMost, uploadGrace, uploadKey, uploadOid, uploadRead, uploadedKept };
|
package/dist/lfs/service.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LfsFeature } from "../contracts/lfs.mjs";
|
|
1
|
+
import { LfsFeature, LfsOptions } from "../contracts/lfs.mjs";
|
|
2
2
|
import { GitError } from "../contracts/result.mjs";
|
|
3
3
|
import "../core/parts.mjs";
|
|
4
4
|
import { LfsCall } from "./objects.mjs";
|
|
@@ -10,5 +10,8 @@ export interface LfsRoute extends LfsCall {
|
|
|
10
10
|
}
|
|
11
11
|
/** Git LFS's API for a server's repos, its objects in `bucket`. */
|
|
12
12
|
export type LfsService = (call: LfsRoute) => Effect.Effect<Response, GitError>;
|
|
13
|
-
/**
|
|
14
|
-
|
|
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;
|
package/dist/lfs/service.mjs
CHANGED
|
@@ -4,8 +4,14 @@ 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
|
-
|
|
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
|
+
});
|
|
9
15
|
const methodNotAllowed = (allow) => Effect.succeed(lfsAnswer(405, { message: "Method not allowed" }, { allow }));
|
|
10
16
|
/** LFS's routes over `parts`, provided `needs`, the server's services, which `openRepo` reads. */
|
|
11
17
|
const lfsService = (needs, parts) => (call) => Effect.provideContext(served(parts, call), needs);
|
package/dist/lfs/upkeep.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { bucketDo } from "../storage/calls.mjs";
|
|
2
2
|
import { decodeRow } from "../store/errors.mjs";
|
|
3
|
-
import { EndingRow, ListedRow, StagingRow, UploadRow, endingKey, lfsCollections, listedRead, objectKey,
|
|
3
|
+
import { EndingRow, ListedRow, StagingRow, UploadRow, endingKey, lfsCollections, listedRead, objectKey, uploadOid } from "./rows.mjs";
|
|
4
|
+
import { uploadedSweepOf, uploadedSweepRead } from "./uploaded.mjs";
|
|
4
5
|
import * as Effect from "effect/Effect";
|
|
5
6
|
// src/lfs/upkeep.ts
|
|
6
7
|
/**
|
|
@@ -13,7 +14,7 @@ import * as Effect from "effect/Effect";
|
|
|
13
14
|
* lists it again, and an upload after gets a key of its own. A delete that lands late, after a try
|
|
14
15
|
* that sent it timed out, reaches only bytes no listing names. A key is deleted before the row
|
|
15
16
|
* that names it is dropped, so a crash between leaves the row, and the next step deletes the key
|
|
16
|
-
* again.
|
|
17
|
+
* again. Own uploads go once their days are past, as receipts do.
|
|
17
18
|
*/
|
|
18
19
|
/** The most rows of each kind a step ends. */
|
|
19
20
|
const upkeepPage = 500;
|
|
@@ -31,18 +32,23 @@ const lfsUpkeep = (rows, bucket, signed) => ({ repo, at }) => upkeepStep({
|
|
|
31
32
|
const did = { more: true };
|
|
32
33
|
const earliest = (a, b) => a === void 0 ? b : b === void 0 ? a : Math.min(a, b);
|
|
33
34
|
/**
|
|
34
|
-
* One step: the ending rows, else the due staging rows, else the due upload rows
|
|
35
|
-
* and answers `more`; with nothing due, it answers when
|
|
35
|
+
* One step: the ending rows, else the due staging rows, else the due upload rows, else the own
|
|
36
|
+
* uploads past their days. Each does a page and answers `more`; with nothing due, it answers when
|
|
37
|
+
* the soonest row is.
|
|
36
38
|
*/
|
|
37
39
|
const upkeepStep = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
|
|
38
|
-
const snapshot = yield* upkeep.rows.read(upkeep.repo, [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
const snapshot = yield* upkeep.rows.read(upkeep.repo, [
|
|
41
|
+
{
|
|
42
|
+
collection: lfsCollections.ending,
|
|
43
|
+
limit: upkeepPage
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
collection: lfsCollections.staging,
|
|
47
|
+
limit: upkeepPage
|
|
48
|
+
},
|
|
49
|
+
uploadedSweepRead
|
|
50
|
+
]);
|
|
51
|
+
const [ending = [], staging = [], uploaded = []] = snapshot.results;
|
|
46
52
|
const endings = yield* Effect.forEach(ending, (row) => Effect.map(decodeRow(EndingRow, row, `LFS ending row ${row.id}`), (decoded) => ({
|
|
47
53
|
id: row.id,
|
|
48
54
|
...decoded
|
|
@@ -55,8 +61,13 @@ const upkeepStep = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
|
|
|
55
61
|
const dueStages = stages.filter((stage) => stage.removeAt <= upkeep.at);
|
|
56
62
|
if (dueStages.length > 0) return yield* endStages(upkeep, snapshot.version, dueStages);
|
|
57
63
|
const uploads = yield* dueUploads(upkeep);
|
|
58
|
-
if (uploads.
|
|
59
|
-
const
|
|
64
|
+
if (uploads.ids.length > 0) return yield* endUploads(upkeep, uploads.ids);
|
|
65
|
+
const sweep = uploadedSweepOf(uploaded, upkeep.at);
|
|
66
|
+
if (sweep.delete.length > 0) {
|
|
67
|
+
yield* upkeep.rows.commit(upkeep.repo, snapshot.version, { delete: sweep.delete });
|
|
68
|
+
return did;
|
|
69
|
+
}
|
|
70
|
+
const due = stages.map((stage) => stage.removeAt).reduce(earliest, earliest(uploads.next, sweep.due));
|
|
60
71
|
return due === void 0 ? { more: false } : {
|
|
61
72
|
more: false,
|
|
62
73
|
due
|
|
@@ -86,9 +97,9 @@ const endStages = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep, version,
|
|
|
86
97
|
})) });
|
|
87
98
|
return did;
|
|
88
99
|
});
|
|
89
|
-
/** Up to a page of the upload rows that are due, and when the soonest of the rest is. */
|
|
100
|
+
/** Up to a page of the upload rows that are due, by ID, and when the soonest of the rest is. */
|
|
90
101
|
const dueUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
|
|
91
|
-
const
|
|
102
|
+
const ids = [];
|
|
92
103
|
let next;
|
|
93
104
|
let after;
|
|
94
105
|
for (;;) {
|
|
@@ -103,11 +114,11 @@ const dueUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
|
|
|
103
114
|
for (const row of rows) {
|
|
104
115
|
const upload = yield* uploadOf(row);
|
|
105
116
|
if (upload.removeAt > upkeep.at) next = earliest(next, upload.removeAt);
|
|
106
|
-
else if (
|
|
117
|
+
else if (ids.length < upkeepPage) ids.push(row.id);
|
|
107
118
|
}
|
|
108
119
|
after = rows.at(-1)?.id;
|
|
109
120
|
if (rows.length < upkeepPage || after === void 0) return {
|
|
110
|
-
|
|
121
|
+
ids,
|
|
111
122
|
next
|
|
112
123
|
};
|
|
113
124
|
}
|
|
@@ -115,20 +126,24 @@ const dueUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
|
|
|
115
126
|
const uploadOf = (row) => decodeRow(UploadRow, row, `LFS object ${row.id}'s upload`);
|
|
116
127
|
const listedOf = (row) => decodeRow(ListedRow, row, `LFS object ${row.id}`);
|
|
117
128
|
/**
|
|
118
|
-
* Drops each due upload row, read again at one version. On a signed bucket, an object
|
|
119
|
-
* unlisted, or listed at another key,
|
|
120
|
-
* Worker's bytes are at staging keys, which their own rows end.
|
|
129
|
+
* Drops each due upload row, by its ID, read again at one version. On a signed bucket, an object
|
|
130
|
+
* still unlisted, or listed at another key, as another uploader's bytes are, gets its ending row in
|
|
131
|
+
* the same commit, then its bytes go; a Worker's bytes are at staging keys, which their own rows end.
|
|
121
132
|
*/
|
|
122
|
-
const endUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep,
|
|
123
|
-
const snapshot = yield* upkeep.rows.read(upkeep.repo,
|
|
133
|
+
const endUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep, ids) {
|
|
134
|
+
const snapshot = yield* upkeep.rows.read(upkeep.repo, ids.flatMap((id) => [{
|
|
135
|
+
collection: lfsCollections.uploads,
|
|
136
|
+
id
|
|
137
|
+
}, listedRead(uploadOid(id))]));
|
|
124
138
|
const dropped = [];
|
|
125
139
|
const ended = [];
|
|
126
|
-
for (const [index,
|
|
140
|
+
for (const [index, id] of ids.entries()) {
|
|
141
|
+
const oid = uploadOid(id);
|
|
127
142
|
const uploadRow = snapshot.results[index * 2]?.[0];
|
|
128
143
|
const listedRow = snapshot.results[index * 2 + 1]?.[0];
|
|
129
144
|
const upload = uploadRow === void 0 ? void 0 : yield* uploadOf(uploadRow);
|
|
130
145
|
if (upload === void 0 || upload.removeAt > upkeep.at) continue;
|
|
131
|
-
dropped.push(
|
|
146
|
+
dropped.push(id);
|
|
132
147
|
const key = objectKey(upkeep.repo, oid, upload.generation);
|
|
133
148
|
const listed = listedRow === void 0 ? void 0 : yield* listedOf(listedRow);
|
|
134
149
|
if (upkeep.signed && listed?.key !== key) ended.push({
|
|
@@ -143,7 +158,10 @@ const endUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep, oids) {
|
|
|
143
158
|
id,
|
|
144
159
|
value: { key }
|
|
145
160
|
})),
|
|
146
|
-
delete: dropped.map(
|
|
161
|
+
delete: dropped.map((id) => ({
|
|
162
|
+
collection: lfsCollections.uploads,
|
|
163
|
+
id
|
|
164
|
+
}))
|
|
147
165
|
});
|
|
148
166
|
if (!committed.ok || ended.length === 0) return did;
|
|
149
167
|
return yield* endObjects(upkeep, committed.version, ended);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { largestObject } from "./rows.mjs";
|
|
2
|
+
// src/lfs/upload-most.ts
|
|
3
|
+
/**
|
|
4
|
+
* The largest Git LFS upload through the server, `workerUploadMost`, for a bucket that signs no
|
|
5
|
+
* links: the least of what the platform's body cap passes on, what its CPU cap lets the upload
|
|
6
|
+
* hash and store, and `largestObject`. A larger one is refused before a byte streams, at the
|
|
7
|
+
* batch, so git-lfs never starts it.
|
|
8
|
+
*/
|
|
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
|
+
const cpuShare = .8;
|
|
11
|
+
/** The bytes `cpuMs` of CPU hashes and stores, at `uploadMsPerMiB` within `cpuShare` of it. */
|
|
12
|
+
const cpuBytes = (cpuMs) => Math.floor(cpuShare * cpuMs / 64 * 1024 ** 2);
|
|
13
|
+
/** The largest upload `caps` let finish: `largestObject` where neither binds below it. */
|
|
14
|
+
const uploadMostOf = (caps) => {
|
|
15
|
+
const bounds = [{
|
|
16
|
+
bytes: largestObject,
|
|
17
|
+
by: "object"
|
|
18
|
+
}];
|
|
19
|
+
if (caps.bodyCap !== void 0) bounds.push({
|
|
20
|
+
bytes: caps.bodyCap,
|
|
21
|
+
by: "body"
|
|
22
|
+
});
|
|
23
|
+
if (caps.cpuMs !== void 0) bounds.push({
|
|
24
|
+
bytes: cpuBytes(caps.cpuMs),
|
|
25
|
+
by: "cpu"
|
|
26
|
+
});
|
|
27
|
+
return bounds.reduce((least, bound) => bound.bytes < least.bytes ? bound : least);
|
|
28
|
+
};
|
|
29
|
+
/** Why `caps` aren't caps: each must be a whole number of bytes or milliseconds above 0. */
|
|
30
|
+
const capsRefusal = (caps) => {
|
|
31
|
+
for (const [name, value] of Object.entries(caps)) if (value !== void 0 && !(Number.isSafeInteger(value) && value > 0)) return `An LFS upload's ${name} is a whole number above 0, not ${String(value)}`;
|
|
32
|
+
};
|
|
33
|
+
/** What each cap that sets the largest upload is, as a refusal names it. */
|
|
34
|
+
const setBy = {
|
|
35
|
+
body: "the largest body its platform passes on",
|
|
36
|
+
cpu: "what its CPU cap lets it hash and store",
|
|
37
|
+
object: "R2's largest single put"
|
|
38
|
+
};
|
|
39
|
+
/** Why an upload of more than `most` is refused, and what takes it. */
|
|
40
|
+
const pastMost = (most) => `An upload through this server is at most ${most.bytes} bytes, ${setBy[most.by]}: a bucket that signs its links takes a larger one straight`;
|
|
41
|
+
export { capsRefusal, cpuShare, pastMost, uploadMostOf };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { dayMs, dayOf, sweepOf } from "../core/receipts.mjs";
|
|
2
|
+
import { decodeRow } from "../store/errors.mjs";
|
|
3
|
+
import { lfsCollections, uploadedKept } from "./rows.mjs";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
// src/lfs/uploaded.ts
|
|
7
|
+
/**
|
|
8
|
+
* A caller's own upload: an object whose bytes it sent, checked against the oid, which its pushes'
|
|
9
|
+
* pointers may name for `uploadedKept` after, though no ref it sees reaches the object yet. So a
|
|
10
|
+
* caller who sees only some refs proves it holds an object's bytes by sending them, and the
|
|
11
|
+
* pointer rule never takes a hidden object's oid alone as proof (#1943). Only the caller's writer,
|
|
12
|
+
* `ownWriter`'s SHA-256 of its actor's ID, names it, so the row's ID is one length; an anonymous
|
|
13
|
+
* caller keeps none.
|
|
14
|
+
*/
|
|
15
|
+
const UploadedRow = /* @__PURE__ */ Schema.Struct({ at: Schema.Int });
|
|
16
|
+
/** An own upload's ID: its day, padded so the oldest read first, its writer and its oid. */
|
|
17
|
+
const uploadedId = (at, writer, oid) => `${dayOf(at)}:${writer}:${oid}`;
|
|
18
|
+
/** The row a verified upload of `oid` by `writer` at `at` puts, in its commit. */
|
|
19
|
+
const uploadedRow = (writer, oid, at) => ({
|
|
20
|
+
collection: lfsCollections.uploaded,
|
|
21
|
+
id: uploadedId(at, writer, oid),
|
|
22
|
+
value: { at }
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Which of `oids` `writer` uploaded to `repo` within `uploadedKept` before `at`: one read of each
|
|
26
|
+
* one's rows from today and yesterday, at most `sweepPage` oids a read.
|
|
27
|
+
*/
|
|
28
|
+
const uploadedOf = /* @__PURE__ */ Effect.fnUntraced(function* (rows, repo, writer, oids, at) {
|
|
29
|
+
const days = [at, at - dayMs];
|
|
30
|
+
const own = /* @__PURE__ */ new Set();
|
|
31
|
+
for (let from = 0; from < oids.length; from += 500) {
|
|
32
|
+
const chunk = oids.slice(from, from + 500);
|
|
33
|
+
const reads = chunk.flatMap((oid) => days.map((day) => ({
|
|
34
|
+
collection: lfsCollections.uploaded,
|
|
35
|
+
id: uploadedId(day, writer, oid)
|
|
36
|
+
})));
|
|
37
|
+
const snapshot = yield* rows.read(repo, reads);
|
|
38
|
+
for (const [index, found] of snapshot.results.entries()) {
|
|
39
|
+
const oid = chunk[Math.floor(index / days.length)];
|
|
40
|
+
for (const row of found) {
|
|
41
|
+
const upload = yield* decodeRow(UploadedRow, row, `LFS upload '${row.id}'`);
|
|
42
|
+
if (oid !== void 0 && at < upload.at + uploadedKept) own.add(oid);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return own;
|
|
47
|
+
});
|
|
48
|
+
/** What LFS's upkeep reads to sweep own uploads: the oldest first. */
|
|
49
|
+
const uploadedSweepRead = {
|
|
50
|
+
collection: lfsCollections.uploaded,
|
|
51
|
+
limit: 500
|
|
52
|
+
};
|
|
53
|
+
const uploadedKey = (id) => [{
|
|
54
|
+
collection: lfsCollections.uploaded,
|
|
55
|
+
id
|
|
56
|
+
}];
|
|
57
|
+
/** A sweep of own uploads, of `rows` read by `uploadedSweepRead`: those whose days are past at `at`. */
|
|
58
|
+
const uploadedSweepOf = (rows, at) => sweepOf(rows, at, uploadedKey);
|
|
59
|
+
export { UploadedRow, uploadedOf, uploadedRow, uploadedSweepOf, uploadedSweepRead };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { hexOf } from "./hex.mjs";
|
|
2
|
+
import { Sha256 } from "./sha256.mjs";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Exit from "effect/Exit";
|
|
5
|
+
// src/protocol/bytes/sha256-hasher.ts
|
|
6
|
+
const platform = globalThis;
|
|
7
|
+
/** This runtime's hashes. */
|
|
8
|
+
const runtime = {
|
|
9
|
+
DigestStream: platform.crypto?.DigestStream,
|
|
10
|
+
createHash: platform.process?.getBuiltinModule?.("node:crypto").createHash
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A `Sha256Hasher` through the first hash `on` has: `DigestStream`, whose writes are each awaited
|
|
14
|
+
* so that it holds none of the body's bytes, then `createHash`, then `Sha256`. Its sum is read once.
|
|
15
|
+
*
|
|
16
|
+
* A `DigestStream`'s writer is held only while one of its Effects runs, and let go however that
|
|
17
|
+
* ends: a hasher dropped between them, as by an upload whose put failed, locks nothing. One
|
|
18
|
+
* interrupted at a write or its sum is aborted, without waiting, and is done.
|
|
19
|
+
*/
|
|
20
|
+
const sha256HasherOn = (on) => {
|
|
21
|
+
if (on.DigestStream !== void 0) {
|
|
22
|
+
const stream = new on.DigestStream("SHA-256");
|
|
23
|
+
stream.digest.catch(() => void 0);
|
|
24
|
+
/** `use` on the stream's writer, taken for it alone, the stream aborted if it's interrupted. */
|
|
25
|
+
const held = (use) => Effect.acquireUseRelease(Effect.sync(() => stream.getWriter()), (writer) => Effect.promise(() => use(writer)), (writer, exit) => Effect.sync(() => {
|
|
26
|
+
writer.releaseLock();
|
|
27
|
+
if (Exit.hasInterrupts(exit)) stream.abort().catch(() => void 0);
|
|
28
|
+
}));
|
|
29
|
+
return {
|
|
30
|
+
write: (bytes) => held((writer) => writer.write(bytes)),
|
|
31
|
+
hex: held((writer) => writer.close().then(() => stream.digest.then((sum) => hexOf(new Uint8Array(sum)))))
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (on.createHash !== void 0) {
|
|
35
|
+
const hash = on.createHash("sha256");
|
|
36
|
+
return {
|
|
37
|
+
write: (bytes) => Effect.sync(() => {
|
|
38
|
+
hash.update(bytes);
|
|
39
|
+
}),
|
|
40
|
+
hex: Effect.sync(() => hash.digest("hex"))
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const sha = new Sha256();
|
|
44
|
+
return {
|
|
45
|
+
write: (bytes) => Effect.sync(() => sha.update(bytes)),
|
|
46
|
+
hex: Effect.sync(() => sha.hex())
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
/** A `Sha256Hasher` through this runtime's own hash, or `Sha256` where it has none. */
|
|
50
|
+
const nativeSha256Hasher = () => sha256HasherOn(runtime);
|
|
51
|
+
export { nativeSha256Hasher, sha256HasherOn };
|
|
@@ -16,4 +16,9 @@ const isOid = (oid) => /^[0-9a-f]{40}$/.test(oid);
|
|
|
16
16
|
* message. JSON's string form, which never throws for a string.
|
|
17
17
|
*/
|
|
18
18
|
const quoted = (text) => JSON.stringify(text);
|
|
19
|
-
|
|
19
|
+
/** `text`'s first `most` UTF-16 units, the first half of a surrogate pair the cut splits dropped. */
|
|
20
|
+
const cutWords = (text, most) => {
|
|
21
|
+
const cut = text.slice(0, most);
|
|
22
|
+
return /[\uD800-\uDBFF]$/u.test(cut) ? cut.slice(0, -1) : cut;
|
|
23
|
+
};
|
|
24
|
+
export { cutWords, isOid, isWellFormed, quoted, utf8 };
|
|
@@ -202,7 +202,10 @@ const entryFault = (entry) => {
|
|
|
202
202
|
if (entry.name.length > nameMost) return finding("largePathname", "contains excessively large pathname");
|
|
203
203
|
if (entry.zeroPadded) return finding("zeroPaddedFilemode", "contains zero-padded file modes");
|
|
204
204
|
};
|
|
205
|
-
const duplicate = () =>
|
|
205
|
+
const duplicate = (name) => ({
|
|
206
|
+
...finding("duplicateEntries", "contains duplicate file entries"),
|
|
207
|
+
name: new TextDecoder().decode(name)
|
|
208
|
+
});
|
|
206
209
|
/** Whether an entry before `end` is a file, any kind but a folder, named `name`. */
|
|
207
210
|
const fileBefore = (bytes, end, name) => {
|
|
208
211
|
for (let at = 0; at < end;) {
|
|
@@ -229,9 +232,9 @@ const orderReader = (bytes) => {
|
|
|
229
232
|
const tree = entry.kind === "tree";
|
|
230
233
|
const before = previous;
|
|
231
234
|
previous = entry;
|
|
232
|
-
if (before !== void 0 && compareNames(before.name, before.kind === "tree", entry.name, tree) >= 0) return sameName(before.name, entry.name) || tree && fileBefore(bytes, at, entry.name) ? duplicate() : finding("treeNotSorted", "not properly sorted");
|
|
235
|
+
if (before !== void 0 && compareNames(before.name, before.kind === "tree", entry.name, tree) >= 0) return sameName(before.name, entry.name) || tree && fileBefore(bytes, at, entry.name) ? duplicate(entry.name) : finding("treeNotSorted", "not properly sorted");
|
|
233
236
|
for (let top = files.at(-1); top !== void 0; top = files.at(-1)) {
|
|
234
|
-
if (tree && sameName(top, entry.name)) return duplicate();
|
|
237
|
+
if (tree && sameName(top, entry.name)) return duplicate(entry.name);
|
|
235
238
|
if (top.length < entry.name.length && (entry.name[top.length] ?? slash) < slash && sameName(top, entry.name.subarray(0, top.length))) break;
|
|
236
239
|
files.pop();
|
|
237
240
|
}
|