@ref0/git 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/authorize.d.mts +1 -1
- package/dist/auth/fences.d.mts +1 -1
- package/dist/auth/host-function.mjs +2 -2
- package/dist/auth/identify.d.mts +1 -1
- package/dist/auth/tokens.d.mts +1 -1
- package/dist/client/client.mjs +2 -3
- package/dist/client/local.mjs +13 -3
- package/dist/contracts/calls-spent.mjs +3 -2
- package/dist/contracts/client.d.mts +2 -2
- package/dist/contracts/handlers.d.mts +2 -1
- package/dist/contracts/objects.d.mts +2 -2
- package/dist/contracts/promises.d.mts +13 -38
- package/dist/contracts/promises.mjs +13 -0
- package/dist/contracts/queue.d.mts +2 -1
- package/dist/contracts/result.d.mts +7 -0
- package/dist/contracts/server.d.mts +67 -40
- package/dist/contracts/sync.d.mts +1 -1
- package/dist/contracts/topics.d.mts +7 -1
- package/dist/core/access.d.mts +1 -1
- package/dist/core/call-names.d.mts +1 -0
- package/dist/core/call-names.mjs +93 -0
- package/dist/core/events/deliver.mjs +14 -7
- package/dist/core/events/stream.d.mts +1 -1
- package/dist/core/events/stream.mjs +8 -1
- package/dist/core/hooks/post-receive.mjs +15 -7
- package/dist/core/promise.mjs +28 -10
- package/dist/core/push.mjs +2 -1
- package/dist/core/seam.d.mts +2 -0
- package/dist/core/seam.mjs +19 -6
- package/dist/extend.d.mts +2 -1
- package/dist/extend.mjs +3 -1
- package/dist/index.d.mts +2 -2
- package/dist/lfs/objects.mjs +1 -1
- package/dist/lfs/rows.mjs +1 -1
- package/dist/queue/advance.mjs +2 -1
- package/dist/queue/host.d.mts +1 -1
- package/dist/queue/host.mjs +1 -1
- package/dist/queue/schedule.mjs +1 -1
- package/dist/rest/blobs.d.mts +15 -15
- package/dist/rest/client.mjs +2 -2
- package/dist/rest/commits.d.mts +91 -91
- package/dist/rest/errors.d.mts +2 -2
- package/dist/rest/errors.mjs +2 -2
- package/dist/rest/files.d.mts +81 -81
- package/dist/rest/handler.d.mts +1 -0
- package/dist/rest/handler.mjs +39 -16
- package/dist/rest/handlers.mjs +6 -6
- package/dist/rest/repos.d.mts +38 -38
- package/dist/rest/tags.d.mts +41 -41
- package/dist/rest/tokens.d.mts +145 -145
- package/dist/rest/work.d.mts +43 -43
- package/dist/server/extension.d.mts +6 -3
- package/dist/server/extension.mjs +39 -31
- package/dist/server/lifecycle.d.mts +3 -0
- package/dist/server/lifecycle.mjs +89 -0
- package/dist/server/routes.d.mts +7 -4
- package/dist/server/routes.mjs +12 -19
- package/dist/server/server.d.mts +8 -2
- package/dist/server/server.mjs +280 -104
- package/dist/signin/context.d.mts +1 -1
- package/dist/signin/grants.d.mts +1 -1
- package/dist/storage/bits.mjs +41 -0
- package/dist/storage/calls.d.mts +1 -1
- package/dist/storage/calls.mjs +2 -2
- package/dist/storage/fetch.d.mts +3 -1
- package/dist/storage/fetch.mjs +230 -24
- package/dist/storage/index-bitmaps.d.mts +1 -1
- package/dist/storage/index-build.d.mts +1 -1
- package/dist/storage/index-build.mjs +27 -13
- package/dist/storage/index-fetch.d.mts +1 -0
- package/dist/storage/index-fetch.mjs +103 -182
- package/dist/storage/index-graph.d.mts +1 -1
- package/dist/storage/loose.mjs +3 -2
- package/dist/storage/pack-order.d.mts +1 -1
- package/dist/storage/pack-order.mjs +3 -1
- package/dist/storage/pack-ranges.d.mts +1 -1
- package/dist/storage/pack-reads.d.mts +1 -1
- package/dist/storage/pack-reads.mjs +17 -0
- package/dist/storage/pack-receive.d.mts +2 -2
- package/dist/storage/pack-receive.mjs +1 -1
- package/dist/storage/packs.d.mts +2 -2
- package/dist/storage/packs.mjs +10 -7
- package/dist/storage/push-uploads.mjs +2 -1
- package/dist/storage/ready.d.mts +2 -2
- package/dist/storage/receive-links.mjs +1 -1
- package/dist/storage/repack.d.mts +2 -2
- package/dist/storage/rows.d.mts +2 -1
- package/dist/storage/rows.mjs +1 -1
- package/dist/storage/send-list.d.mts +8 -0
- package/dist/storage/send-list.mjs +319 -0
- package/dist/storage/shallow.d.mts +1 -2
- package/dist/storage/unpack.mjs +5 -3
- package/dist/storage/walk.d.mts +2 -1
- package/dist/storage/walk.mjs +14 -8
- package/dist/store/catalogue.d.mts +1 -1
- package/dist/store/closed.d.mts +21 -0
- package/dist/store/closed.mjs +34 -0
- package/dist/store/crossing.mjs +9 -6
- package/dist/store/cursor-seal.mjs +4 -1
- package/dist/store/errors.mjs +13 -7
- package/dist/store/outbox.mjs +4 -2
- package/dist/store/promises.d.mts +5 -0
- package/dist/store/promises.mjs +258 -0
- package/dist/sync/bound.mjs +9 -4
- package/dist/sync/jobs.d.mts +3 -3
- package/dist/sync/jobs.mjs +28 -25
- package/dist/sync/tries.mjs +2 -2
- package/dist/topics/advance.mjs +2 -1
- package/dist/topics/calls.mjs +3 -3
- package/dist/topics/host.d.mts +1 -1
- package/dist/topics/host.mjs +1 -1
- package/dist/topics/topic.mjs +22 -7
- package/package.json +2 -2
package/dist/auth/fences.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { tryClosing } from "../store/closed.mjs";
|
|
2
2
|
import { gitError } from "../store/errors.mjs";
|
|
3
3
|
import { randomText } from "../store/random.mjs";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
@@ -39,7 +39,7 @@ const failed = (reports, name, about, cause, timedOut) => {
|
|
|
39
39
|
* is interrupted or runs out of time.
|
|
40
40
|
*/
|
|
41
41
|
const hostCall = (reports, name, about, run, options = {}) => {
|
|
42
|
-
const call =
|
|
42
|
+
const call = tryClosing(async (signal) => run(signal), (cause) => failed(reports, name, about, cause, false));
|
|
43
43
|
const { timeout } = options;
|
|
44
44
|
if (timeout === void 0) return call;
|
|
45
45
|
return Effect.timeoutOrElse(call, {
|
package/dist/auth/identify.d.mts
CHANGED
package/dist/auth/tokens.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import "../contracts/promises.mjs";
|
|
1
2
|
import "../contracts/actors.mjs";
|
|
2
3
|
import "../contracts/operations.mjs";
|
|
3
4
|
import "../contracts/services.mjs";
|
|
4
5
|
import { TokensFeature } from "../contracts/tokens.mjs";
|
|
5
6
|
import "../store/outbox.mjs";
|
|
6
|
-
import "../contracts/promises.mjs";
|
|
7
7
|
import { JobDefinition, Moment, Read, Row } from "@ref0/infra";
|
|
8
8
|
import "effect/Effect";
|
|
9
9
|
/** Turns on Git's own tokens. */
|
package/dist/client/client.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { guardedCalls, promiseCalls } from "../core/promise.mjs";
|
|
1
|
+
import { guardedCalls, noDoor, promiseCalls } from "../core/promise.mjs";
|
|
2
2
|
import { resultIn } from "../store/crossing.mjs";
|
|
3
3
|
import { gitHttp } from "./git-http.mjs";
|
|
4
4
|
import { localSide } from "./local.mjs";
|
|
5
5
|
import { fetchInto, pushFrom, remoteRefs } from "./remote.mjs";
|
|
6
|
-
import * as Effect from "effect/Effect";
|
|
7
6
|
// src/client/client.ts
|
|
8
7
|
/**
|
|
9
8
|
* A client of one remote, as Effects: its remote calls over Git's smart HTTP, and its local
|
|
@@ -19,7 +18,7 @@ const effectGitClient = (options) => {
|
|
|
19
18
|
fetch: (input) => fetchInto(http, local, input),
|
|
20
19
|
push: (input) => pushFrom(http, local, input),
|
|
21
20
|
...local.calls
|
|
22
|
-
},
|
|
21
|
+
}, noDoor);
|
|
23
22
|
};
|
|
24
23
|
/**
|
|
25
24
|
* A client of `options.url`: `remoteRefs`, `fetch` and `push` on the remote, and the server's
|
package/dist/client/local.mjs
CHANGED
|
@@ -15,12 +15,17 @@ import { engineParts } from "../engine/parts.mjs";
|
|
|
15
15
|
import { entryOf } from "../store/catalogue.mjs";
|
|
16
16
|
import { gitError } from "../store/errors.mjs";
|
|
17
17
|
import { gitStore } from "../store/git-store.mjs";
|
|
18
|
+
import { openDoor, promisesStore } from "../store/promises.mjs";
|
|
18
19
|
import { newInternalId } from "../store/scopes.mjs";
|
|
19
|
-
import { resultIn } from "../store/crossing.mjs";
|
|
20
|
+
import { noCall, resultIn, syncIn } from "../store/crossing.mjs";
|
|
20
21
|
import { defaultFetchLimits } from "../storage/fetch.mjs";
|
|
21
22
|
import { loose } from "../storage/loose.mjs";
|
|
23
|
+
import { Records } from "@ref0/infra";
|
|
22
24
|
import * as Effect from "effect/Effect";
|
|
23
|
-
import
|
|
25
|
+
import * as Context from "effect/Context";
|
|
26
|
+
import * as Layer from "effect/Layer";
|
|
27
|
+
import * as Memory from "@ref0/infra/memory";
|
|
28
|
+
import * as Scope$1 from "effect/Scope";
|
|
24
29
|
// src/client/local.ts
|
|
25
30
|
/** The one repo a client's storage holds, by the name its catalogue lists it under. */
|
|
26
31
|
const localRepo = "local";
|
|
@@ -93,12 +98,17 @@ const engineOf = (given) => {
|
|
|
93
98
|
if (parts === void 0) throw new TypeError("options.engine must be one engine() made");
|
|
94
99
|
return parts;
|
|
95
100
|
};
|
|
101
|
+
/** A store in this process's memory, kept for the client's life, run on the context it built. */
|
|
102
|
+
const memoryStore = () => {
|
|
103
|
+
const built = syncIn(Layer.buildWithScope(Memory.layer(), Scope$1.makeUnsafe()), noCall);
|
|
104
|
+
return promisesStore(Context.get(built, Records.Records), built, openDoor);
|
|
105
|
+
};
|
|
96
106
|
/**
|
|
97
107
|
* A client's local side over `adapter`, a memory store when left out, and `objects`, `loose()`
|
|
98
108
|
* when left out: the server's core, with no queue, deciding everything for its own caller.
|
|
99
109
|
*/
|
|
100
110
|
const localSide = (options) => {
|
|
101
|
-
const adapter = options.adapter ?? { store:
|
|
111
|
+
const adapter = options.adapter ?? { store: memoryStore() };
|
|
102
112
|
const { store } = adapter;
|
|
103
113
|
const { clock, now } = clocksOf(adapter.clock);
|
|
104
114
|
const objects = (options.objects ?? loose()).open({
|
|
@@ -2,9 +2,9 @@ import { isInfraError } from "@ref0/infra";
|
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as EffectResult from "effect/Result";
|
|
4
4
|
import * as Option from "effect/Option";
|
|
5
|
+
import * as Predicate from "effect/Predicate";
|
|
5
6
|
import * as Cause from "effect/Cause";
|
|
6
7
|
import * as Exit from "effect/Exit";
|
|
7
|
-
import * as Predicate from "effect/Predicate";
|
|
8
8
|
// src/contracts/calls-spent.ts
|
|
9
9
|
/**
|
|
10
10
|
* A call that never started, or that the platform refused, past a bound: `most` of `bound`'s calls
|
|
@@ -43,7 +43,8 @@ const callLimitTry = "The server reached its limit of store calls for one reques
|
|
|
43
43
|
const spentRefusal = (spent) => spent.of === "budget" ? {
|
|
44
44
|
code: "RESOURCE_EXHAUSTED",
|
|
45
45
|
message: spent.message,
|
|
46
|
-
hint: "
|
|
46
|
+
hint: "Make fewer calls inside it",
|
|
47
|
+
hostHint: "Raise the CallBudget",
|
|
47
48
|
context: { reason: "call-budget" },
|
|
48
49
|
cause: spent
|
|
49
50
|
} : {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Bucket as Bucket$1, Clock, RecordStore } from "./promises.mjs";
|
|
1
2
|
import { CallInput } from "./actors.mjs";
|
|
2
3
|
import { BlobCalls } from "./blobs.mjs";
|
|
3
4
|
import { CommitCalls } from "./commits.mjs";
|
|
@@ -11,12 +12,11 @@ import { RemoteOptions, WithoutActor } from "./remote.mjs";
|
|
|
11
12
|
import { Result } from "./result.mjs";
|
|
12
13
|
import { TagCalls } from "./tags.mjs";
|
|
13
14
|
import { TreeCalls } from "./trees.mjs";
|
|
14
|
-
import { Bucket, Clock, RecordStore } from "./promises.mjs";
|
|
15
15
|
import { Listing, Page } from "@ref0/infra";
|
|
16
16
|
/** Where a client keeps its objects and refs: the server's keys, with no `jobs`. */
|
|
17
17
|
export interface ClientAdapter {
|
|
18
18
|
readonly store: RecordStore;
|
|
19
|
-
readonly bucket?: Bucket;
|
|
19
|
+
readonly bucket?: Bucket$1;
|
|
20
20
|
/** The store's clock: Effect's when left out. */
|
|
21
21
|
readonly clock?: Clock;
|
|
22
22
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Duration
|
|
1
|
+
import { Duration } from "./promises.mjs";
|
|
2
|
+
import { Retry } from "@ref0/infra";
|
|
2
3
|
/** A host function Git calls inside a request or a job, with the length of one try. */
|
|
3
4
|
export interface HandlerOptions<Handler> {
|
|
4
5
|
readonly handler: Handler;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { Bucket as Bucket$1, Clock } from "./promises.mjs";
|
|
1
2
|
import { CallInput } from "./actors.mjs";
|
|
2
3
|
import "./engine.mjs";
|
|
3
4
|
import { InternalRepoId, Oid } from "./ids.mjs";
|
|
4
5
|
import { RepoStats } from "./repos.mjs";
|
|
5
6
|
import { GitError, Result } from "./result.mjs";
|
|
6
7
|
import { GitStore, Listed, Pack } from "./store.mjs";
|
|
7
|
-
import { Bucket, Clock } from "./promises.mjs";
|
|
8
8
|
import { CallLimits, Key, Listing, Moment, Page, Row } from "@ref0/infra";
|
|
9
9
|
export type Bytes = ReadableStream<Uint8Array>;
|
|
10
10
|
export type ObjectType = 'commit' | 'tree' | 'blob' | 'tag';
|
|
@@ -411,7 +411,7 @@ export interface ObjectsStep {
|
|
|
411
411
|
*/
|
|
412
412
|
export interface ObjectsOpenInput<NeedsBucket extends boolean = boolean> {
|
|
413
413
|
readonly store: GitStore;
|
|
414
|
-
readonly bucket: NeedsBucket extends true ? Bucket : Bucket | undefined;
|
|
414
|
+
readonly bucket: NeedsBucket extends true ? Bucket$1 : Bucket$1 | undefined;
|
|
415
415
|
readonly clock: Clock;
|
|
416
416
|
readonly fetchLimits: EffectiveLimits;
|
|
417
417
|
/**
|
|
@@ -1,52 +1,24 @@
|
|
|
1
|
-
import { Addition, CallOptions, Change, Claim, ClaimRequest, ClaimResult, Committed, Count,
|
|
2
|
-
|
|
1
|
+
import { Addition, CallOptions, Change, Claim, ClaimRequest, ClaimResult, Committed, Count, JobCounts, JobDefinition, JobItem, JobListRequest, JobRef, Listing, Moment, Multipart, Outcome, Page, ProgressStored, ProgressWrite, PutOptions, Range, Read, RetryInput, Scope, Settled, Snapshot, Stored, UrlOptions, Watch, WatchedRow } from "@ref0/infra";
|
|
2
|
+
import * as EffectDuration from "effect/Duration";
|
|
3
|
+
/** Records: the truth, as `Records.Records` gives them. */
|
|
3
4
|
export interface RecordStore {
|
|
4
|
-
read(scope: Scope, reads: Read[], counts?: Count[]): Promise<Snapshot>;
|
|
5
|
+
read(scope: Scope, reads: readonly Read[], counts?: readonly Count[]): Promise<Snapshot>;
|
|
5
6
|
commit(scope: Scope, change: Change): Promise<Committed>;
|
|
6
7
|
add(scope: Scope, addition: Addition): Promise<void>;
|
|
7
8
|
watch(scope: Scope, watch: Watch): ReadableStream<WatchedRow>;
|
|
8
9
|
}
|
|
9
|
-
/**
|
|
10
|
-
export interface
|
|
10
|
+
/** Records and their job table, as `Records.Records` gives them. */
|
|
11
|
+
export interface Store extends RecordStore {
|
|
11
12
|
claim(scope: Scope, request: ClaimRequest): Promise<ClaimResult>;
|
|
12
13
|
settle(claim: Claim, outcome: Outcome): Promise<Settled>;
|
|
13
14
|
progress(scope: Scope, input: ProgressWrite): Promise<ProgressStored>;
|
|
14
|
-
due?(request: DueRequest): Promise<Listing<Scope>>;
|
|
15
15
|
count(scope: Scope): Promise<JobCounts>;
|
|
16
16
|
list(scope: Scope, request: JobListRequest): Promise<Listing<JobItem>>;
|
|
17
17
|
retry(scope: Scope, job: JobRef, input?: RetryInput): Promise<void>;
|
|
18
18
|
discard(scope: Scope, job: JobRef): Promise<void>;
|
|
19
19
|
}
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
readonly run: (scope: Scope) => Promise<void>;
|
|
23
|
-
readonly traceparent?: () => string | undefined;
|
|
24
|
-
}
|
|
25
|
-
/** A store's wake-up: the platform's part, which runs the queue when a scope's jobs are due. */
|
|
26
|
-
export interface Wake {
|
|
27
|
-
set(scope: Scope, at: Moment): Promise<void>;
|
|
28
|
-
listen(listener: WakeListener): void;
|
|
29
|
-
start?(): () => Promise<void>;
|
|
30
|
-
fetch?(request: Request): Promise<Response | undefined>;
|
|
31
|
-
}
|
|
32
|
-
/** Records and their job table in one database, and its wake-up. */
|
|
33
|
-
export interface Store extends RecordStore, JobStore {
|
|
34
|
-
readonly wake: Wake;
|
|
35
|
-
}
|
|
36
|
-
/** The queue over a store. */
|
|
37
|
-
export interface JobQueue {
|
|
38
|
-
readonly store: Store;
|
|
39
|
-
register(...definitions: JobDefinition[]): void;
|
|
40
|
-
run(scope: Scope): Promise<RunResult>;
|
|
41
|
-
start(): () => Promise<void>;
|
|
42
|
-
fetch(request: Request): Promise<Response | undefined>;
|
|
43
|
-
count(scope: Scope): Promise<JobCounts>;
|
|
44
|
-
list(scope: Scope, request: JobListRequest): Promise<Listing<JobItem>>;
|
|
45
|
-
retry(scope: Scope, job: JobRef): Promise<void>;
|
|
46
|
-
discard(scope: Scope, job: JobRef): Promise<void>;
|
|
47
|
-
}
|
|
48
|
-
/** Files by key. */
|
|
49
|
-
export interface Bucket {
|
|
20
|
+
/** Files by key, as `Bucket.Bucket` gives them. */
|
|
21
|
+
interface Bucket$1 {
|
|
50
22
|
/** How a body of unknown length goes up, and the calls each put makes past its parts (Q829). */
|
|
51
23
|
readonly multipart: Multipart;
|
|
52
24
|
put(key: string, body: ReadableStream<Uint8Array>, options?: PutOptions & CallOptions): Promise<Stored>;
|
|
@@ -55,9 +27,12 @@ export interface Bucket {
|
|
|
55
27
|
list(prefix: string, page?: Page, options?: CallOptions): Promise<Listing<Stored>>;
|
|
56
28
|
url?(key: string, options: UrlOptions & CallOptions): Promise<string>;
|
|
57
29
|
}
|
|
58
|
-
/** The
|
|
30
|
+
/** The runtime's `Clock`, as a promise: leases and due times are compared on it. */
|
|
59
31
|
export interface Clock {
|
|
60
32
|
now(): Moment;
|
|
61
33
|
/** Resolves at `until` on this clock, or as soon as `signal` aborts. */
|
|
62
34
|
sleep(until: Moment, signal?: AbortSignal): Promise<void>;
|
|
63
|
-
}
|
|
35
|
+
}
|
|
36
|
+
/** A length of time: milliseconds, or Effect's words for one, such as `'30 seconds'`. */
|
|
37
|
+
export type Duration = EffectDuration.Input;
|
|
38
|
+
export { Bucket$1 as Bucket };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as Option from "effect/Option";
|
|
2
|
+
import * as EffectDuration from "effect/Duration";
|
|
3
|
+
// src/contracts/promises.ts
|
|
4
|
+
/** `duration` in whole milliseconds, or a `TypeError` for a negative, endless or unreadable one. */
|
|
5
|
+
const millis = (duration) => {
|
|
6
|
+
const value = Option.match(EffectDuration.fromInput(duration), {
|
|
7
|
+
onNone: () => NaN,
|
|
8
|
+
onSome: EffectDuration.toMillis
|
|
9
|
+
});
|
|
10
|
+
if (!Number.isFinite(value) || value < 0) throw new TypeError(`Not a duration: ${String(duration)}`);
|
|
11
|
+
return Math.round(value);
|
|
12
|
+
};
|
|
13
|
+
export { millis };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Duration } from "./promises.mjs";
|
|
1
2
|
import { ActorId, ActorInput, WriteInput } from "./actors.mjs";
|
|
2
3
|
import { CommitMessage } from "./commits.mjs";
|
|
3
4
|
import { Commit, TreeChange } from "./engine.mjs";
|
|
@@ -5,7 +6,7 @@ import { Oid, RefName, RepoId } from "./ids.mjs";
|
|
|
5
6
|
import { RepoInput } from "./repos.mjs";
|
|
6
7
|
import { Awaitable, DecisionAnswer, Result, Verdict } from "./result.mjs";
|
|
7
8
|
import { GitServices } from "./services.mjs";
|
|
8
|
-
import {
|
|
9
|
+
import { JobDefinition, Listing, Page } from "@ref0/infra";
|
|
9
10
|
/**
|
|
10
11
|
* The merge queue: entries ask for a source's head on a target, and candidates, the commits a
|
|
11
12
|
* host's CI checks, merge them in order once a report passes them. Each ID is opaque and carries
|
|
@@ -80,7 +80,14 @@ export interface GitErrorContexts {
|
|
|
80
80
|
export type GitErrorCode = keyof GitErrorContexts;
|
|
81
81
|
export interface GitErrorFields {
|
|
82
82
|
readonly message: string;
|
|
83
|
+
/** What the caller can do: every face that tells the refusal tells it. */
|
|
83
84
|
readonly hint?: string;
|
|
85
|
+
/**
|
|
86
|
+
* What the host can do, in the host's words, such as an option to raise: in-process calls and
|
|
87
|
+
* the error log keep it, and HTTP, Git's wire and the drop-in's bodies strip it, as they do
|
|
88
|
+
* `cause` (Q851).
|
|
89
|
+
*/
|
|
90
|
+
readonly hostHint?: string;
|
|
84
91
|
/** HTTP strips it. */
|
|
85
92
|
readonly cause?: unknown;
|
|
86
93
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Bucket as Bucket$1, Clock, Duration, Store } from "./promises.mjs";
|
|
1
2
|
import { AccessOption } from "./access.mjs";
|
|
2
3
|
import { Actor, ActorInput, Caller, GitAuth, GitAuthorize } from "./actors.mjs";
|
|
3
4
|
import { BlobCalls } from "./blobs.mjs";
|
|
@@ -25,32 +26,23 @@ import { GitSignInOptions } from "./signin.mjs";
|
|
|
25
26
|
import { TokenCalls, TokenScope, TokensFeature } from "./tokens.mjs";
|
|
26
27
|
import { WorkCalls } from "./work.mjs";
|
|
27
28
|
import { TopicCalls, TopicsFactory } from "./topics.mjs";
|
|
28
|
-
import { Bucket,
|
|
29
|
-
import { CallLimits, Duration, JobDefinition } from "@ref0/infra";
|
|
29
|
+
import { Bucket, CallLimits, JobDefinition, JobQueue, Records } from "@ref0/infra";
|
|
30
30
|
import * as Effect from "effect/Effect";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* request counts every store call from its serve to its pack's last byte on one count, bounded
|
|
47
|
-
* by them less `requestCallsBefore`, the token's read before it: its haves and its tags' peels
|
|
48
|
-
* with its pack's, and v0's advertisement's peels. One that would pass them is refused with an
|
|
49
|
-
* `ERR` before the call that would (#709). Another fetch, as a drop-in route's, counts its own
|
|
50
|
-
* calls alone. The host's own functions aren't counted. With none, a fetch has no bound.
|
|
51
|
-
*/
|
|
52
|
-
readonly callLimits?: CallLimits.CallLimits['Service'];
|
|
53
|
-
}
|
|
31
|
+
import * as Layer from "effect/Layer";
|
|
32
|
+
import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
33
|
+
/** The services every Git server takes from its adapter. */
|
|
34
|
+
export type GitNeeds = Records.Records | JobQueue.JobQueue | CallLimits.CallLimits;
|
|
35
|
+
/**
|
|
36
|
+
* The host's adapter: one Layer, or several, giving `Records`, `JobQueue` and `CallLimits`, and a
|
|
37
|
+
* `Bucket` for `packs()` and LFS, with `BucketUploads` for push uploads and `BucketLinks` for
|
|
38
|
+
* LFS's links. Git builds them, with its own wiring, into `GitServer.runtime`.
|
|
39
|
+
* Its `CallLimits` are checked as the server builds, before any objects open them: a bound that's
|
|
40
|
+
* no whole number of calls fails the build, logged as "The Git server failed to start" with the
|
|
41
|
+
* bound it names, and every request answers `UNAVAILABLE` until it's fixed.
|
|
42
|
+
*/
|
|
43
|
+
export type GitAdapter = Layer.Layer<never, Error> | readonly Layer.Layer<never, Error>[];
|
|
44
|
+
/** What `adapter` gives. */
|
|
45
|
+
export type ProvidedBy<A extends GitAdapter> = A extends readonly (infer L extends Layer.Any)[] ? Layer.Success<L> : A extends Layer.Any ? Layer.Success<A> : never;
|
|
54
46
|
export interface ResolveInput extends ActorInput {
|
|
55
47
|
readonly url: URL;
|
|
56
48
|
readonly path: string;
|
|
@@ -75,8 +67,8 @@ export interface Refusal {
|
|
|
75
67
|
readonly actor?: Actor;
|
|
76
68
|
}
|
|
77
69
|
/** Each piece adds its own options: C's are these. */
|
|
78
|
-
export interface GitServerOptions {
|
|
79
|
-
readonly adapter:
|
|
70
|
+
export interface GitServerOptions<A extends GitAdapter = GitAdapter> {
|
|
71
|
+
readonly adapter: A;
|
|
80
72
|
readonly objects: ObjectsFactory;
|
|
81
73
|
/** One `engine()` made: the object calls run its xdiff too, so any other is refused. */
|
|
82
74
|
readonly engine: GitEngine;
|
|
@@ -107,6 +99,12 @@ export interface GitServerOptions {
|
|
|
107
99
|
readonly fetchLimits?: EffectiveLimits;
|
|
108
100
|
/** A large push's pack straight to the bucket: off unless set, and a bucket that signs parts. */
|
|
109
101
|
readonly pushes?: PushOptions;
|
|
102
|
+
/**
|
|
103
|
+
* The route's own limit, such as `'60 seconds'`, counted from each request's start. A pack that
|
|
104
|
+
* would run past it ends 5 seconds before, or a tenth of a shorter limit, on side-band 3, naming
|
|
105
|
+
* the limit and `git clone --depth 1`. With none, a pack runs to its end.
|
|
106
|
+
*/
|
|
107
|
+
readonly maxDuration?: Duration;
|
|
110
108
|
}
|
|
111
109
|
/**
|
|
112
110
|
* `access`, private branches from `@ref0/git/access`, only over objects that keep the
|
|
@@ -118,15 +116,14 @@ type AccessSetup = {
|
|
|
118
116
|
readonly access: AccessOption;
|
|
119
117
|
readonly objects: IndexedObjectsFactory;
|
|
120
118
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
export type ServerSetup = GitServerOptions & ({
|
|
126
|
-
readonly adapter: WithBucket;
|
|
127
|
-
} | {
|
|
119
|
+
/**
|
|
120
|
+
* `packs()` needs a `Bucket`; `loose()` doesn't. Only `packs()` takes `access`. An adapter that
|
|
121
|
+
* gives no `Records`, `JobQueue` or `CallLimits` is refused.
|
|
122
|
+
*/
|
|
123
|
+
export type ServerSetup<A extends GitAdapter = GitAdapter> = GitServerOptions<A> & ([GitNeeds] extends [ProvidedBy<A>] ? [Bucket.Bucket] extends [ProvidedBy<A>] ? unknown : {
|
|
128
124
|
readonly objects: ObjectsFactory<false>;
|
|
129
|
-
|
|
125
|
+
} : {
|
|
126
|
+
readonly adapter: never;
|
|
130
127
|
}) & AccessSetup;
|
|
131
128
|
/** Each piece adds its own groups: C's, RD's objects, Q's `queue` and TP's `topics`. */
|
|
132
129
|
export interface ServerCalls {
|
|
@@ -145,33 +142,63 @@ export interface ServerCalls {
|
|
|
145
142
|
readonly queue?: MergeQueueCalls;
|
|
146
143
|
readonly topics?: TopicCalls;
|
|
147
144
|
}
|
|
148
|
-
export interface GitServer extends ServerCalls {
|
|
145
|
+
export interface GitServer<R = never> extends ServerCalls {
|
|
149
146
|
/** 404 outside Git's URLs. */
|
|
150
147
|
readonly fetch: (request: Request) => Promise<Response>;
|
|
151
148
|
/** `undefined` only for a URL Git doesn't own. */
|
|
152
149
|
readonly route: (request: Request) => Promise<Response | undefined>;
|
|
153
150
|
readonly identify: (request: Request) => Promise<Result<Caller>>;
|
|
154
|
-
/**
|
|
151
|
+
/**
|
|
152
|
+
* The isolate's runtime, over the adapter's Layers and Git's own wiring, which registers Git's
|
|
153
|
+
* jobs on the adapter's queue: built at most once, starting as the tick that made the server
|
|
154
|
+
* ends, so `extendGit` and `syncJobs` join in that tick, and a module that only runs jobs has
|
|
155
|
+
* them. A failed build stays failed: every call answers `UNAVAILABLE`, and `fetch` a 503. The
|
|
156
|
+
* bridge until SV's step 2c.
|
|
157
|
+
*/
|
|
158
|
+
readonly runtime: ManagedRuntime.ManagedRuntime<R, Error>;
|
|
159
|
+
/** Disposes `runtime`. */
|
|
155
160
|
readonly close: () => Promise<void>;
|
|
156
161
|
}
|
|
157
162
|
/** What a package built on Git, such as `@ref0/github`, adds to one server. */
|
|
158
163
|
export interface GitExtension {
|
|
164
|
+
/** Named other than `git.…`, as Git's own jobs are. */
|
|
159
165
|
readonly jobs?: readonly JobDefinition[];
|
|
160
166
|
readonly pushRules?: readonly PushRule[];
|
|
161
167
|
readonly grants?: readonly GrantResolver[];
|
|
168
|
+
/**
|
|
169
|
+
* Runs in the server's build, after Git's own wiring and before the extension's jobs are
|
|
170
|
+
* registered, with the adapter as promises: the bridge until SV's step 2b deletes it with
|
|
171
|
+
* `extendGit`.
|
|
172
|
+
*/
|
|
173
|
+
readonly bind?: (adapter: BoundAdapter) => void;
|
|
174
|
+
}
|
|
175
|
+
/** The adapter as `GitExtension.bind` takes it: the bridge's promise shapes. */
|
|
176
|
+
export interface BoundAdapter {
|
|
177
|
+
readonly store: Store;
|
|
178
|
+
readonly bucket: Bucket$1 | undefined;
|
|
179
|
+
readonly clock: Clock;
|
|
162
180
|
}
|
|
163
181
|
export interface ExtendedGit {
|
|
164
|
-
readonly adapter: GitAdapter;
|
|
165
182
|
/**
|
|
166
183
|
* Where the server serves Git's URLs, as it routes by them: `''` at the host's root, else one
|
|
167
184
|
* leading slash and no trailing one, as `/git`. A package builds its links to Git's routes on it.
|
|
168
185
|
*/
|
|
169
186
|
readonly basePath: string;
|
|
170
187
|
readonly internalId: (repo: RepoId) => Promise<InternalRepoId>;
|
|
188
|
+
/**
|
|
189
|
+
* Once the server's build has ended: success when it's built, `UNAVAILABLE` naming its failure
|
|
190
|
+
* when it failed, as every call then answers. It rejects once the server is closed, as its calls
|
|
191
|
+
* do. A package that serves over what its `bind` was handed waits on it first, since a step
|
|
192
|
+
* after that bind can still fail the build. Like a call, it starts the build, which closes
|
|
193
|
+
* joins: ask it as a call is handled, never while extensions still join. The bridge until SV's
|
|
194
|
+
* step 2b deletes it with `ExtendedGit`.
|
|
195
|
+
*/
|
|
196
|
+
readonly ready: () => Promise<Result<void>>;
|
|
171
197
|
/**
|
|
172
198
|
* `internalId` as an Effect, its refusal Git's error, not an `Error`'s cause. These Effect twins,
|
|
173
|
-
* `effectRepo`, `effectAccess`, `effectGrantAgain` and `effectHostCalls` beside it, each
|
|
174
|
-
*
|
|
199
|
+
* `effectRepo`, `effectAccess`, `effectGrantAgain` and `effectHostCalls` beside it, each go
|
|
200
|
+
* through the server's door as their Promise twins do, so one the closing outlives dies closed,
|
|
201
|
+
* count their store calls into the `CallBudget` provided around them, and answer one spent as its
|
|
175
202
|
* refusal, as `effectCallsFor`'s calls do (Q830). Their names are a bridge's (Q787): the drop-in's
|
|
176
203
|
* Effect step (Q783) gives them their Promise twins' once those are gone.
|
|
177
204
|
*/
|
|
@@ -163,7 +163,7 @@ export interface ImportJobData {
|
|
|
163
163
|
export interface MirrorJobData {
|
|
164
164
|
readonly ref: RefName;
|
|
165
165
|
}
|
|
166
|
-
/** Sync's two job definitions,
|
|
166
|
+
/** Sync's two job definitions, which one server's build binds and registers on its queue. */
|
|
167
167
|
export type SyncJobs = readonly [JobDefinition<'git.sync.import', ImportJobData, ImportJobData>, JobDefinition<'git.sync.mirror', MirrorJobData, MirrorJobData>];
|
|
168
168
|
/**
|
|
169
169
|
* Creates `repo` and copies the source into it on the queue, a push under 100 MB at a time, each
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { Duration } from "./promises.mjs";
|
|
1
2
|
import { ActorInput, WriteInput } from "./actors.mjs";
|
|
2
3
|
import { HandlerOptions } from "./handlers.mjs";
|
|
3
4
|
import { Oid, RefName, RepoId, TopicId } from "./ids.mjs";
|
|
4
5
|
import { CandidateId, EntryId, Judged, QueueMeta, Report, ReportOptions, ReportResult } from "./queue.mjs";
|
|
5
6
|
import { Awaitable, DecisionAnswer, Result } from "./result.mjs";
|
|
6
7
|
import { GitServices } from "./services.mjs";
|
|
7
|
-
import {
|
|
8
|
+
import { JobDefinition, Listing, Page } from "@ref0/infra";
|
|
8
9
|
/** One repo's target in a topic: at most one entry a repo and target. */
|
|
9
10
|
export interface TopicTarget {
|
|
10
11
|
readonly repo: RepoId;
|
|
@@ -44,6 +45,11 @@ export interface TopicFailure {
|
|
|
44
45
|
/** A host function's failure ID, when one failed. */
|
|
45
46
|
readonly error?: string;
|
|
46
47
|
readonly hint: string;
|
|
48
|
+
/**
|
|
49
|
+
* The host's own step, as raising a `topics()` timeout: in-process calls keep it, and REST's
|
|
50
|
+
* body and the `topic.failed` event leave it out, as a `GitError`'s `hostHint` (Q851).
|
|
51
|
+
*/
|
|
52
|
+
readonly hostHint?: string;
|
|
47
53
|
}
|
|
48
54
|
/**
|
|
49
55
|
* `reserving` while it takes each target, which `waitingOn` says it waits on, `checking` while it
|
package/dist/core/access.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "../contracts/promises.mjs";
|
|
1
2
|
import "../contracts/actors.mjs";
|
|
2
3
|
import "../contracts/objects.mjs";
|
|
3
4
|
import "../contracts/operations.mjs";
|
|
@@ -16,7 +17,6 @@ import "../store/outbox.mjs";
|
|
|
16
17
|
import "../store/records.mjs";
|
|
17
18
|
import "./receipts.mjs";
|
|
18
19
|
import "./view.mjs";
|
|
19
|
-
import "../contracts/promises.mjs";
|
|
20
20
|
import { JobDefinition, Moment, Read, Row } from "@ref0/infra";
|
|
21
21
|
import "effect/Effect";
|
|
22
22
|
import "effect/Types";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../contracts/server.mjs";
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// src/core/call-names.ts
|
|
2
|
+
/**
|
|
3
|
+
* Each group of the server's calls, by name: its face makes them before its runtime is built, and
|
|
4
|
+
* each runs once the build is done. Every call is here, as `complete` checks.
|
|
5
|
+
*/
|
|
6
|
+
const callNames = {
|
|
7
|
+
repos: [
|
|
8
|
+
"create",
|
|
9
|
+
"get",
|
|
10
|
+
"list",
|
|
11
|
+
"update",
|
|
12
|
+
"rename",
|
|
13
|
+
"delete"
|
|
14
|
+
],
|
|
15
|
+
forks: [
|
|
16
|
+
"create",
|
|
17
|
+
"get",
|
|
18
|
+
"list",
|
|
19
|
+
"sync",
|
|
20
|
+
"fetch"
|
|
21
|
+
],
|
|
22
|
+
work: [
|
|
23
|
+
"list",
|
|
24
|
+
"retry",
|
|
25
|
+
"discard"
|
|
26
|
+
],
|
|
27
|
+
refs: [
|
|
28
|
+
"get",
|
|
29
|
+
"protection",
|
|
30
|
+
"list",
|
|
31
|
+
"count",
|
|
32
|
+
"sees",
|
|
33
|
+
"update"
|
|
34
|
+
],
|
|
35
|
+
blobs: ["get", "create"],
|
|
36
|
+
trees: [
|
|
37
|
+
"get",
|
|
38
|
+
"diff",
|
|
39
|
+
"create",
|
|
40
|
+
"merge"
|
|
41
|
+
],
|
|
42
|
+
commits: [
|
|
43
|
+
"get",
|
|
44
|
+
"list",
|
|
45
|
+
"mergeBase",
|
|
46
|
+
"diff",
|
|
47
|
+
"compare",
|
|
48
|
+
"create",
|
|
49
|
+
"revert",
|
|
50
|
+
"pick"
|
|
51
|
+
],
|
|
52
|
+
tags: [
|
|
53
|
+
"get",
|
|
54
|
+
"peel",
|
|
55
|
+
"create"
|
|
56
|
+
],
|
|
57
|
+
files: [
|
|
58
|
+
"read",
|
|
59
|
+
"list",
|
|
60
|
+
"diff"
|
|
61
|
+
],
|
|
62
|
+
merges: ["create"],
|
|
63
|
+
lfs: ["get"],
|
|
64
|
+
tokens: [
|
|
65
|
+
"create",
|
|
66
|
+
"list",
|
|
67
|
+
"get",
|
|
68
|
+
"revoke",
|
|
69
|
+
"revokeKey"
|
|
70
|
+
],
|
|
71
|
+
queue: [
|
|
72
|
+
"add",
|
|
73
|
+
"remove",
|
|
74
|
+
"hold",
|
|
75
|
+
"release",
|
|
76
|
+
"report",
|
|
77
|
+
"retry",
|
|
78
|
+
"restart",
|
|
79
|
+
"get",
|
|
80
|
+
"list",
|
|
81
|
+
"holds",
|
|
82
|
+
"candidates",
|
|
83
|
+
"candidate"
|
|
84
|
+
],
|
|
85
|
+
topics: [
|
|
86
|
+
"add",
|
|
87
|
+
"get",
|
|
88
|
+
"list",
|
|
89
|
+
"remove",
|
|
90
|
+
"report"
|
|
91
|
+
]
|
|
92
|
+
};
|
|
93
|
+
export { callNames };
|