@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/store/outbox.mjs
CHANGED
|
@@ -131,11 +131,13 @@ const eventLimits = {
|
|
|
131
131
|
};
|
|
132
132
|
const mib = (bytes) => `${Math.round(bytes / 1024 ** 2)} MiB`;
|
|
133
133
|
const exhausted = (scope, undelivered) => fail("RESOURCE_EXHAUSTED", `${mib(undelivered)} of events in '${scope}' wait for delivery`, {
|
|
134
|
-
hint: `
|
|
134
|
+
hint: `Past ${mib(eventLimits.undelivered)} undelivered, writes that add events are refused until they're delivered: try again later`,
|
|
135
|
+
hostHint: `The host's events delivery, 'git.deliver' in '${scope}', is failing or behind: fix it, then retry or discard that job`,
|
|
135
136
|
context: { reason: "events-undelivered" }
|
|
136
137
|
});
|
|
137
138
|
const waitsFull = (scope) => fail("RESOURCE_EXHAUSTED", `'${scope}' already waits on 20 repos that had its names`, {
|
|
138
|
-
hint:
|
|
139
|
+
hint: "Each wait ends once the repo that had the name delivers its events: try again then",
|
|
140
|
+
hostHint: `'git.deliver' in '${scope}' looks for them every 10 seconds`,
|
|
139
141
|
context: { reason: "events-waiting" }
|
|
140
142
|
});
|
|
141
143
|
/**
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { exitIn, noCall, readableIn, syncIn, uncounted } from "./crossing.mjs";
|
|
2
|
+
import { JobGate } from "@ref0/infra";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
import * as Cause from "effect/Cause";
|
|
6
|
+
import * as Exit from "effect/Exit";
|
|
7
|
+
import * as Stream from "effect/Stream";
|
|
8
|
+
import * as EffectDuration from "effect/Duration";
|
|
9
|
+
import * as Scheduler from "effect/Scheduler";
|
|
10
|
+
import * as Data from "effect/Data";
|
|
11
|
+
// src/store/promises.ts
|
|
12
|
+
/** The door of a bridge with no server to close, as a client's own store: it always runs. */
|
|
13
|
+
const openDoor = {
|
|
14
|
+
refusal: () => void 0,
|
|
15
|
+
closing: new AbortController().signal
|
|
16
|
+
};
|
|
17
|
+
/** `door`'s refusal now, thrown: before a run, and after one, so a run the door outlived ends. */
|
|
18
|
+
const askDoor = (door) => {
|
|
19
|
+
const refused = door.refusal();
|
|
20
|
+
if (refused !== void 0) throw refused;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* `readable`, which errors with `closing`'s reason once it aborts, and cancels `readable` then. It
|
|
24
|
+
* stops the stream from in front of it, not inside it. `readableIn` runs the stream at once, so a
|
|
25
|
+
* cancel, even one before the first pull, reaches the bucket's stream the call opened.
|
|
26
|
+
* `Stream.interruptWhen` pulls on a forked fiber, and a cancel before that fiber starts left the
|
|
27
|
+
* bucket's stream open, cancelled by nothing.
|
|
28
|
+
*/
|
|
29
|
+
const untilClosing = (readable, closing) => {
|
|
30
|
+
const reader = readable.getReader();
|
|
31
|
+
let onClose = () => {};
|
|
32
|
+
const stop = () => closing.removeEventListener("abort", onClose);
|
|
33
|
+
reader.closed.then(stop, stop);
|
|
34
|
+
return new ReadableStream({
|
|
35
|
+
start: (controller) => {
|
|
36
|
+
onClose = () => {
|
|
37
|
+
controller.error(closing.reason);
|
|
38
|
+
reader.cancel(closing.reason).catch(() => void 0);
|
|
39
|
+
};
|
|
40
|
+
if (closing.aborted) return onClose();
|
|
41
|
+
closing.addEventListener("abort", onClose, { once: true });
|
|
42
|
+
},
|
|
43
|
+
pull: async (controller) => {
|
|
44
|
+
const next = await reader.read();
|
|
45
|
+
if (closing.aborted) return controller.error(closing.reason);
|
|
46
|
+
if (next.done) return controller.close();
|
|
47
|
+
controller.enqueue(next.value);
|
|
48
|
+
},
|
|
49
|
+
cancel: (reason) => reader.cancel(reason)
|
|
50
|
+
}, { highWaterMark: 0 });
|
|
51
|
+
};
|
|
52
|
+
/** Why a bridge's run takes no call scope: the door that called it counted its call. */
|
|
53
|
+
const bridged = uncounted("a bridge's run: the door that called it counted the call");
|
|
54
|
+
/**
|
|
55
|
+
* How the bridge runs on `context`: as a promise, at once, as an exit, and a stream as Web's. Each
|
|
56
|
+
* asks `door` first. The server's closing stops what's still running, and it ends as the door
|
|
57
|
+
* refuses: a promise rejects and a stream errors, never ending early as if it had finished.
|
|
58
|
+
*/
|
|
59
|
+
const runnerOf = (context, door) => {
|
|
60
|
+
const provided = (effect) => Effect.provideContext(effect, context);
|
|
61
|
+
const signalOf = (signal) => signal === void 0 ? door.closing : AbortSignal.any([signal, door.closing]);
|
|
62
|
+
const runExit = async (effect, signal) => {
|
|
63
|
+
askDoor(door);
|
|
64
|
+
const exit = await exitIn(provided(effect), bridged, signalOf(signal));
|
|
65
|
+
askDoor(door);
|
|
66
|
+
return exit;
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
run: async (effect, signal) => {
|
|
70
|
+
const exit = await runExit(effect, signal);
|
|
71
|
+
if (Exit.isFailure(exit)) throw Cause.squash(exit.cause);
|
|
72
|
+
return exit.value;
|
|
73
|
+
},
|
|
74
|
+
runNow: (effect) => {
|
|
75
|
+
askDoor(door);
|
|
76
|
+
return syncIn(provided(effect), bridged);
|
|
77
|
+
},
|
|
78
|
+
runExit,
|
|
79
|
+
readable: (stream) => {
|
|
80
|
+
const refused = door.refusal();
|
|
81
|
+
if (refused !== void 0) return readableIn(Stream.die(refused), context);
|
|
82
|
+
return untilClosing(readableIn(stream, context), door.closing);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
/** The store over `Records`, run on `context` through `door`. */
|
|
87
|
+
const promisesStore = (records, context, door) => {
|
|
88
|
+
const { jobs } = records;
|
|
89
|
+
const { run, readable } = runnerOf(context, door);
|
|
90
|
+
return {
|
|
91
|
+
read: (scope, reads, counts) => run(records.read(scope, reads, counts)),
|
|
92
|
+
commit: (scope, change) => run(records.commit(scope, change)),
|
|
93
|
+
add: (scope, addition) => run(records.add(scope, addition)),
|
|
94
|
+
watch: (scope, watch) => readable(Stream.suspend(() => records.watch(scope, watch))),
|
|
95
|
+
claim: (scope, request) => run(jobs.claim(scope, request)),
|
|
96
|
+
settle: (claim, outcome) => run(jobs.settle(claim, outcome)),
|
|
97
|
+
progress: (scope, write) => run(jobs.progress(scope, write)),
|
|
98
|
+
count: (scope) => run(jobs.count(scope)),
|
|
99
|
+
list: (scope, request) => run(jobs.list(scope, request)),
|
|
100
|
+
retry: (scope, job, input) => run(jobs.retry(scope, job, input)),
|
|
101
|
+
discard: (scope, job) => run(jobs.discard(scope, job))
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
/** How long a job's try a closed server holds off waits before the host's queue claims it again. */
|
|
105
|
+
const closedRetry = 6e4;
|
|
106
|
+
/**
|
|
107
|
+
* A job's store through `door`: each call asks it first, a read of the server's state with no
|
|
108
|
+
* await, so a try the closing outlived sends nothing more once one write lands.
|
|
109
|
+
*/
|
|
110
|
+
const doorStore = (store, door) => {
|
|
111
|
+
const wrapped = {
|
|
112
|
+
wake: {
|
|
113
|
+
set: (scope, at) => (askDoor(door), store.wake.set(scope, at)),
|
|
114
|
+
listen: (listener) => store.wake.listen(listener)
|
|
115
|
+
},
|
|
116
|
+
read: (scope, reads, counts) => (askDoor(door), store.read(scope, reads, counts)),
|
|
117
|
+
watch: (scope, watch) => (askDoor(door), store.watch(scope, watch)),
|
|
118
|
+
commit: (scope, change) => (askDoor(door), store.commit(scope, change)),
|
|
119
|
+
add: (scope, addition) => (askDoor(door), store.add(scope, addition)),
|
|
120
|
+
claim: (scope, request) => (askDoor(door), store.claim(scope, request)),
|
|
121
|
+
settle: (claim, outcome) => (askDoor(door), store.settle(claim, outcome)),
|
|
122
|
+
progress: (scope, write) => (askDoor(door), store.progress(scope, write)),
|
|
123
|
+
count: (scope) => (askDoor(door), store.count(scope)),
|
|
124
|
+
list: (scope, request) => (askDoor(door), store.list(scope, request)),
|
|
125
|
+
retry: (scope, job, input) => (askDoor(door), store.retry(scope, job, input)),
|
|
126
|
+
discard: (scope, job) => (askDoor(door), store.discard(scope, job))
|
|
127
|
+
};
|
|
128
|
+
const due = store.due?.bind(store);
|
|
129
|
+
if (due === void 0) return wrapped;
|
|
130
|
+
return {
|
|
131
|
+
...wrapped,
|
|
132
|
+
due: (request) => (askDoor(door), due(request))
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* The gate around each try of the jobs the server adds: once closed, or once its build failed, a
|
|
137
|
+
* try waits `closedRetry` and spends no attempt, and its `onFailure` doesn't run; each store call asks the
|
|
138
|
+
* door. Both read a flag, so a try's calls take no more turns than they did.
|
|
139
|
+
*/
|
|
140
|
+
const gateOf = (door, now) => ({
|
|
141
|
+
later: () => door.refusal() === void 0 ? void 0 : now() + closedRetry,
|
|
142
|
+
store: (store) => doorStore(store, door)
|
|
143
|
+
});
|
|
144
|
+
/**
|
|
145
|
+
* The queue over `JobQueue`, run on `context`: `register` throws a refused definition, as the
|
|
146
|
+
* promise queue did, and adds each through the server's door.
|
|
147
|
+
*/
|
|
148
|
+
const promisesQueue = (queue, context, door) => {
|
|
149
|
+
const { run, runNow } = runnerOf(context, door);
|
|
150
|
+
const now = () => syncIn(Effect.provideContext(Effect.clockWith((clock) => Effect.sync(() => clock.currentTimeMillisUnsafe())), context), noCall);
|
|
151
|
+
const gate = gateOf(door, now);
|
|
152
|
+
return {
|
|
153
|
+
register: (...definitions) => runNow(queue.addJobs(...definitions).pipe(Effect.provideService(JobGate, gate))),
|
|
154
|
+
run: (scope) => run(queue.run(scope)),
|
|
155
|
+
count: (scope) => run(queue.count(scope)),
|
|
156
|
+
list: (scope, request) => run(queue.list(scope, request)),
|
|
157
|
+
retry: (scope, job) => run(queue.retry(scope, job)),
|
|
158
|
+
discard: (scope, job) => run(queue.discard(scope, job))
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
/** A put's body that failed as it was read, carrying its own failure. */
|
|
162
|
+
var BodyFailure = class extends Data.TaggedError("BodyFailure") {};
|
|
163
|
+
const bodyOf = (body) => Stream.fromReadableStream({
|
|
164
|
+
evaluate: () => body,
|
|
165
|
+
onError: (cause) => new BodyFailure({ cause })
|
|
166
|
+
});
|
|
167
|
+
/**
|
|
168
|
+
* The bucket over `Bucket`, with `BucketLinks`' and `BucketUploads`' methods when the runtime has
|
|
169
|
+
* them, run on `context`: git tells a signing bucket by its methods.
|
|
170
|
+
*/
|
|
171
|
+
const promisesBucket = (bucket, links, uploads, context, door) => {
|
|
172
|
+
const { run, runExit, readable } = runnerOf(context, door);
|
|
173
|
+
const dropped = (body) => {
|
|
174
|
+
readableIn(body, context).cancel().catch(() => void 0);
|
|
175
|
+
};
|
|
176
|
+
const face = {
|
|
177
|
+
multipart: bucket.multipart,
|
|
178
|
+
put: (key, body, options) => run(Effect.catchTag(bucket.put(key, bodyOf(body), options), "BodyFailure", (failure) => Effect.die(failure.cause)), options?.signal),
|
|
179
|
+
/**
|
|
180
|
+
* `noted` is the body's single owner from infra's answer until `readable` takes it, in the tick
|
|
181
|
+
* the door last lets the read through. Every other way out, a failure, an interrupt or the door's
|
|
182
|
+
* refusal, cancels it, once.
|
|
183
|
+
*/
|
|
184
|
+
read: async (key, range, options) => {
|
|
185
|
+
const noted = { body: void 0 };
|
|
186
|
+
/**
|
|
187
|
+
* Nothing may yield between infra's answer and `noted`, its single owner, or an interrupt
|
|
188
|
+
* landing at that yield drops the body. So `PreventSchedulerYield` covers the host's whole
|
|
189
|
+
* read, from the bucket call's start to `noted`, and never the body's reading, which
|
|
190
|
+
* `readable` runs on `context`. A host `Bucket` Layer running long synchronous Effect work
|
|
191
|
+
* inside `read` delays other fibers until it returns; a pending promise still suspends. I0-1c's
|
|
192
|
+
* lazy read, which opens the body only when run, deletes this.
|
|
193
|
+
*/
|
|
194
|
+
const noting = Effect.provideService(Effect.uninterruptibleMask((restore) => Effect.tap(restore(bucket.read(key, range)), (found) => Effect.sync(() => {
|
|
195
|
+
noted.body = Option.getOrUndefined(found);
|
|
196
|
+
}))), Scheduler.PreventSchedulerYield, true);
|
|
197
|
+
try {
|
|
198
|
+
const exit = await runExit(noting, options?.signal);
|
|
199
|
+
if (Exit.isFailure(exit)) throw Cause.squash(exit.cause);
|
|
200
|
+
askDoor(door);
|
|
201
|
+
const body = noted.body;
|
|
202
|
+
noted.body = void 0;
|
|
203
|
+
return body === void 0 ? void 0 : readable(body);
|
|
204
|
+
} finally {
|
|
205
|
+
if (noted.body !== void 0) dropped(noted.body);
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
delete: (key, options) => run(bucket.remove(key), options?.signal),
|
|
209
|
+
list: (prefix, page, options) => run(bucket.list(prefix, page), options?.signal)
|
|
210
|
+
};
|
|
211
|
+
const signed = Option.match(links, {
|
|
212
|
+
onNone: () => ({}),
|
|
213
|
+
onSome: (links) => ({
|
|
214
|
+
url: (key, options) => run(links.url(key, options), options.signal),
|
|
215
|
+
putUrl: (key, options) => run(links.putUrl(key, options), options.signal),
|
|
216
|
+
head: (key, options) => run(Effect.map(links.head(key), Option.getOrUndefined), options?.signal)
|
|
217
|
+
})
|
|
218
|
+
});
|
|
219
|
+
const parted = Option.match(uploads, {
|
|
220
|
+
onNone: () => ({}),
|
|
221
|
+
onSome: (uploads) => ({
|
|
222
|
+
maxParts: uploads.maxParts,
|
|
223
|
+
beginUpload: (key, options) => run(uploads.beginUpload(key), options?.signal),
|
|
224
|
+
uploadUrl: (key, options) => run(uploads.uploadUrl(key, options), options.signal),
|
|
225
|
+
listParts: (key, upload, options) => run(uploads.listParts(key, upload), options?.signal),
|
|
226
|
+
completeUpload: (key, input, options) => run(uploads.completeUpload(key, input), options?.signal),
|
|
227
|
+
abortUpload: (key, upload, options) => run(uploads.abortUpload(key, upload), options?.signal)
|
|
228
|
+
})
|
|
229
|
+
});
|
|
230
|
+
return {
|
|
231
|
+
...face,
|
|
232
|
+
...signed,
|
|
233
|
+
...parted
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
/** The longest one timer waits: a later `until` sleeps in turns. */
|
|
237
|
+
const longestTimer = 2 ** 31 - 1;
|
|
238
|
+
/**
|
|
239
|
+
* The runtime's `Clock` as a promise, run on `context`, counted down by what each sleep asked, as a
|
|
240
|
+
* test's moves. It mirrors infra's `promiseClockOf`, which git can't import: infra's root names no
|
|
241
|
+
* promise face. Both go with the bridges, this one with SV's last step.
|
|
242
|
+
*/
|
|
243
|
+
const promisesClock = (clock, context, door) => {
|
|
244
|
+
const { runExit } = runnerOf(context, door);
|
|
245
|
+
const face = {
|
|
246
|
+
now: () => clock.currentTimeMillisUnsafe(),
|
|
247
|
+
sleep: async (until, signal) => {
|
|
248
|
+
askDoor(door);
|
|
249
|
+
for (let left = until - face.now(); left > 0 && signal?.aborted !== true;) {
|
|
250
|
+
const slept = Math.min(left, longestTimer);
|
|
251
|
+
await runExit(clock.sleep(EffectDuration.millis(slept)), signal);
|
|
252
|
+
left -= slept;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
return face;
|
|
257
|
+
};
|
|
258
|
+
export { openDoor, promisesBucket, promisesClock, promisesQueue, promisesStore };
|
package/dist/sync/bound.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { seamOf } from "../core/seam.mjs";
|
|
1
2
|
import { fail } from "../store/errors.mjs";
|
|
2
3
|
import * as Effect from "effect/Effect";
|
|
3
4
|
// src/sync/bound.ts
|
|
@@ -18,12 +19,16 @@ const bindSync = (git, bound) => {
|
|
|
18
19
|
if (boundByServer.has(git)) throw new TypeError("syncJobs runs once for each server");
|
|
19
20
|
boundByServer.set(git, bound);
|
|
20
21
|
};
|
|
21
|
-
/**
|
|
22
|
-
|
|
22
|
+
/**
|
|
23
|
+
* The server's binding, once its build has run, since the build makes it: `sync-unbound` when
|
|
24
|
+
* `syncJobs` never bound the server, and the build's own `UNAVAILABLE` when it failed.
|
|
25
|
+
*/
|
|
26
|
+
const boundOf = (git) => Effect.flatMap(seamOf(git)?.parts ?? Effect.void, () => {
|
|
23
27
|
const bound = boundByServer.get(git);
|
|
24
28
|
return bound === void 0 ? fail("FAILED_PRECONDITION", "Sync's jobs aren't bound to this server", {
|
|
25
|
-
hint: "
|
|
29
|
+
hint: "This server doesn't offer import or mirroring",
|
|
30
|
+
hostHint: "Call syncJobs(git, { providers }) as the server is made, before its build starts",
|
|
26
31
|
context: { reason: "sync-unbound" }
|
|
27
32
|
}) : Effect.succeed(bound);
|
|
28
|
-
};
|
|
33
|
+
});
|
|
29
34
|
export { bindSync, boundOf, importLimits };
|
package/dist/sync/jobs.d.mts
CHANGED
|
@@ -2,8 +2,8 @@ import { GitServer } from "../contracts/server.mjs";
|
|
|
2
2
|
import { SyncJobs, SyncJobsOptions } from "../contracts/sync.mjs";
|
|
3
3
|
import "./bound.mjs";
|
|
4
4
|
/**
|
|
5
|
-
* Sync's two jobs
|
|
6
|
-
* `
|
|
7
|
-
*
|
|
5
|
+
* Sync's two jobs, which `git`'s build binds and registers on its queue: `git.sync.import`, keyed
|
|
6
|
+
* `import`, and `git.sync.mirror`, keyed by its ref, each in its repo's scope. Called once for each
|
|
7
|
+
* server, before its runtime is built.
|
|
8
8
|
*/
|
|
9
9
|
export declare const syncJobs: (git: GitServer, options: SyncJobsOptions) => SyncJobs;
|
package/dist/sync/jobs.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { hostAuthorize } from "../auth/authorize.mjs";
|
|
2
|
-
import { partsOf } from "../core/seam.mjs";
|
|
3
2
|
import { mirrorJobName } from "../store/records.mjs";
|
|
4
3
|
import { knowJobs } from "../server/extension.mjs";
|
|
5
4
|
import { bindSync, importLimits } from "./bound.mjs";
|
|
@@ -31,22 +30,21 @@ const providersOf = (providers) => {
|
|
|
31
30
|
return named;
|
|
32
31
|
};
|
|
33
32
|
/**
|
|
34
|
-
* `syncJobs` with the import's limits, which tests make small: the jobs' definitions
|
|
35
|
-
* `git
|
|
33
|
+
* `syncJobs` with the import's limits, which tests make small: the jobs' definitions, known to
|
|
34
|
+
* `git`'s pushes by name, which its build binds and registers on its queue.
|
|
36
35
|
*/
|
|
37
36
|
const syncJobsWith = (git, options, limits) => {
|
|
38
|
-
const parts = partsOf(git);
|
|
39
|
-
if (parts === void 0) throw new TypeError("syncJobs takes a server createGitServer made");
|
|
40
|
-
const host = {
|
|
41
|
-
...parts.core,
|
|
42
|
-
authorize: hostAuthorize
|
|
43
|
-
};
|
|
44
37
|
const caller = { actor: { anonymous: true } };
|
|
45
38
|
const providers = providersOf(options.providers);
|
|
39
|
+
let bound;
|
|
40
|
+
const boundNow = () => {
|
|
41
|
+
if (bound === void 0) throw new TypeError("Sync's jobs ran before the server's build");
|
|
42
|
+
return bound;
|
|
43
|
+
};
|
|
46
44
|
const importJob = defineJob({
|
|
47
45
|
name: importJobName,
|
|
48
46
|
schema: Schema.toStandardSchemaV1(ImportJobData),
|
|
49
|
-
handler: (job, context) => importTry(
|
|
47
|
+
handler: (job, context) => importTry(boundNow())(job, context),
|
|
50
48
|
timeout: tryTimeout,
|
|
51
49
|
retry: syncRetry,
|
|
52
50
|
onFailure: importFailed
|
|
@@ -54,27 +52,32 @@ const syncJobsWith = (git, options, limits) => {
|
|
|
54
52
|
const mirrorJob = defineJob({
|
|
55
53
|
name: mirrorJobName,
|
|
56
54
|
schema: Schema.toStandardSchemaV1(MirrorJobData),
|
|
57
|
-
handler: (job, context) => mirrorTry(
|
|
55
|
+
handler: (job, context) => mirrorTry(boundNow())(job, context),
|
|
58
56
|
timeout: tryTimeout,
|
|
59
57
|
retry: syncRetry
|
|
60
58
|
});
|
|
61
|
-
knowJobs(git, [importJob, mirrorJob])
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
knowJobs(git, [importJob, mirrorJob], ({ parts }) => {
|
|
60
|
+
const host = {
|
|
61
|
+
...parts.core,
|
|
62
|
+
authorize: hostAuthorize
|
|
63
|
+
};
|
|
64
|
+
bound = {
|
|
65
|
+
core: parts.core,
|
|
66
|
+
host,
|
|
67
|
+
caller,
|
|
68
|
+
providers,
|
|
69
|
+
limits,
|
|
70
|
+
importJob,
|
|
71
|
+
mirrorJob
|
|
72
|
+
};
|
|
73
|
+
bindSync(git, bound);
|
|
74
|
+
});
|
|
72
75
|
return [importJob, mirrorJob];
|
|
73
76
|
};
|
|
74
77
|
/**
|
|
75
|
-
* Sync's two jobs
|
|
76
|
-
* `
|
|
77
|
-
*
|
|
78
|
+
* Sync's two jobs, which `git`'s build binds and registers on its queue: `git.sync.import`, keyed
|
|
79
|
+
* `import`, and `git.sync.mirror`, keyed by its ref, each in its repo's scope. Called once for each
|
|
80
|
+
* server, before its runtime is built.
|
|
78
81
|
*/
|
|
79
82
|
const syncJobs = (git, options) => syncJobsWith(git, options, importLimits);
|
|
80
83
|
export { syncJobs, syncJobsWith };
|
package/dist/sync/tries.mjs
CHANGED
|
@@ -44,8 +44,8 @@ const syncRetry = ({ attempt, error }) => {
|
|
|
44
44
|
return Math.min(1e3 * 2 ** (attempt - 1), 6e5);
|
|
45
45
|
};
|
|
46
46
|
/** A source naming a provider `syncJobs` wasn't given: refused as it's asked for. */
|
|
47
|
-
const unknownProvider = (name) => gitError("INVALID_ARGUMENT", `No provider named '${name}'
|
|
48
|
-
|
|
47
|
+
const unknownProvider = (name) => gitError("INVALID_ARGUMENT", `No provider named '${name}'`, {
|
|
48
|
+
hostHint: `Pass the '${name}' provider to syncJobs`,
|
|
49
49
|
context: { reason: "provider-unknown" }
|
|
50
50
|
});
|
|
51
51
|
const providerFailed = (name) => gitError("UNAVAILABLE", `The '${name}' provider made no remote for this try`, { hint: "The job tries again" });
|
package/dist/topics/advance.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { millis } from "../contracts/promises.mjs";
|
|
1
2
|
import { hostCall } from "../auth/host-function.mjs";
|
|
2
3
|
import { advanceRow } from "../store/queue-jobs.mjs";
|
|
3
4
|
import { storeCall } from "../store/errors.mjs";
|
|
@@ -8,7 +9,7 @@ import { projectTopic } from "./directory.mjs";
|
|
|
8
9
|
import { saveMargin } from "./host.mjs";
|
|
9
10
|
import { addMember, candidateAt, memberRead, releaseMember, reserveMember } from "./members.mjs";
|
|
10
11
|
import { commitTopic, currentSet, durationWords, entriesOf, failureOf, readTopic, setKeyOf, topicOf } from "./topic.mjs";
|
|
11
|
-
import { LostTry, defineJob
|
|
12
|
+
import { LostTry, defineJob } from "@ref0/infra";
|
|
12
13
|
import * as Effect from "effect/Effect";
|
|
13
14
|
import * as Result from "effect/Result";
|
|
14
15
|
import * as Schema from "effect/Schema";
|
package/dist/topics/calls.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { addMissing } from "./advance.mjs";
|
|
|
8
8
|
import { claimKey, indexPage } from "./directory.mjs";
|
|
9
9
|
import { admitMember } from "./members.mjs";
|
|
10
10
|
import { TopicReportRow } from "./rows.mjs";
|
|
11
|
-
import { commitTopic, currentSet, existing, failureOf, hintOf, readTopic, sameMembers, setKeyOf, topicOf } from "./topic.mjs";
|
|
11
|
+
import { answeredFailure, commitTopic, currentSet, existing, failureOf, hintOf, readTopic, sameMembers, setKeyOf, topicOf } from "./topic.mjs";
|
|
12
12
|
import * as Effect from "effect/Effect";
|
|
13
13
|
import * as Schema from "effect/Schema";
|
|
14
14
|
// src/topics/calls.ts
|
|
@@ -161,10 +161,10 @@ const seenTopic = Effect.fnUntraced(function* (core, caller, topic, row) {
|
|
|
161
161
|
if (waitingOn !== void 0 && shown(waitingOn)) seen.waitingOn = waitingOn;
|
|
162
162
|
if (failure !== void 0) {
|
|
163
163
|
const { repo, entry, candidate } = failure;
|
|
164
|
-
seen.failure = naming.has(failure.reason) && repo !== void 0 && row.members.some((member) => member.repo === repo && places.has(placeOf(member))) && (entry === void 0 || entries.some((seenEntry) => seenEntry.entry === entry)) && (candidate === void 0 || candidates.some((seenOne) => seenOne.candidate === candidate)) ? failure : {
|
|
164
|
+
seen.failure = naming.has(failure.reason) && repo !== void 0 && row.members.some((member) => member.repo === repo && places.has(placeOf(member))) && (entry === void 0 || entries.some((seenEntry) => seenEntry.entry === entry)) && (candidate === void 0 || candidates.some((seenOne) => seenOne.candidate === candidate)) ? failure : answeredFailure({
|
|
165
165
|
reason: failure.reason,
|
|
166
166
|
hint: hintOf(row, failure.reason)
|
|
167
|
-
};
|
|
167
|
+
});
|
|
168
168
|
}
|
|
169
169
|
return seen;
|
|
170
170
|
});
|
package/dist/topics/host.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import "../contracts/promises.mjs";
|
|
1
2
|
import "../contracts/services.mjs";
|
|
2
3
|
import { TopicsFactory, TopicsOptions } from "../contracts/topics.mjs";
|
|
3
4
|
import "../queue/host.mjs";
|
|
4
|
-
import { Duration } from "@ref0/infra";
|
|
5
5
|
/**
|
|
6
6
|
* Topics across a server's repos: `git.topics`, their jobs and their events. A `timeout` or a
|
|
7
7
|
* `report.timeout` that isn't a duration from 1 millisecond to 365 days, in whole milliseconds, or
|
package/dist/topics/host.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { millis } from "../contracts/promises.mjs";
|
|
1
2
|
import { checkTimeout, isTimeout } from "../queue/host.mjs";
|
|
2
3
|
import "../queue/schedule.mjs";
|
|
3
|
-
import { millis } from "@ref0/infra";
|
|
4
4
|
import * as Predicate from "effect/Predicate";
|
|
5
5
|
// src/topics/host.ts
|
|
6
6
|
/** What `topics()` checked, by the factory it made, so a server takes only those. */
|
package/dist/topics/topic.mjs
CHANGED
|
@@ -81,23 +81,38 @@ const entriesOf = (row) => row.members.flatMap(({ repo, target, source, head, ke
|
|
|
81
81
|
/** A duration as a hint says it: its words, or its milliseconds. */
|
|
82
82
|
const durationWords = (duration) => Predicate.isNumber(duration) ? `${duration} ms` : duration;
|
|
83
83
|
/**
|
|
84
|
-
* A failure's hint from its reason alone, and `summary` before it when given:
|
|
85
|
-
* key never opens again
|
|
84
|
+
* A failure's hint from its reason alone, and `summary` before it when given: the caller's own
|
|
85
|
+
* steps, since a failed topic's key never opens again. Raising a timeout is the host's, `hostHintOf`.
|
|
86
86
|
*/
|
|
87
87
|
const hintOf = (row, reason, summary) => {
|
|
88
88
|
const again = `the change under a new key: ${row.key} never opens again`;
|
|
89
89
|
const how = reason === "timeout" || reason === "report-timeout" ? {
|
|
90
|
-
timeout:
|
|
91
|
-
"report-timeout": "Send the report sooner
|
|
90
|
+
timeout: "Restart each stalled target with queue.restart",
|
|
91
|
+
"report-timeout": "Send the report sooner"
|
|
92
92
|
}[reason] : void 0;
|
|
93
93
|
if (how === void 0) return `Add ${again}`;
|
|
94
94
|
return summary === void 0 ? `${how}, then add ${again}` : `${summary}. ${how}, then add ${again}`;
|
|
95
95
|
};
|
|
96
|
-
/**
|
|
96
|
+
/** Each timeout's step only the host can take, since `topics()` sets it. */
|
|
97
|
+
const hostSteps = {
|
|
98
|
+
timeout: "Raise topics({ timeout }) if the targets were only slow",
|
|
99
|
+
"report-timeout": "Raise topics({ report: { timeout } }) if reports come in slower"
|
|
100
|
+
};
|
|
101
|
+
/** A failure's step only the host can take: none but a timeout's. */
|
|
102
|
+
const hostHintOf = (reason) => hostSteps[reason];
|
|
103
|
+
/** A failure, with its hint, which names its summary: as the `topic.failed` event keeps it. */
|
|
97
104
|
const failureOf = (row, failure) => ({
|
|
98
105
|
...failure,
|
|
99
106
|
hint: hintOf(row, failure.reason, failure.summary)
|
|
100
107
|
});
|
|
108
|
+
/** A failure as in-process calls answer it: with the host's step, `hostHint`, when it has one. */
|
|
109
|
+
const answeredFailure = (failure) => {
|
|
110
|
+
const hostHint = hostHintOf(failure.reason);
|
|
111
|
+
return hostHint === void 0 ? failure : {
|
|
112
|
+
...failure,
|
|
113
|
+
hostHint
|
|
114
|
+
};
|
|
115
|
+
};
|
|
101
116
|
/** A topic as its calls answer it. */
|
|
102
117
|
const topicOf = (id, row) => {
|
|
103
118
|
const topic = {
|
|
@@ -107,7 +122,7 @@ const topicOf = (id, row) => {
|
|
|
107
122
|
entries: entriesOf(row),
|
|
108
123
|
candidates: row.candidates.map(({ base: _base, passed: _passed, ...listed }) => listed)
|
|
109
124
|
};
|
|
110
|
-
if (row.failure !== void 0) topic.failure = failureOf(row, row.failure);
|
|
125
|
+
if (row.failure !== void 0) topic.failure = answeredFailure(failureOf(row, row.failure));
|
|
111
126
|
if (row.waitingOn !== void 0) topic.waitingOn = row.waitingOn;
|
|
112
127
|
return topic;
|
|
113
128
|
};
|
|
@@ -123,4 +138,4 @@ const sameMembers = (row, members) => {
|
|
|
123
138
|
const held = new Set(row.members.map(named));
|
|
124
139
|
return row.members.length === members.length && members.every((member) => held.has(named(member)));
|
|
125
140
|
};
|
|
126
|
-
export { commitTopic, currentSet, durationWords, entriesOf, existing, failureOf, hintOf, readTopic, sameMembers, setKeyOf, topicOf };
|
|
141
|
+
export { answeredFailure, commitTopic, currentSet, durationWords, entriesOf, existing, failureOf, hintOf, hostHintOf, readTopic, sameMembers, setKeyOf, topicOf };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ref0/git",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Git hosting as a library: a server, a client and the engine",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
}
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@ref0/infra": "0.
|
|
81
|
+
"@ref0/infra": "0.3.0",
|
|
82
82
|
"effect": "4.1.4",
|
|
83
83
|
"pako": "2.1.0"
|
|
84
84
|
},
|