@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
|
@@ -4,11 +4,14 @@ import { ExtendedGit, GitExtension, GitServer } from "../contracts/server.mjs";
|
|
|
4
4
|
import "../contracts/services.mjs";
|
|
5
5
|
import "../contracts/rules.mjs";
|
|
6
6
|
import "../contracts/tokens.mjs";
|
|
7
|
+
import "../core/seam.mjs";
|
|
8
|
+
import "./lifecycle.mjs";
|
|
7
9
|
import { JobDefinition } from "@ref0/infra";
|
|
8
10
|
import "effect/Effect";
|
|
9
11
|
/**
|
|
10
|
-
* Joins a package built on Git, such as `@ref0/github`, to one server: its
|
|
11
|
-
* queue, its push rules after the host's own, and its grant
|
|
12
|
-
* the
|
|
12
|
+
* Joins a package built on Git, such as `@ref0/github`, to one server: its `bind` and then its jobs
|
|
13
|
+
* on the server's queue, in its build, its push rules after the host's own, and its grant
|
|
14
|
+
* resolvers before `auth`. Refused after the tick that made the server, for a job name or a grant
|
|
15
|
+
* resolver's name already registered, or for a job named `git.…`, as Git's own are. The bridge until SV's step 2b deletes it.
|
|
13
16
|
*/
|
|
14
17
|
export declare const extendGit: (git: GitServer, extension: GitExtension) => ExtendedGit;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { grantNameOf } from "../auth/grants.mjs";
|
|
2
2
|
import { servedSources } from "../core/rules/protect.mjs";
|
|
3
3
|
import { guardedCall } from "../core/promise.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { lazyParts, seamOf } from "../core/seam.mjs";
|
|
5
5
|
import { hostRecordOf, internalIdOf } from "../store/catalogue.mjs";
|
|
6
|
-
import { gitError, thrownError } from "../store/errors.mjs";
|
|
7
6
|
import { runIn, uncounted } from "../store/crossing.mjs";
|
|
7
|
+
import { gitError, thrownError } from "../store/errors.mjs";
|
|
8
8
|
import * as Effect from "effect/Effect";
|
|
9
9
|
// src/server/extension.ts
|
|
10
10
|
const attachedByServer = /* @__PURE__ */ new WeakMap();
|
|
11
|
-
/** A server's registry,
|
|
12
|
-
const openExtensions = (
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
/** A server's registry, empty until extensions add to it and its build adds its own jobs. */
|
|
12
|
+
const openExtensions = (queued) => ({
|
|
13
|
+
jobs: /* @__PURE__ */ new Map(),
|
|
14
|
+
added: [],
|
|
15
|
+
binds: [],
|
|
15
16
|
pushRules: [],
|
|
16
17
|
grants: [],
|
|
17
|
-
queued
|
|
18
|
-
started: false
|
|
18
|
+
queued
|
|
19
19
|
});
|
|
20
20
|
/** Called once, by `createGitServer`, for the server it returns. */
|
|
21
21
|
const attachExtensions = (git, attached) => {
|
|
@@ -23,56 +23,64 @@ const attachExtensions = (git, attached) => {
|
|
|
23
23
|
};
|
|
24
24
|
/** Thrown as an `Error`, the refusal its cause, since `extendGit` runs once at setup. */
|
|
25
25
|
const refused = (message) => new Error(message, { cause: gitError("FAILED_PRECONDITION", message) });
|
|
26
|
+
/** The refusal of a join after the tick that made the server, when its build has started. */
|
|
27
|
+
const lateJoin = (call) => `${call} joins a server in the tick createGitServer made it in: call it where the server is made, before any await`;
|
|
26
28
|
/** `jobs` added to what the server knows by name, refused for a name it knows already. */
|
|
27
29
|
const noted = (extensions, jobs) => {
|
|
28
30
|
const names = jobs.map((job) => job.name);
|
|
29
31
|
const taken = names.find((name, index) => extensions.jobs.has(name) || names.indexOf(name) !== index);
|
|
30
32
|
if (taken !== void 0) throw refused(`A job is named '${taken}' already`);
|
|
31
33
|
for (const job of jobs) extensions.jobs.set(job.name, job);
|
|
34
|
+
extensions.added.push(...jobs);
|
|
32
35
|
};
|
|
33
36
|
/**
|
|
34
|
-
* Jobs the server finds by name, such as `syncJobs`' definitions, which a push saves
|
|
35
|
-
* commit,
|
|
36
|
-
*
|
|
37
|
+
* Jobs the server registers and finds by name, such as `syncJobs`' definitions, which a push saves
|
|
38
|
+
* in its commit, with what binds them in the server's build. Refused after the tick that made the
|
|
39
|
+
* server, or for a job name the server knows already.
|
|
37
40
|
*/
|
|
38
|
-
const knowJobs = (git, jobs) => {
|
|
41
|
+
const knowJobs = (git, jobs, bind) => {
|
|
39
42
|
const attached = attachedByServer.get(git);
|
|
40
43
|
if (attached === void 0) throw new TypeError("syncJobs takes a server createGitServer made");
|
|
41
|
-
if (attached.
|
|
44
|
+
if (attached.admit("join") === "late") throw refused(lateJoin("syncJobs"));
|
|
42
45
|
noted(attached.extensions, jobs);
|
|
46
|
+
attached.extensions.binds.push(bind);
|
|
43
47
|
};
|
|
44
48
|
/**
|
|
45
|
-
* Joins a package built on Git, such as `@ref0/github`, to one server: its
|
|
46
|
-
* queue, its push rules after the host's own, and its grant
|
|
47
|
-
* the
|
|
49
|
+
* Joins a package built on Git, such as `@ref0/github`, to one server: its `bind` and then its jobs
|
|
50
|
+
* on the server's queue, in its build, its push rules after the host's own, and its grant
|
|
51
|
+
* resolvers before `auth`. Refused after the tick that made the server, for a job name or a grant
|
|
52
|
+
* resolver's name already registered, or for a job named `git.…`, as Git's own are. The bridge until SV's step 2b deletes it.
|
|
48
53
|
*/
|
|
49
54
|
const extendGit = (git, extension) => {
|
|
50
55
|
const attached = attachedByServer.get(git);
|
|
51
|
-
const
|
|
52
|
-
if (attached === void 0 ||
|
|
56
|
+
const seam = seamOf(git);
|
|
57
|
+
if (attached === void 0 || seam === void 0) throw new TypeError("extendGit takes a server createGitServer made");
|
|
53
58
|
const { extensions } = attached;
|
|
54
|
-
if (
|
|
59
|
+
if (attached.admit("join") === "late") throw refused(lateJoin("extendGit"));
|
|
55
60
|
const resolvers = (extension.grants ?? []).map((resolver) => resolver.name);
|
|
56
61
|
const named = resolvers.find((name, index) => extensions.grants.some((one) => one.name === name) || resolvers.indexOf(name) !== index);
|
|
57
62
|
if (named !== void 0) throw refused(`A grant resolver is named '${named}' already`);
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
extensions.
|
|
63
|
+
const own = (extension.jobs ?? []).find((job) => job.name.startsWith("git."));
|
|
64
|
+
if (own !== void 0) throw refused(`Git's own jobs are named 'git.…': name '${own.name}' another way`);
|
|
65
|
+
noted(extensions, extension.jobs ?? []);
|
|
66
|
+
const { bind } = extension;
|
|
67
|
+
if (bind !== void 0) extensions.binds.push((built) => bind(built.adapter));
|
|
61
68
|
if (!extensions.queued) servedSources(extension.pushRules ?? []);
|
|
62
69
|
extensions.pushRules.push(...extension.pushRules ?? []);
|
|
63
70
|
extensions.grants.push(...extension.grants ?? []);
|
|
64
|
-
const {
|
|
65
|
-
const
|
|
66
|
-
const
|
|
71
|
+
const { built, through } = attached;
|
|
72
|
+
const store = Effect.map(built, ({ adapter }) => adapter.store);
|
|
73
|
+
const extensionCall = (effect) => runIn(Effect.mapError(through(effect), thrownError), uncounted("an extension's own call (#725)"));
|
|
74
|
+
const effectCall = guardedCall(through);
|
|
67
75
|
return {
|
|
68
|
-
adapter: extensions.adapter,
|
|
69
76
|
basePath: attached.basePath,
|
|
70
|
-
internalId: (repo) => extensionCall(
|
|
71
|
-
effectInternalId: (repo) => effectCall(
|
|
72
|
-
repo: (internalId) => extensionCall(
|
|
73
|
-
effectRepo: (internalId) => effectCall(
|
|
77
|
+
internalId: (repo) => extensionCall(Effect.flatMap(store, (on) => internalIdOf(on, repo))),
|
|
78
|
+
effectInternalId: (repo) => effectCall(Effect.flatMap(store, (on) => internalIdOf(on, repo))),
|
|
79
|
+
repo: (internalId) => extensionCall(Effect.flatMap(store, (on) => hostRecordOf(on, internalId))),
|
|
80
|
+
effectRepo: (internalId) => effectCall(Effect.flatMap(store, (on) => hostRecordOf(on, internalId))),
|
|
81
|
+
ready: attached.ready,
|
|
74
82
|
callsFor: attached.callsFor,
|
|
75
|
-
effectCallsFor:
|
|
83
|
+
effectCallsFor: lazyParts(seam).callsFor,
|
|
76
84
|
hostCalls: () => attached.hostCalls,
|
|
77
85
|
effectHostCalls: () => attached.effectHostCalls,
|
|
78
86
|
access: (caller, repo) => extensionCall(attached.access(caller, repo)),
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { closedError } from "../store/closed.mjs";
|
|
2
|
+
import { gitError, thrownError } from "../store/errors.mjs";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Cause from "effect/Cause";
|
|
5
|
+
// src/server/lifecycle.ts
|
|
6
|
+
/** Every entry in every state, decided here alone. */
|
|
7
|
+
const admissions = {
|
|
8
|
+
join: {
|
|
9
|
+
joining: "join",
|
|
10
|
+
building: "late",
|
|
11
|
+
built: "late",
|
|
12
|
+
failed: "late",
|
|
13
|
+
closed: "late"
|
|
14
|
+
},
|
|
15
|
+
call: {
|
|
16
|
+
joining: "wait",
|
|
17
|
+
building: "wait",
|
|
18
|
+
built: "run",
|
|
19
|
+
failed: "unavailable",
|
|
20
|
+
closed: "closed"
|
|
21
|
+
},
|
|
22
|
+
bridge: {
|
|
23
|
+
joining: "run",
|
|
24
|
+
building: "run",
|
|
25
|
+
built: "run",
|
|
26
|
+
failed: "unavailable",
|
|
27
|
+
closed: "closed"
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/** The moves each state allows: `closed` allows none. */
|
|
31
|
+
const moves = {
|
|
32
|
+
joining: ["building", "closed"],
|
|
33
|
+
building: [
|
|
34
|
+
"built",
|
|
35
|
+
"failed",
|
|
36
|
+
"closed"
|
|
37
|
+
],
|
|
38
|
+
built: ["closed"],
|
|
39
|
+
failed: ["closed"],
|
|
40
|
+
closed: []
|
|
41
|
+
};
|
|
42
|
+
/** What a call or request answers once the build failed: the failure, for the host's logs. */
|
|
43
|
+
const unavailable = (cause) => gitError("UNAVAILABLE", "The Git server failed to start", {
|
|
44
|
+
cause: Cause.squash(cause),
|
|
45
|
+
hint: "Fix the host's adapter, then restart"
|
|
46
|
+
});
|
|
47
|
+
/** A server's life, `joining` until its build starts. */
|
|
48
|
+
const serverLife = () => {
|
|
49
|
+
let state = { kind: "joining" };
|
|
50
|
+
const closing = new AbortController();
|
|
51
|
+
return {
|
|
52
|
+
now: () => state,
|
|
53
|
+
admit: (entry) => admissions[entry][state.kind],
|
|
54
|
+
move: (to) => {
|
|
55
|
+
if (!moves[state.kind].includes(to.kind)) return false;
|
|
56
|
+
state = to;
|
|
57
|
+
if (to.kind === "closed") closing.abort(closedError());
|
|
58
|
+
return true;
|
|
59
|
+
},
|
|
60
|
+
closing: closing.signal
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* The bridge's refusal in the state now, or `undefined` while it runs: once the build failed, Git's
|
|
65
|
+
* `UNAVAILABLE` naming its failure, as the server's calls answer.
|
|
66
|
+
*/
|
|
67
|
+
const bridgeRefusal = (life) => {
|
|
68
|
+
const admitted = life.admit("bridge");
|
|
69
|
+
if (admitted === "closed") return closedError();
|
|
70
|
+
const now = life.now();
|
|
71
|
+
return admitted === "unavailable" && now.kind === "failed" ? thrownError(unavailable(now.cause)) : void 0;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* `effect` through the door, for a run outside the server's runtime, which `close()` doesn't stop:
|
|
75
|
+
* it asks the door first, then races the closing, so a run still going as the server closes dies
|
|
76
|
+
* with the closed error whatever it would have answered. No ask after: the race already listens
|
|
77
|
+
* before the run can end, so a close before its answer always wins.
|
|
78
|
+
*/
|
|
79
|
+
const throughDoor = (life) => (effect) => {
|
|
80
|
+
const ask = Effect.suspend(() => life.admit("call") === "closed" ? Effect.die(closedError()) : Effect.void);
|
|
81
|
+
const closes = Effect.callback((resume) => {
|
|
82
|
+
const onAbort = () => resume(Effect.die(closedError()));
|
|
83
|
+
if (life.closing.aborted) return onAbort();
|
|
84
|
+
life.closing.addEventListener("abort", onAbort, { once: true });
|
|
85
|
+
return Effect.sync(() => life.closing.removeEventListener("abort", onAbort));
|
|
86
|
+
});
|
|
87
|
+
return Effect.andThen(ask, Effect.raceFirst(closes, effect));
|
|
88
|
+
};
|
|
89
|
+
export { bridgeRefusal, serverLife, throughDoor, unavailable };
|
package/dist/server/routes.d.mts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { ObjectsFactory } from "../contracts/objects.mjs";
|
|
2
2
|
import { GitServerOptions, ServerCalls } from "../contracts/server.mjs";
|
|
3
3
|
import { EffectCalls, GitAuth, GitAuthorize } from "../contracts/services.mjs";
|
|
4
|
+
import { Bucket, CallLimits, JobQueue, Records } from "@ref0/infra";
|
|
4
5
|
import * as Context from "effect/Context";
|
|
5
6
|
import * as Layer from "effect/Layer";
|
|
6
|
-
import { Bucket, JobQueue, Records } from "@ref0/infra/effect";
|
|
7
7
|
import * as HttpRouter from "effect/http/HttpRouter";
|
|
8
8
|
/** What `GitServer.routes` takes: `createGitServer`'s options but those its services give. */
|
|
9
9
|
export interface GitRoutesOptions<Objects extends ObjectsFactory = ObjectsFactory> extends Omit<GitServerOptions, 'adapter' | 'auth' | 'authorize' | 'objects'> {
|
|
10
10
|
readonly objects: Objects;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* What the routes need: the host's records, jobs, call limits and deciders, and a bucket unless
|
|
14
|
+
* `loose()`. Any other service the host gives, as `BucketUploads`, the server takes too.
|
|
15
|
+
*/
|
|
16
|
+
export type GitRoutesServices<Objects extends ObjectsFactory> = HttpRouter.HttpRouter | Records.Records | JobQueue.JobQueue | CallLimits.CallLimits | Context.Service.Identifier<typeof GitAuth> | Context.Service.Identifier<typeof GitAuthorize> | (Objects extends ObjectsFactory<false> ? never : Bucket.Bucket);
|
|
14
17
|
/**
|
|
15
18
|
* Git's routes on a host's `HttpRouter`: the server `createGitServer` makes from `options`, over
|
|
16
|
-
* the host's `Records`, `JobQueue` and `Bucket`, deciding with its `GitAuth` and `GitAuthorize`.
|
|
19
|
+
* the host's services, its `Records`, `JobQueue`, `CallLimits` and `Bucket`, deciding with its `GitAuth` and `GitAuthorize`.
|
|
17
20
|
* Every URL under `basePath` answers as `createRestHandler`'s `fetch` does: REST's, then Git's
|
|
18
21
|
* protocol, then a JSON `404`. The server closes with the Layer.
|
|
19
22
|
*/
|
package/dist/server/routes.mjs
CHANGED
|
@@ -2,11 +2,11 @@ import { GitAuth, GitAuthorize } from "../contracts/services.mjs";
|
|
|
2
2
|
import { createRestHandler } from "../rest/handler.mjs";
|
|
3
3
|
import { createGitServer } from "./server.mjs";
|
|
4
4
|
import { runIn, uncounted } from "../store/crossing.mjs";
|
|
5
|
+
import { Bucket } from "@ref0/infra";
|
|
5
6
|
import * as Effect from "effect/Effect";
|
|
6
7
|
import * as Context from "effect/Context";
|
|
7
|
-
import "effect/Layer";
|
|
8
|
+
import * as Layer from "effect/Layer";
|
|
8
9
|
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
|
9
|
-
import { Bucket, JobQueue, Records } from "@ref0/infra/effect";
|
|
10
10
|
import * as HttpRouter from "effect/http/HttpRouter";
|
|
11
11
|
import * as HttpServerRequest from "effect/http/HttpServerRequest";
|
|
12
12
|
// src/server/routes.ts
|
|
@@ -25,14 +25,14 @@ const looseOnly = (objects) => {
|
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
27
|
* Git's routes on a host's `HttpRouter`: the server `createGitServer` makes from `options`, over
|
|
28
|
-
* the host's `Records`, `JobQueue` and `Bucket`, deciding with its `GitAuth` and `GitAuthorize`.
|
|
28
|
+
* the host's services, its `Records`, `JobQueue`, `CallLimits` and `Bucket`, deciding with its `GitAuth` and `GitAuthorize`.
|
|
29
29
|
* Every URL under `basePath` answers as `createRestHandler`'s `fetch` does: REST's, then Git's
|
|
30
30
|
* protocol, then a JSON `404`. The server closes with the Layer.
|
|
31
31
|
*/
|
|
32
32
|
const routes = (options) => HttpRouter.use((router) => Effect.gen(function* () {
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const bucket = Context.getOrUndefined(
|
|
33
|
+
const context = yield* Effect.context();
|
|
34
|
+
const adapter = Layer.succeedContext(context);
|
|
35
|
+
const bucket = Context.getOrUndefined(context, Bucket.Bucket);
|
|
36
36
|
const auth = yield* GitAuth;
|
|
37
37
|
const authorize = yield* GitAuthorize;
|
|
38
38
|
const hostDecider = uncounted("the host's own auth and authorize");
|
|
@@ -40,24 +40,17 @@ const routes = (options) => HttpRouter.use((router) => Effect.gen(function* () {
|
|
|
40
40
|
auth: (input) => runIn(auth.identify(input), hostDecider),
|
|
41
41
|
authorize: (input) => runIn(authorize.check(input), hostDecider)
|
|
42
42
|
};
|
|
43
|
-
const
|
|
43
|
+
const made = () => bucket === void 0 ? createGitServer({
|
|
44
44
|
...options,
|
|
45
45
|
...deciders,
|
|
46
46
|
objects: looseOnly(options.objects),
|
|
47
|
-
adapter
|
|
48
|
-
|
|
49
|
-
jobs
|
|
50
|
-
}
|
|
51
|
-
} : {
|
|
47
|
+
adapter
|
|
48
|
+
}) : createGitServer({
|
|
52
49
|
...options,
|
|
53
50
|
...deciders,
|
|
54
|
-
adapter:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
bucket
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const git = yield* Effect.acquireRelease(Effect.sync(() => createGitServer(setup)), (made) => Effect.promise(() => made.close()));
|
|
51
|
+
adapter: Layer.merge(adapter, Layer.succeed(Bucket.Bucket, bucket))
|
|
52
|
+
});
|
|
53
|
+
const git = yield* Effect.acquireRelease(Effect.sync(made), (made) => Effect.promise(() => made.close()));
|
|
61
54
|
const rest = createRestHandler(git);
|
|
62
55
|
const serve = (request) => Effect.orDie(HttpServerRequest.toWeb(request)).pipe(Effect.flatMap((web) => Effect.promise(() => rest.fetch(web))), Effect.map((response) => HttpServerResponse.raw(response)));
|
|
63
56
|
yield* router.add("*", pathUnder(options.basePath ?? ""), serve);
|
package/dist/server/server.d.mts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
import { GitServer, ServerSetup } from "../contracts/server.mjs";
|
|
2
|
-
|
|
1
|
+
import { GitAdapter, GitServer, ProvidedBy, ServerSetup } from "../contracts/server.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* A Git server over one adapter: its calls, `identify`, and `fetch` and `route`, Git's Smart HTTP
|
|
4
|
+
* over its core and its sign-in, which answer `404` and `undefined` outside their URLs. Its
|
|
5
|
+
* runtime builds the adapter's Layers and Git's wiring once the tick that made it ends, which
|
|
6
|
+
* registers Git's jobs on the adapter's queue, and never runs them: the host starts them.
|
|
7
|
+
*/
|
|
8
|
+
export declare const createGitServer: <const A extends GitAdapter>(options: ServerSetup<A>) => GitServer<ProvidedBy<A>>;
|