@effected/runtimes 0.1.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/BunResolver.js +79 -0
- package/DenoResolver.js +79 -0
- package/GitHub.js +220 -0
- package/LICENSE +21 -0
- package/NodeRelease.js +73 -0
- package/NodeResolver.js +114 -0
- package/NodeSchedule.js +217 -0
- package/README.md +155 -0
- package/ResolvedVersions.js +122 -0
- package/index.d.ts +737 -0
- package/index.js +9 -0
- package/internal/defaults/bun.js +855 -0
- package/internal/defaults/deno.js +1543 -0
- package/internal/defaults/node.js +4443 -0
- package/internal/feeds.js +84 -0
- package/internal/githubRuntime.js +43 -0
- package/internal/http.js +127 -0
- package/internal/releaseIndex.js +46 -0
- package/internal/resolve.js +44 -0
- package/internal/strategy.js +53 -0
- package/package.json +50 -0
- package/tsdoc-metadata.json +11 -0
package/BunResolver.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { bunDefaults } from "./internal/defaults/bun.js";
|
|
2
|
+
import { Increments } from "./ResolvedVersions.js";
|
|
3
|
+
import { build } from "./internal/githubRuntime.js";
|
|
4
|
+
import { populateAuto, populateFresh, populateOffline } from "./internal/strategy.js";
|
|
5
|
+
import { SemVer } from "@effected/semver";
|
|
6
|
+
import { Context, Schema } from "effect";
|
|
7
|
+
|
|
8
|
+
//#region src/BunResolver.ts
|
|
9
|
+
/**
|
|
10
|
+
* One published Bun release.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
var BunRelease = class extends Schema.Class("BunRelease")({
|
|
15
|
+
/** The released version. */
|
|
16
|
+
version: SemVer,
|
|
17
|
+
/** When it was published. */
|
|
18
|
+
date: Schema.DateTimeUtc
|
|
19
|
+
}) {};
|
|
20
|
+
/**
|
|
21
|
+
* How to resolve Bun versions.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
const BunResolverOptions = Schema.Struct({
|
|
26
|
+
/** The semver range to match. Defaults to `*`. */
|
|
27
|
+
range: Schema.optionalKey(Schema.String),
|
|
28
|
+
/** How to group matches. Defaults to `latest`. */
|
|
29
|
+
increments: Schema.optionalKey(Increments),
|
|
30
|
+
/** A range whose newest match becomes the `default` field. */
|
|
31
|
+
defaultVersion: Schema.optionalKey(Schema.String)
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* The Bun resolver.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { BunResolver } from "@effected/runtimes";
|
|
39
|
+
* import { Effect } from "effect";
|
|
40
|
+
*
|
|
41
|
+
* const program = Effect.gen(function* () {
|
|
42
|
+
* const resolver = yield* BunResolver;
|
|
43
|
+
* return (yield* resolver.resolve({ range: "^1.0.0" })).latest;
|
|
44
|
+
* }).pipe(Effect.provide(BunResolver.layerOffline));
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
var BunResolver = class extends Context.Service()("@effected/runtimes/BunResolver") {
|
|
50
|
+
/** Try GitHub, fall back to the bundled snapshot. */
|
|
51
|
+
static layer = mk(this, (index, live, offline) => populateAuto(index, "bun", live, offline));
|
|
52
|
+
/** GitHub or nothing. Fails with `FreshnessError` when it cannot be reached. */
|
|
53
|
+
static layerFresh = mk(this, (index, live) => populateFresh(index, "bun", live));
|
|
54
|
+
/** The bundled snapshot only. Performs no IO and requires nothing. */
|
|
55
|
+
static layerOffline = mk(this, (index, _live, offline) => populateOffline(index, offline));
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* The tag arrives as `this` rather than by name.
|
|
59
|
+
*
|
|
60
|
+
* A static initializer runs while the module-scope `BunResolver` binding is
|
|
61
|
+
* still in its temporal dead zone, so naming the class here throws "Cannot
|
|
62
|
+
* access 'BunResolver' before initialization" at import time. Inside a static
|
|
63
|
+
* initializer `this` *is* the class, which is why `Layer.effect(this, ...)` is
|
|
64
|
+
* the idiomatic v4 spelling.
|
|
65
|
+
*/
|
|
66
|
+
function mk(tag, strategy) {
|
|
67
|
+
return build({
|
|
68
|
+
tag,
|
|
69
|
+
runtime: "bun",
|
|
70
|
+
owner: "oven-sh",
|
|
71
|
+
repo: "bun",
|
|
72
|
+
spanName: "BunResolver.resolve",
|
|
73
|
+
defaults: bunDefaults,
|
|
74
|
+
make: (fields) => BunRelease.make(fields)
|
|
75
|
+
}, strategy);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { BunRelease, BunResolver, BunResolverOptions };
|
package/DenoResolver.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Increments } from "./ResolvedVersions.js";
|
|
2
|
+
import { build } from "./internal/githubRuntime.js";
|
|
3
|
+
import { populateAuto, populateFresh, populateOffline } from "./internal/strategy.js";
|
|
4
|
+
import { denoDefaults } from "./internal/defaults/deno.js";
|
|
5
|
+
import { SemVer } from "@effected/semver";
|
|
6
|
+
import { Context, Schema } from "effect";
|
|
7
|
+
|
|
8
|
+
//#region src/DenoResolver.ts
|
|
9
|
+
/**
|
|
10
|
+
* One published Deno release.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
var DenoRelease = class extends Schema.Class("DenoRelease")({
|
|
15
|
+
/** The released version. */
|
|
16
|
+
version: SemVer,
|
|
17
|
+
/** When it was published. */
|
|
18
|
+
date: Schema.DateTimeUtc
|
|
19
|
+
}) {};
|
|
20
|
+
/**
|
|
21
|
+
* How to resolve Deno versions.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
const DenoResolverOptions = Schema.Struct({
|
|
26
|
+
/** The semver range to match. Defaults to `*`. */
|
|
27
|
+
range: Schema.optionalKey(Schema.String),
|
|
28
|
+
/** How to group matches. Defaults to `latest`. */
|
|
29
|
+
increments: Schema.optionalKey(Increments),
|
|
30
|
+
/** A range whose newest match becomes the `default` field. */
|
|
31
|
+
defaultVersion: Schema.optionalKey(Schema.String)
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* The Deno resolver.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { DenoResolver } from "@effected/runtimes";
|
|
39
|
+
* import { Effect } from "effect";
|
|
40
|
+
*
|
|
41
|
+
* const program = Effect.gen(function* () {
|
|
42
|
+
* const resolver = yield* DenoResolver;
|
|
43
|
+
* return (yield* resolver.resolve({ range: "^2.0.0" })).latest;
|
|
44
|
+
* }).pipe(Effect.provide(DenoResolver.layerOffline));
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
var DenoResolver = class extends Context.Service()("@effected/runtimes/DenoResolver") {
|
|
50
|
+
/** Try GitHub, fall back to the bundled snapshot. */
|
|
51
|
+
static layer = mk(this, (index, live, offline) => populateAuto(index, "deno", live, offline));
|
|
52
|
+
/** GitHub or nothing. Fails with `FreshnessError` when it cannot be reached. */
|
|
53
|
+
static layerFresh = mk(this, (index, live) => populateFresh(index, "deno", live));
|
|
54
|
+
/** The bundled snapshot only. Performs no IO and requires nothing. */
|
|
55
|
+
static layerOffline = mk(this, (index, _live, offline) => populateOffline(index, offline));
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* The tag arrives as `this` rather than by name.
|
|
59
|
+
*
|
|
60
|
+
* A static initializer runs while the module-scope `DenoResolver` binding is
|
|
61
|
+
* still in its temporal dead zone, so naming the class here throws "Cannot
|
|
62
|
+
* access 'DenoResolver' before initialization" at import time. Inside a static
|
|
63
|
+
* initializer `this` *is* the class, which is why `Layer.effect(this, ...)` is
|
|
64
|
+
* the idiomatic v4 spelling.
|
|
65
|
+
*/
|
|
66
|
+
function mk(tag, strategy) {
|
|
67
|
+
return build({
|
|
68
|
+
tag,
|
|
69
|
+
runtime: "deno",
|
|
70
|
+
owner: "denoland",
|
|
71
|
+
repo: "deno",
|
|
72
|
+
spanName: "DenoResolver.resolve",
|
|
73
|
+
defaults: denoDefaults,
|
|
74
|
+
make: (fields) => DenoRelease.make(fields)
|
|
75
|
+
}, strategy);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { DenoRelease, DenoResolver, DenoResolverOptions };
|
package/GitHub.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { paginate } from "./internal/http.js";
|
|
2
|
+
import { Config, Context, Effect, Layer, Option, Redacted, Schema } from "effect";
|
|
3
|
+
import { FetchHttpClient, HttpClient } from "effect/unstable/http";
|
|
4
|
+
|
|
5
|
+
//#region src/GitHub.ts
|
|
6
|
+
/**
|
|
7
|
+
* Talking to GitHub: pluggable authentication, a REST client, and the typed
|
|
8
|
+
* failure ladder that every network fetch in this package reports through.
|
|
9
|
+
*
|
|
10
|
+
* The two nodejs.org feeds reuse this ladder rather than minting a parallel
|
|
11
|
+
* one, so the module is named for its dominant user rather than for the
|
|
12
|
+
* lowest common denominator.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* GitHub rejected the credentials.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
var AuthenticationError = class extends Schema.TaggedErrorClass()("AuthenticationError", {
|
|
22
|
+
/** How the request was authenticated when it was rejected. */
|
|
23
|
+
method: Schema.Literals(["token", "anonymous"]) }) {};
|
|
24
|
+
/**
|
|
25
|
+
* GitHub's rate limit was exhausted.
|
|
26
|
+
*
|
|
27
|
+
* `retryAfter` is what a caller needs to back off correctly, which is why it is
|
|
28
|
+
* a structured field rather than prose in a message.
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
var RateLimitError = class extends Schema.TaggedErrorClass()("RateLimitError", {
|
|
33
|
+
/** Seconds to wait before retrying, when GitHub said. */
|
|
34
|
+
retryAfter: Schema.optionalKey(Schema.Number),
|
|
35
|
+
/** The request quota for the window. */
|
|
36
|
+
limit: Schema.Number,
|
|
37
|
+
/** Requests left in the window. */
|
|
38
|
+
remaining: Schema.Number
|
|
39
|
+
}) {};
|
|
40
|
+
/**
|
|
41
|
+
* A request did not complete, or completed with an unusable status.
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
var NetworkError = class extends Schema.TaggedErrorClass()("NetworkError", {
|
|
46
|
+
/** The URL that failed. */
|
|
47
|
+
url: Schema.String,
|
|
48
|
+
/** The HTTP status, when there was a response at all. */
|
|
49
|
+
status: Schema.optionalKey(Schema.Number),
|
|
50
|
+
/** The underlying transport failure. */
|
|
51
|
+
cause: Schema.Defect()
|
|
52
|
+
}) {};
|
|
53
|
+
/**
|
|
54
|
+
* A feed responded, but not with the shape this package expects.
|
|
55
|
+
*
|
|
56
|
+
* An operator-facing signal that an upstream feed changed.
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
var ResponseParseError = class extends Schema.TaggedErrorClass()("ResponseParseError", {
|
|
61
|
+
/** The URL whose body could not be decoded. */
|
|
62
|
+
source: Schema.String,
|
|
63
|
+
/** The decoding failure. */
|
|
64
|
+
cause: Schema.Defect()
|
|
65
|
+
}) {};
|
|
66
|
+
/**
|
|
67
|
+
* Materialize the engine's raw failure record into the public error ladder.
|
|
68
|
+
*
|
|
69
|
+
* The engine (`internal/http.ts`) never imports these classes — it returns raw
|
|
70
|
+
* records and this is the single place they become errors. That is what keeps
|
|
71
|
+
* the transport layer free of the facade and the import graph acyclic.
|
|
72
|
+
*
|
|
73
|
+
* `method` is what the *caller* actually sent, not a guess. Hardcoding it to
|
|
74
|
+
* `"token"` made the `"anonymous"` arm of `AuthenticationError` unreachable and
|
|
75
|
+
* mislabelled every anonymous rejection — the same shape of lie as v3's
|
|
76
|
+
* hardcoded `source: "api"`.
|
|
77
|
+
*
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
const mapHttpFailure = (failure, method) => {
|
|
81
|
+
switch (failure._kind) {
|
|
82
|
+
case "auth": return new AuthenticationError({ method });
|
|
83
|
+
case "rateLimit": return new RateLimitError({
|
|
84
|
+
...failure.retryAfter !== void 0 ? { retryAfter: failure.retryAfter } : {},
|
|
85
|
+
limit: failure.limit,
|
|
86
|
+
remaining: failure.remaining
|
|
87
|
+
});
|
|
88
|
+
case "network": return new NetworkError({
|
|
89
|
+
url: failure.url,
|
|
90
|
+
...failure.status !== void 0 ? { status: failure.status } : {},
|
|
91
|
+
cause: failure.cause
|
|
92
|
+
});
|
|
93
|
+
case "parse": return new ResponseParseError({
|
|
94
|
+
source: failure.source,
|
|
95
|
+
cause: failure.cause
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* A tag as `GET /repos/{owner}/{repo}/tags` returns it.
|
|
101
|
+
*
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
104
|
+
var GitHubTag = class extends Schema.Class("GitHubTag")({ name: Schema.String }) {};
|
|
105
|
+
/**
|
|
106
|
+
* A release as `GET /repos/{owner}/{repo}/releases` returns it.
|
|
107
|
+
*
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
var GitHubRelease = class extends Schema.Class("GitHubRelease")({
|
|
111
|
+
tag_name: Schema.String,
|
|
112
|
+
draft: Schema.Boolean,
|
|
113
|
+
prerelease: Schema.Boolean,
|
|
114
|
+
published_at: Schema.NullOr(Schema.String)
|
|
115
|
+
}) {};
|
|
116
|
+
const bearer = (token) => ({ authorization: `Bearer ${Redacted.value(token)}` });
|
|
117
|
+
/**
|
|
118
|
+
* Read the credentials as `Redacted` from the start.
|
|
119
|
+
*
|
|
120
|
+
* `Config.string` would hand back a plain string that only becomes `Redacted` at
|
|
121
|
+
* the `bearer` call — a window in which the secret is an ordinary value that any
|
|
122
|
+
* log, span annotation or error rendering could pick up. `Config.redacted` closes
|
|
123
|
+
* the window: the token is never a bare string anywhere in this module.
|
|
124
|
+
*/
|
|
125
|
+
const patConfig = Config.redacted("GITHUB_PERSONAL_ACCESS_TOKEN").pipe(Config.option);
|
|
126
|
+
const tokenConfig = Config.redacted("GITHUB_TOKEN").pipe(Config.option);
|
|
127
|
+
/**
|
|
128
|
+
* How GitHub requests are authenticated.
|
|
129
|
+
*
|
|
130
|
+
* @public
|
|
131
|
+
*/
|
|
132
|
+
var GitHubAuth = class GitHubAuth extends Context.Service()("@effected/runtimes/GitHubAuth") {
|
|
133
|
+
/**
|
|
134
|
+
* Send no credentials. GitHub allows this, at a much lower rate limit.
|
|
135
|
+
*/
|
|
136
|
+
static anonymous = Layer.succeed(GitHubAuth)({ headers: Effect.succeed({}) });
|
|
137
|
+
/**
|
|
138
|
+
* Authenticate with a personal access token.
|
|
139
|
+
*
|
|
140
|
+
* This returns a fresh layer per call, so bind it to a constant rather than
|
|
141
|
+
* calling it inline twice — layers are memoized by reference.
|
|
142
|
+
*/
|
|
143
|
+
static token = (token) => Layer.succeed(GitHubAuth)({ headers: Effect.succeed(bearer(token)) });
|
|
144
|
+
/**
|
|
145
|
+
* Detect a credential from the environment, preferring an explicit PAT.
|
|
146
|
+
*
|
|
147
|
+
* Precedence is `GITHUB_PERSONAL_ACCESS_TOKEN`, then `GITHUB_TOKEN`, then
|
|
148
|
+
* unauthenticated — the v3 policy, kept, but read through `Config` so a test
|
|
149
|
+
* can swap the `ConfigProvider` instead of mutating `process.env`.
|
|
150
|
+
*/
|
|
151
|
+
static layer = Layer.effect(GitHubAuth, Effect.gen(function* () {
|
|
152
|
+
const pat = yield* patConfig;
|
|
153
|
+
const token = yield* tokenConfig;
|
|
154
|
+
if (Option.isSome(pat)) {
|
|
155
|
+
if (Option.isSome(token)) yield* Effect.logWarning("Both GITHUB_PERSONAL_ACCESS_TOKEN and GITHUB_TOKEN are set; using the former");
|
|
156
|
+
return { headers: Effect.succeed(bearer(pat.value)) };
|
|
157
|
+
}
|
|
158
|
+
if (Option.isSome(token)) return { headers: Effect.succeed(bearer(token.value)) };
|
|
159
|
+
return { headers: Effect.succeed({}) };
|
|
160
|
+
}).pipe(Effect.orDie));
|
|
161
|
+
};
|
|
162
|
+
const TagList = Schema.Array(GitHubTag);
|
|
163
|
+
const ReleaseList = Schema.Array(GitHubRelease);
|
|
164
|
+
const listUrl = (owner, repo, kind) => (page, perPage) => `https://api.github.com/repos/${owner}/${repo}/${kind}?per_page=${perPage}&page=${page}`;
|
|
165
|
+
const GITHUB_HEADERS = {
|
|
166
|
+
accept: "application/vnd.github+json",
|
|
167
|
+
"x-github-api-version": "2022-11-28"
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* A GitHub REST client over `HttpClient`.
|
|
171
|
+
*
|
|
172
|
+
* v3 reached for `octokit` here, which cost two large dependency graphs to fund
|
|
173
|
+
* two GET requests. Programming against `HttpClient` from `effect` core keeps
|
|
174
|
+
* the package boundary tier and lets a consumer supply any transport.
|
|
175
|
+
*
|
|
176
|
+
* @public
|
|
177
|
+
*/
|
|
178
|
+
var GitHubClient = class GitHubClient extends Context.Service()("@effected/runtimes/GitHubClient") {
|
|
179
|
+
/**
|
|
180
|
+
* The client, requiring an `HttpClient` and a `GitHubAuth` from the context.
|
|
181
|
+
*/
|
|
182
|
+
static layer = Layer.effect(GitHubClient, Effect.gen(function* () {
|
|
183
|
+
const auth = yield* GitHubAuth;
|
|
184
|
+
const http = yield* HttpClient.HttpClient;
|
|
185
|
+
const list = (owner, repo, kind, schema, options) => Effect.gen(function* () {
|
|
186
|
+
const headers = yield* auth.headers;
|
|
187
|
+
const method = headers.authorization === void 0 ? "anonymous" : "token";
|
|
188
|
+
return yield* paginate(listUrl(owner, repo, kind), schema, {
|
|
189
|
+
...GITHUB_HEADERS,
|
|
190
|
+
...headers
|
|
191
|
+
}, options).pipe(Effect.mapError((failure) => mapHttpFailure(failure, method)));
|
|
192
|
+
}).pipe(Effect.provideService(HttpClient.HttpClient, http));
|
|
193
|
+
return {
|
|
194
|
+
listTags: Effect.fn("GitHubClient.listTags")(function* (owner, repo, options) {
|
|
195
|
+
yield* Effect.annotateCurrentSpan({
|
|
196
|
+
owner,
|
|
197
|
+
repo
|
|
198
|
+
});
|
|
199
|
+
return yield* list(owner, repo, "tags", TagList, options);
|
|
200
|
+
}),
|
|
201
|
+
listReleases: Effect.fn("GitHubClient.listReleases")(function* (owner, repo, options) {
|
|
202
|
+
yield* Effect.annotateCurrentSpan({
|
|
203
|
+
owner,
|
|
204
|
+
repo
|
|
205
|
+
});
|
|
206
|
+
return yield* list(owner, repo, "releases", ReleaseList, options);
|
|
207
|
+
})
|
|
208
|
+
};
|
|
209
|
+
}));
|
|
210
|
+
/**
|
|
211
|
+
* The client with batteries: environment-detected auth over `fetch`.
|
|
212
|
+
*
|
|
213
|
+
* The common wiring, in one import. Use {@link GitHubClient.layer} directly
|
|
214
|
+
* to supply your own credential or transport.
|
|
215
|
+
*/
|
|
216
|
+
static layerDefault = GitHubClient.layer.pipe(Layer.provide(Layer.mergeAll(GitHubAuth.layer, FetchHttpClient.layer)));
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
//#endregion
|
|
220
|
+
export { AuthenticationError, GitHubAuth, GitHubClient, GitHubRelease, GitHubTag, NetworkError, RateLimitError, ResponseParseError, mapHttpFailure };
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 C. Spencer Beggs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NodeRelease.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { isLtsPhase } from "./NodeSchedule.js";
|
|
2
|
+
import { SemVer } from "@effected/semver";
|
|
3
|
+
import { Option, Schema } from "effect";
|
|
4
|
+
|
|
5
|
+
//#region src/NodeRelease.ts
|
|
6
|
+
/**
|
|
7
|
+
* A published Node.js release.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* One Node.js release.
|
|
13
|
+
*
|
|
14
|
+
* Unlike its v3 ancestor this is an ordinary immutable value. v3's `NodeRelease`
|
|
15
|
+
* carried a `Ref<NodeSchedule>` so that `release.phase()` could reach the
|
|
16
|
+
* schedule, which meant every release held shared mutable state and could not be
|
|
17
|
+
* a data class at all. Phase is now a question you ask *with* a schedule rather
|
|
18
|
+
* than a property the release drags around.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { NodeRelease, NodeSchedule } from "@effected/runtimes";
|
|
23
|
+
* import { DateTime, Effect } from "effect";
|
|
24
|
+
*
|
|
25
|
+
* const program = Effect.gen(function* () {
|
|
26
|
+
* const schedule = yield* NodeSchedule.fromData({
|
|
27
|
+
* v20: { start: "2023-04-18", lts: "2023-10-24", end: "2026-04-30" },
|
|
28
|
+
* });
|
|
29
|
+
* const release = NodeRelease.make({
|
|
30
|
+
* version: yield* SemVer.parse("20.11.0"),
|
|
31
|
+
* npm: yield* SemVer.parse("10.2.4"),
|
|
32
|
+
* date: DateTime.makeUnsafe("2024-01-09"),
|
|
33
|
+
* });
|
|
34
|
+
* return release.isLts(schedule, DateTime.makeUnsafe("2024-06-01")); // true
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
var NodeRelease = class extends Schema.Class("NodeRelease")({
|
|
41
|
+
/** The released version. */
|
|
42
|
+
version: SemVer,
|
|
43
|
+
/** The npm version bundled with it. */
|
|
44
|
+
npm: SemVer,
|
|
45
|
+
/** When it was published. */
|
|
46
|
+
date: Schema.DateTimeUtc
|
|
47
|
+
}) {
|
|
48
|
+
/**
|
|
49
|
+
* This release's lifecycle phase at a point in time.
|
|
50
|
+
*
|
|
51
|
+
* The release line, not the major, is what the schedule is keyed by: `0.10`
|
|
52
|
+
* and `0.12` are separate lines with separate end dates, so asking by major
|
|
53
|
+
* alone would answer `0.12` with `0.8`'s schedule.
|
|
54
|
+
*
|
|
55
|
+
* `Option.none()` when the schedule does not cover this line, or when `now`
|
|
56
|
+
* predates the line's release.
|
|
57
|
+
*/
|
|
58
|
+
phase(schedule, now) {
|
|
59
|
+
return schedule.phaseFor(this.version, now);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Whether this release is in Long-Term Support at a point in time.
|
|
63
|
+
*/
|
|
64
|
+
isLts(schedule, now) {
|
|
65
|
+
return Option.match(this.phase(schedule, now), {
|
|
66
|
+
onNone: () => false,
|
|
67
|
+
onSome: isLtsPhase
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { NodeRelease };
|
package/NodeResolver.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { NodePhase, NodeSchedule } from "./NodeSchedule.js";
|
|
2
|
+
import { buildNodeReleases, fetchNodeReleases, fetchNodeSchedule } from "./internal/feeds.js";
|
|
3
|
+
import { make } from "./internal/releaseIndex.js";
|
|
4
|
+
import { Increments } from "./ResolvedVersions.js";
|
|
5
|
+
import { resolveWith } from "./internal/resolve.js";
|
|
6
|
+
import { populateAuto, populateFresh, populateOffline } from "./internal/strategy.js";
|
|
7
|
+
import { nodeDefaults, nodeScheduleDefaults } from "./internal/defaults/node.js";
|
|
8
|
+
import { Context, DateTime, Effect, Layer, Option, Ref, Schema } from "effect";
|
|
9
|
+
|
|
10
|
+
//#region src/NodeResolver.ts
|
|
11
|
+
/**
|
|
12
|
+
* How to resolve Node.js versions.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
const NodeResolverOptions = Schema.Struct({
|
|
17
|
+
/** The semver range to match. Defaults to `*`. */
|
|
18
|
+
range: Schema.optionalKey(Schema.String),
|
|
19
|
+
/** Lifecycle phases to accept. Defaults to `current` and `active-lts`. */
|
|
20
|
+
phases: Schema.optionalKey(Schema.Array(NodePhase)),
|
|
21
|
+
/** How to group matches. Defaults to `latest`. */
|
|
22
|
+
increments: Schema.optionalKey(Increments),
|
|
23
|
+
/** A range whose newest match becomes the `default` field. Defaults to the LTS pick. */
|
|
24
|
+
defaultVersion: Schema.optionalKey(Schema.String),
|
|
25
|
+
/** The moment to evaluate lifecycle phases at. Defaults to now, read from `Clock`. */
|
|
26
|
+
date: Schema.optionalKey(Schema.DateTimeUtc)
|
|
27
|
+
});
|
|
28
|
+
const DEFAULT_PHASES = ["current", "active-lts"];
|
|
29
|
+
/**
|
|
30
|
+
* The Node.js resolver.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { NodeResolver } from "@effected/runtimes";
|
|
35
|
+
* import { Effect } from "effect";
|
|
36
|
+
*
|
|
37
|
+
* const program = Effect.gen(function* () {
|
|
38
|
+
* const resolver = yield* NodeResolver;
|
|
39
|
+
* const result = yield* resolver.resolve({ range: ">=20", phases: ["active-lts"] });
|
|
40
|
+
* return result.latest;
|
|
41
|
+
* }).pipe(Effect.provide(NodeResolver.layerOffline));
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
var NodeResolver = class extends Context.Service()("@effected/runtimes/NodeResolver") {
|
|
47
|
+
/**
|
|
48
|
+
* Try the live feeds, fall back to the bundled snapshot.
|
|
49
|
+
*
|
|
50
|
+
* A fallback is recorded as `source: "cache"` and logged, so a caller can
|
|
51
|
+
* always tell a live answer from a snapshot.
|
|
52
|
+
*/
|
|
53
|
+
static layer = build(this, (index, live, offline) => populateAuto(index, "node", live, offline));
|
|
54
|
+
/**
|
|
55
|
+
* Live feeds or nothing. Fails with `FreshnessError` when they cannot be reached.
|
|
56
|
+
*/
|
|
57
|
+
static layerFresh = build(this, (index, live) => populateFresh(index, "node", live));
|
|
58
|
+
/**
|
|
59
|
+
* The bundled snapshot only. Performs no IO and requires nothing.
|
|
60
|
+
*/
|
|
61
|
+
static layerOffline = build(this, (index, _live, offline) => populateOffline(index, offline));
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Assemble a Node resolver layer around a strategy.
|
|
65
|
+
*
|
|
66
|
+
* The strategy's own error and requirement channels flow straight out into the
|
|
67
|
+
* layer's, so `layerOffline` genuinely requires nothing and `layer` genuinely
|
|
68
|
+
* cannot fail — no casts, and the types say what is true.
|
|
69
|
+
*
|
|
70
|
+
* The tag arrives as `this`: a static initializer runs while the module-scope
|
|
71
|
+
* `NodeResolver` binding is still in its temporal dead zone, so naming the class
|
|
72
|
+
* here throws at import time.
|
|
73
|
+
*/
|
|
74
|
+
function build(tag, strategy) {
|
|
75
|
+
return Layer.effect(tag, Effect.gen(function* () {
|
|
76
|
+
const index = yield* make();
|
|
77
|
+
const scheduleRef = yield* Ref.make(NodeSchedule.empty);
|
|
78
|
+
yield* strategy(index, Effect.gen(function* () {
|
|
79
|
+
const [raw, scheduleData] = yield* Effect.all([fetchNodeReleases(), fetchNodeSchedule()]);
|
|
80
|
+
yield* Ref.set(scheduleRef, yield* NodeSchedule.fromData(scheduleData));
|
|
81
|
+
return yield* buildNodeReleases(raw);
|
|
82
|
+
}).pipe(Effect.catchTag("InvalidVersionError", (cause) => Effect.die(cause))), Effect.gen(function* () {
|
|
83
|
+
yield* Ref.set(scheduleRef, yield* NodeSchedule.fromData(nodeScheduleDefaults));
|
|
84
|
+
return yield* buildNodeReleases(nodeDefaults);
|
|
85
|
+
}).pipe(Effect.orDie));
|
|
86
|
+
return { resolve: Effect.fn("NodeResolver.resolve")(function* (options) {
|
|
87
|
+
const range = options?.range ?? "*";
|
|
88
|
+
const phases = options?.phases ?? DEFAULT_PHASES;
|
|
89
|
+
const now = options?.date ?? (yield* DateTime.now);
|
|
90
|
+
const schedule = yield* Ref.get(scheduleRef);
|
|
91
|
+
yield* Effect.annotateCurrentSpan({
|
|
92
|
+
runtime: "node",
|
|
93
|
+
range
|
|
94
|
+
});
|
|
95
|
+
return yield* resolveWith({
|
|
96
|
+
index,
|
|
97
|
+
runtime: "node",
|
|
98
|
+
constraint: range,
|
|
99
|
+
increments: options?.increments ?? "latest",
|
|
100
|
+
defaultVersion: options?.defaultVersion,
|
|
101
|
+
phases,
|
|
102
|
+
defaultsToLts: true,
|
|
103
|
+
refine: (releases) => releases.filter((release) => Option.match(release.phase(schedule, now), {
|
|
104
|
+
onNone: () => false,
|
|
105
|
+
onSome: (phase) => phases.includes(phase)
|
|
106
|
+
})),
|
|
107
|
+
pickLts: (releases) => Option.fromUndefinedOr(releases.find((release) => release.isLts(schedule, now)))
|
|
108
|
+
});
|
|
109
|
+
}) };
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
//#endregion
|
|
114
|
+
export { NodeResolver, NodeResolverOptions };
|