runtime-resolver 0.3.22 → 1.0.1

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.
Files changed (68) hide show
  1. package/README.md +34 -35
  2. package/bin/runtime-resolver.js +12 -31
  3. package/command.js +120 -0
  4. package/layers.js +61 -0
  5. package/output.js +55 -0
  6. package/package.json +6 -18
  7. package/report.js +24 -0
  8. package/cli/commands/resolve.js +0 -242
  9. package/cli/schemas/json-schema.js +0 -12
  10. package/cli/schemas/response.js +0 -86
  11. package/data/bun-defaults.js +0 -850
  12. package/data/deno-defaults.js +0 -1538
  13. package/data/node-defaults.js +0 -4435
  14. package/errors/AuthenticationError.js +0 -35
  15. package/errors/CacheError.js +0 -32
  16. package/errors/FreshnessError.js +0 -38
  17. package/errors/InvalidInputError.js +0 -33
  18. package/errors/NetworkError.js +0 -34
  19. package/errors/ParseError.js +0 -33
  20. package/errors/RateLimitError.js +0 -37
  21. package/errors/VersionNotFoundError.js +0 -37
  22. package/index.d.ts +0 -2574
  23. package/index.js +0 -166
  24. package/layers/AutoBunCacheLive.js +0 -47
  25. package/layers/AutoDenoCacheLive.js +0 -47
  26. package/layers/AutoNodeCacheLive.js +0 -58
  27. package/layers/BunReleaseCacheLive.js +0 -25
  28. package/layers/BunResolverLive.js +0 -85
  29. package/layers/BunVersionFetcherLive.js +0 -55
  30. package/layers/DenoReleaseCacheLive.js +0 -25
  31. package/layers/DenoResolverLive.js +0 -84
  32. package/layers/DenoVersionFetcherLive.js +0 -51
  33. package/layers/FreshBunCacheLive.js +0 -60
  34. package/layers/FreshDenoCacheLive.js +0 -60
  35. package/layers/FreshNodeCacheLive.js +0 -55
  36. package/layers/GitHubAppAuth.js +0 -58
  37. package/layers/GitHubAutoAuth.js +0 -70
  38. package/layers/GitHubClientLive.js +0 -130
  39. package/layers/GitHubTokenAuth.js +0 -50
  40. package/layers/NodeReleaseCacheLive.js +0 -77
  41. package/layers/NodeResolverLive.js +0 -107
  42. package/layers/NodeScheduleFetcherLive.js +0 -37
  43. package/layers/NodeVersionFetcherLive.js +0 -55
  44. package/layers/OfflineBunCacheLive.js +0 -40
  45. package/layers/OfflineDenoCacheLive.js +0 -40
  46. package/layers/OfflineNodeCacheLive.js +0 -39
  47. package/layers/RuntimeCacheLive.js +0 -78
  48. package/lib/retry.js +0 -27
  49. package/lib/semver.js +0 -21
  50. package/schemas/bun-release.js +0 -63
  51. package/schemas/deno-release.js +0 -63
  52. package/schemas/github.js +0 -74
  53. package/schemas/node-release.js +0 -133
  54. package/schemas/node-schedule.js +0 -110
  55. package/schemas/node.js +0 -68
  56. package/services/BunReleaseCache.js +0 -33
  57. package/services/BunResolver.js +0 -36
  58. package/services/BunVersionFetcher.js +0 -41
  59. package/services/DenoReleaseCache.js +0 -33
  60. package/services/DenoResolver.js +0 -36
  61. package/services/DenoVersionFetcher.js +0 -41
  62. package/services/GitHubClient.js +0 -40
  63. package/services/NodeReleaseCache.js +0 -41
  64. package/services/NodeResolver.js +0 -44
  65. package/services/NodeScheduleFetcher.js +0 -38
  66. package/services/NodeVersionFetcher.js +0 -39
  67. package/services/OctokitInstance.js +0 -44
  68. package/tsdoc-metadata.json +0 -11
@@ -1,60 +0,0 @@
1
- import { BunRelease } from "../schemas/bun-release.js";
2
- import { BunReleaseCache } from "../services/BunReleaseCache.js";
3
- import { BunVersionFetcher } from "../services/BunVersionFetcher.js";
4
- import { BunReleaseCacheLive } from "./BunReleaseCacheLive.js";
5
- import { FreshnessError } from "../errors/FreshnessError.js";
6
- import { Effect, Layer } from "effect";
7
- import { SemVerParserLive, VersionCacheLive } from "semver-effect";
8
-
9
- //#region src/layers/FreshBunCacheLive.ts
10
- const freshSetup = Effect.gen(function* () {
11
- const cache = yield* BunReleaseCache;
12
- const { inputs } = yield* (yield* BunVersionFetcher).fetch().pipe(Effect.catchTags({
13
- AuthenticationError: (err) => Effect.fail(new FreshnessError({
14
- strategy: "api",
15
- message: `Fresh data required but authentication failed: ${err.message}`
16
- })),
17
- NetworkError: (err) => Effect.fail(new FreshnessError({
18
- strategy: "api",
19
- message: `Fresh data required but network unavailable: ${err.message}`
20
- })),
21
- ParseError: (err) => Effect.fail(new FreshnessError({
22
- strategy: "api",
23
- message: `Fresh data required but parse failed: ${err.message}`
24
- })),
25
- RateLimitError: (err) => Effect.fail(new FreshnessError({
26
- strategy: "api",
27
- message: `Fresh data required but rate limit exceeded: ${err.message}`
28
- }))
29
- }));
30
- const releases = yield* Effect.all(inputs.map((input) => BunRelease.fromInput(input)), { concurrency: "unbounded" }).pipe(Effect.orElseSucceed(() => []));
31
- yield* cache.load(releases);
32
- });
33
- const SemVerLayer = VersionCacheLive.pipe(Layer.provide(SemVerParserLive));
34
- const BaseCacheLayer = BunReleaseCacheLive.pipe(Layer.provide(SemVerLayer));
35
- /**
36
- * Provides the {@link BunReleaseCache} service using the "Fresh" cache strategy.
37
- *
38
- * Requires live release data from the GitHub API via {@link BunVersionFetcher}.
39
- * If the fetch fails for any reason — authentication errors, network errors,
40
- * parse errors, or rate-limit errors — the layer fails with a `FreshnessError`
41
- * rather than falling back to stale data.
42
- *
43
- * Use this strategy in contexts where working with outdated version data would
44
- * be incorrect or misleading, such as CI pipelines or tooling that must reflect
45
- * the true current state of Bun releases.
46
- *
47
- * The three Bun cache strategy layers are:
48
- * - {@link AutoBunCacheLive} — tries API first, falls back to bundled defaults on any error
49
- * - `FreshBunCacheLive` — requires live API data, fails with `FreshnessError` if unavailable
50
- * - {@link OfflineBunCacheLive} — uses only bundled defaults, no network I/O
51
- *
52
- * @see {@link BunReleaseCache}
53
- * @see {@link AutoBunCacheLive}
54
- * @see {@link OfflineBunCacheLive}
55
- * @public
56
- */
57
- const FreshBunCacheLive = BaseCacheLayer.pipe(Layer.tap((ctx) => freshSetup.pipe(Effect.provide(ctx))));
58
-
59
- //#endregion
60
- export { FreshBunCacheLive };
@@ -1,60 +0,0 @@
1
- import { DenoRelease } from "../schemas/deno-release.js";
2
- import { DenoReleaseCache } from "../services/DenoReleaseCache.js";
3
- import { DenoVersionFetcher } from "../services/DenoVersionFetcher.js";
4
- import { DenoReleaseCacheLive } from "./DenoReleaseCacheLive.js";
5
- import { FreshnessError } from "../errors/FreshnessError.js";
6
- import { Effect, Layer } from "effect";
7
- import { SemVerParserLive, VersionCacheLive } from "semver-effect";
8
-
9
- //#region src/layers/FreshDenoCacheLive.ts
10
- const freshSetup = Effect.gen(function* () {
11
- const cache = yield* DenoReleaseCache;
12
- const { inputs } = yield* (yield* DenoVersionFetcher).fetch().pipe(Effect.catchTags({
13
- AuthenticationError: (err) => Effect.fail(new FreshnessError({
14
- strategy: "api",
15
- message: `Fresh data required but authentication failed: ${err.message}`
16
- })),
17
- NetworkError: (err) => Effect.fail(new FreshnessError({
18
- strategy: "api",
19
- message: `Fresh data required but network unavailable: ${err.message}`
20
- })),
21
- ParseError: (err) => Effect.fail(new FreshnessError({
22
- strategy: "api",
23
- message: `Fresh data required but parse failed: ${err.message}`
24
- })),
25
- RateLimitError: (err) => Effect.fail(new FreshnessError({
26
- strategy: "api",
27
- message: `Fresh data required but rate limit exceeded: ${err.message}`
28
- }))
29
- }));
30
- const releases = yield* Effect.all(inputs.map((input) => DenoRelease.fromInput(input)), { concurrency: "unbounded" }).pipe(Effect.orElseSucceed(() => []));
31
- yield* cache.load(releases);
32
- });
33
- const SemVerLayer = VersionCacheLive.pipe(Layer.provide(SemVerParserLive));
34
- const BaseCacheLayer = DenoReleaseCacheLive.pipe(Layer.provide(SemVerLayer));
35
- /**
36
- * Provides the {@link DenoReleaseCache} service using the "Fresh" cache strategy.
37
- *
38
- * Requires live release data from the GitHub API via {@link DenoVersionFetcher}.
39
- * If the fetch fails for any reason — authentication errors, network errors,
40
- * parse errors, or rate-limit errors — the layer fails with a `FreshnessError`
41
- * rather than falling back to stale data.
42
- *
43
- * Use this strategy in contexts where working with outdated version data would
44
- * be incorrect or misleading, such as CI pipelines or tooling that must reflect
45
- * the true current state of Deno releases.
46
- *
47
- * The three Deno cache strategy layers are:
48
- * - {@link AutoDenoCacheLive} — tries API first, falls back to bundled defaults on any error
49
- * - `FreshDenoCacheLive` — requires live API data, fails with `FreshnessError` if unavailable
50
- * - {@link OfflineDenoCacheLive} — uses only bundled defaults, no network I/O
51
- *
52
- * @see {@link DenoReleaseCache}
53
- * @see {@link AutoDenoCacheLive}
54
- * @see {@link OfflineDenoCacheLive}
55
- * @public
56
- */
57
- const FreshDenoCacheLive = BaseCacheLayer.pipe(Layer.tap((ctx) => freshSetup.pipe(Effect.provide(ctx))));
58
-
59
- //#endregion
60
- export { FreshDenoCacheLive };
@@ -1,55 +0,0 @@
1
- import { NodeReleaseCache } from "../services/NodeReleaseCache.js";
2
- import { NodeScheduleFetcher } from "../services/NodeScheduleFetcher.js";
3
- import { NodeVersionFetcher } from "../services/NodeVersionFetcher.js";
4
- import { NodeReleaseCacheLive } from "./NodeReleaseCacheLive.js";
5
- import { FreshnessError } from "../errors/FreshnessError.js";
6
- import { Effect, Layer } from "effect";
7
- import { SemVerParserLive, VersionCacheLive } from "semver-effect";
8
-
9
- //#region src/layers/FreshNodeCacheLive.ts
10
- const freshSetup = Effect.gen(function* () {
11
- const cache = yield* NodeReleaseCache;
12
- const versionFetcher = yield* NodeVersionFetcher;
13
- const scheduleFetcher = yield* NodeScheduleFetcher;
14
- const [fetchResult, scheduleData] = yield* Effect.all([versionFetcher.fetch(), scheduleFetcher.fetch()]).pipe(Effect.catchTags({
15
- NetworkError: (err) => Effect.fail(new FreshnessError({
16
- strategy: "api",
17
- message: `Fresh data required but network unavailable: ${err.message}`
18
- })),
19
- ParseError: (err) => Effect.fail(new FreshnessError({
20
- strategy: "api",
21
- message: `Fresh data required but response could not be parsed: ${err.message}`
22
- }))
23
- }));
24
- yield* cache.updateSchedule(scheduleData);
25
- yield* cache.loadFromInputs(fetchResult.inputs);
26
- });
27
- const SemVerLayer = VersionCacheLive.pipe(Layer.provide(SemVerParserLive));
28
- const BaseCacheLayer = NodeReleaseCacheLive.pipe(Layer.provide(SemVerLayer));
29
- /**
30
- * Provides the {@link NodeReleaseCache} service using the "Fresh" cache strategy.
31
- *
32
- * Requires live release data from `nodejs.org/dist/index.json` via
33
- * {@link NodeVersionFetcher} and the release schedule from the `nodejs/Release`
34
- * repository via {@link NodeScheduleFetcher}. If either fetch fails — due to
35
- * network errors or parse errors — the layer fails with a `FreshnessError`
36
- * rather than falling back to stale data.
37
- *
38
- * Use this strategy in contexts where working with outdated version data would
39
- * be incorrect or misleading, such as CI pipelines or tooling that must reflect
40
- * the true current state of Node.js releases and LTS schedule.
41
- *
42
- * The three Node cache strategy layers are:
43
- * - {@link AutoNodeCacheLive} — tries API first, falls back to bundled defaults on any error
44
- * - `FreshNodeCacheLive` — requires live API data, fails with `FreshnessError` if unavailable
45
- * - {@link OfflineNodeCacheLive} — uses only bundled defaults, no network I/O
46
- *
47
- * @see {@link NodeReleaseCache}
48
- * @see {@link AutoNodeCacheLive}
49
- * @see {@link OfflineNodeCacheLive}
50
- * @public
51
- */
52
- const FreshNodeCacheLive = BaseCacheLayer.pipe(Layer.tap((ctx) => freshSetup.pipe(Effect.provide(ctx))));
53
-
54
- //#endregion
55
- export { FreshNodeCacheLive };
@@ -1,58 +0,0 @@
1
- import { OctokitInstance } from "../services/OctokitInstance.js";
2
- import { AuthenticationError } from "../errors/AuthenticationError.js";
3
- import { Effect, Layer } from "effect";
4
- import { Octokit } from "octokit";
5
- import { createAppAuth } from "@octokit/auth-app";
6
-
7
- //#region src/layers/GitHubAppAuth.ts
8
- const resolveInstallationId = async (auth, installationId) => {
9
- if (installationId) return installationId;
10
- const { token: jwt } = await auth({ type: "app" });
11
- const response = await fetch("https://api.github.com/app/installations?per_page=100", { headers: {
12
- Authorization: `Bearer ${jwt}`,
13
- Accept: "application/vnd.github+json"
14
- } });
15
- if (!response.ok) throw new Error(`Failed to list installations: ${response.status}`);
16
- const installations = await response.json();
17
- if (installations.length === 0) throw new Error("No installations found for this GitHub App");
18
- return installations[0].id;
19
- };
20
- /**
21
- * Provides an {@link OctokitInstance} authenticated as a GitHub App installation.
22
- *
23
- * Accepts a {@link GitHubAppAuthConfig} and uses `@octokit/auth-app` to obtain
24
- * an installation access token. If `installationId` is omitted, the first
25
- * installation returned by the GitHub API is used automatically (suitable for
26
- * apps with a single installation). If authentication fails for any reason the
27
- * layer fails with an `AuthenticationError`.
28
- *
29
- * Use this auth method when your integration runs as a GitHub App rather than
30
- * as an individual user or a CI token.
31
- *
32
- * @param config - App credentials and optional installation ID.
33
- *
34
- * @see {@link GitHubAppAuthConfig}
35
- * @see {@link OctokitInstance}
36
- * @see {@link GitHubAutoAuth}
37
- * @see {@link GitHubTokenAuth}
38
- * @public
39
- */
40
- const GitHubAppAuth = (config) => Layer.effect(OctokitInstance, Effect.tryPromise({
41
- try: async () => {
42
- const auth = createAppAuth({
43
- appId: config.appId,
44
- privateKey: config.privateKey
45
- });
46
- return new Octokit({ auth: (await auth({
47
- type: "installation",
48
- installationId: await resolveInstallationId(auth, config.installationId)
49
- })).token });
50
- },
51
- catch: (error) => new AuthenticationError({
52
- method: "app",
53
- message: error instanceof Error ? error.message : String(error)
54
- })
55
- }));
56
-
57
- //#endregion
58
- export { GitHubAppAuth };
@@ -1,70 +0,0 @@
1
- import { OctokitInstance } from "../services/OctokitInstance.js";
2
- import { GitHubAppAuth } from "./GitHubAppAuth.js";
3
- import { Effect, Layer } from "effect";
4
- import { Octokit } from "octokit";
5
-
6
- //#region src/layers/GitHubAutoAuth.ts
7
- /**
8
- * Provides an {@link OctokitInstance} by auto-detecting the available
9
- * authentication credentials from environment variables at layer construction
10
- * time.
11
- *
12
- * Credentials are evaluated in the following priority order:
13
- * 1. **GitHub App** — when both `GITHUB_APP_ID` and `GITHUB_APP_PRIVATE_KEY`
14
- * are set, authenticates as a GitHub App installation via {@link GitHubAppAuth}.
15
- * `GITHUB_APP_INSTALLATION_ID` is optional; if absent the first installation
16
- * is used automatically.
17
- * 2. **Personal Access Token** — when `GITHUB_PERSONAL_ACCESS_TOKEN` is set,
18
- * authenticates with that token.
19
- * 3. **`GITHUB_TOKEN`** — when `GITHUB_TOKEN` is set (e.g., the default token
20
- * injected in GitHub Actions), authenticates with that token.
21
- * 4. **Unauthenticated** — falls back to an unauthenticated Octokit instance
22
- * when no credentials are found (lower rate limits apply).
23
- *
24
- * If both App and token credentials are present, App auth takes precedence and
25
- * a warning is logged. This layer fails with `AuthenticationError` only when
26
- * App credentials are present but the App authentication itself fails.
27
- *
28
- * Use this layer as the default auth strategy in most applications. Switch to
29
- * {@link GitHubTokenAuth} or {@link GitHubAppAuth} when you need explicit control
30
- * over which credential source is used.
31
- *
32
- * @example
33
- * ```ts
34
- * import { GitHubClientLive, GitHubAutoAuth } from "runtime-resolver";
35
- * import { Layer } from "effect";
36
- *
37
- * const GitHubLayer = GitHubClientLive.pipe(Layer.provide(GitHubAutoAuth));
38
- * ```
39
- *
40
- * @see {@link OctokitInstance}
41
- * @see {@link GitHubTokenAuth}
42
- * @see {@link GitHubAppAuth}
43
- * @public
44
- */
45
- const GitHubAutoAuth = Layer.effect(OctokitInstance, Effect.gen(function* () {
46
- const appId = process.env.GITHUB_APP_ID;
47
- const privateKey = process.env.GITHUB_APP_PRIVATE_KEY;
48
- const installationId = process.env.GITHUB_APP_INSTALLATION_ID;
49
- const pat = process.env.GITHUB_PERSONAL_ACCESS_TOKEN;
50
- const token = process.env.GITHUB_TOKEN;
51
- const hasApp = appId && privateKey;
52
- if (hasApp && (pat || token)) {
53
- const tokenSource = pat ? "GITHUB_PERSONAL_ACCESS_TOKEN" : "GITHUB_TOKEN";
54
- yield* Effect.logWarning(`Multiple GitHub credential sources found. Using GitHub App authentication (from GITHUB_APP_ID). Ignoring ${tokenSource}.`);
55
- }
56
- if (hasApp) {
57
- const appLayer = GitHubAppAuth({
58
- appId,
59
- privateKey,
60
- ...installationId ? { installationId: Number(installationId) } : {}
61
- });
62
- return yield* Effect.provide(OctokitInstance, appLayer);
63
- }
64
- if (pat) return new Octokit({ auth: pat });
65
- if (token) return new Octokit({ auth: token });
66
- return new Octokit();
67
- }));
68
-
69
- //#endregion
70
- export { GitHubAutoAuth };
@@ -1,130 +0,0 @@
1
- import { GitHubClient } from "../services/GitHubClient.js";
2
- import { OctokitInstance } from "../services/OctokitInstance.js";
3
- import { AuthenticationError } from "../errors/AuthenticationError.js";
4
- import { NetworkError } from "../errors/NetworkError.js";
5
- import { ParseError } from "../errors/ParseError.js";
6
- import { RateLimitError } from "../errors/RateLimitError.js";
7
- import { GitHubReleaseList, GitHubTagList } from "../schemas/github.js";
8
- import { Effect, Layer, Schema } from "effect";
9
-
10
- //#region src/layers/GitHubClientLive.ts
11
- const mapOctokitError = (error, url) => {
12
- const err = error;
13
- if (err.status === 401) return new AuthenticationError({
14
- method: "token",
15
- message: `GitHub API authentication failed for ${url}`
16
- });
17
- if (err.status === 403 || err.status === 429) {
18
- const headers = err.response?.headers ?? {};
19
- const retryAfterStr = headers["retry-after"];
20
- return new RateLimitError({
21
- ...retryAfterStr ? { retryAfter: Number.parseInt(retryAfterStr, 10) } : {},
22
- limit: headers["x-ratelimit-limit"] ? Number.parseInt(headers["x-ratelimit-limit"], 10) : 0,
23
- remaining: headers["x-ratelimit-remaining"] ? Number.parseInt(headers["x-ratelimit-remaining"], 10) : 0,
24
- message: `GitHub API rate limit exceeded for ${url}`
25
- });
26
- }
27
- return new NetworkError({
28
- url,
29
- ...err.status !== void 0 ? { status: err.status } : {},
30
- message: error instanceof Error ? error.message : String(error)
31
- });
32
- };
33
- const decodeTagList = Schema.decodeUnknown(GitHubTagList);
34
- const decodeReleaseList = Schema.decodeUnknown(GitHubReleaseList);
35
- /**
36
- * Provides the {@link GitHubClient} service backed by an {@link OctokitInstance}.
37
- *
38
- * This layer wraps an Octokit instance and exposes a typed, Effect-native API
39
- * for listing GitHub releases, listing tags, and fetching arbitrary JSON from
40
- * URLs. HTTP errors are mapped to typed domain errors (`NetworkError`,
41
- * `RateLimitError`, `AuthenticationError`) so they can be handled precisely in
42
- * calling code.
43
- *
44
- * Pair this layer with one of the auth layers to form a complete GitHub
45
- * integration stack:
46
- * - {@link GitHubAutoAuth} — auto-detects auth from environment variables
47
- * - {@link GitHubTokenAuth} — authenticates using a personal access token
48
- * - {@link GitHubAppAuth} — authenticates as a GitHub App installation
49
- *
50
- * @see {@link GitHubClient}
51
- * @see {@link OctokitInstance}
52
- * @see {@link GitHubAutoAuth}
53
- * @public
54
- */
55
- const GitHubClientLive = Layer.effect(GitHubClient, Effect.gen(function* () {
56
- const octokit = yield* OctokitInstance;
57
- return {
58
- listTags: (owner, repo, options) => Effect.gen(function* () {
59
- const perPage = options?.perPage ?? 100;
60
- const maxPages = options?.pages ?? Number.POSITIVE_INFINITY;
61
- const allTags = [];
62
- for (let page = 1; page <= maxPages; page++) {
63
- const response = yield* Effect.tryPromise({
64
- try: () => octokit.rest.repos.listTags({
65
- owner,
66
- repo,
67
- per_page: perPage,
68
- page
69
- }),
70
- catch: (error) => mapOctokitError(error, `repos/${owner}/${repo}/tags`)
71
- });
72
- const tags = yield* decodeTagList(response.data).pipe(Effect.mapError((e) => new ParseError({
73
- source: `repos/${owner}/${repo}/tags`,
74
- message: `Schema validation failed: ${e.message}`
75
- })));
76
- allTags.push(...tags);
77
- if (response.data.length < perPage) break;
78
- }
79
- return allTags;
80
- }),
81
- listReleases: (owner, repo, options) => Effect.gen(function* () {
82
- const perPage = options?.perPage ?? 100;
83
- const maxPages = options?.pages ?? Number.POSITIVE_INFINITY;
84
- const allReleases = [];
85
- for (let page = 1; page <= maxPages; page++) {
86
- const response = yield* Effect.tryPromise({
87
- try: () => octokit.rest.repos.listReleases({
88
- owner,
89
- repo,
90
- per_page: perPage,
91
- page
92
- }),
93
- catch: (error) => mapOctokitError(error, `repos/${owner}/${repo}/releases`)
94
- });
95
- const releases = yield* decodeReleaseList(response.data).pipe(Effect.mapError((e) => new ParseError({
96
- source: `repos/${owner}/${repo}/releases`,
97
- message: `Schema validation failed: ${e.message}`
98
- })));
99
- allReleases.push(...releases);
100
- if (response.data.length < perPage) break;
101
- }
102
- return allReleases;
103
- }),
104
- getJson: (url, schema) => Effect.gen(function* () {
105
- const response = yield* Effect.tryPromise({
106
- try: () => fetch(url),
107
- catch: (error) => new NetworkError({
108
- url,
109
- message: error instanceof Error ? error.message : String(error)
110
- })
111
- });
112
- if (!response.ok) yield* Effect.fail(new NetworkError({
113
- url,
114
- status: response.status,
115
- message: `HTTP ${response.status}: ${response.statusText}`
116
- }));
117
- const json = yield* Effect.tryPromise({
118
- try: () => response.json(),
119
- catch: () => new ParseError({
120
- source: url,
121
- message: "Failed to parse JSON response"
122
- })
123
- });
124
- return yield* schema.decode(json);
125
- })
126
- };
127
- }));
128
-
129
- //#endregion
130
- export { GitHubClientLive };
@@ -1,50 +0,0 @@
1
- import { OctokitInstance } from "../services/OctokitInstance.js";
2
- import { Effect, Layer } from "effect";
3
- import { Octokit } from "octokit";
4
-
5
- //#region src/layers/GitHubTokenAuth.ts
6
- const resolveToken = Effect.sync(() => process.env.GITHUB_PERSONAL_ACCESS_TOKEN || process.env.GITHUB_TOKEN || "");
7
- /**
8
- * Provides an {@link OctokitInstance} authenticated with a GitHub personal
9
- * access token read from the environment at layer construction time.
10
- *
11
- * The token is resolved by checking, in order:
12
- * 1. `GITHUB_PERSONAL_ACCESS_TOKEN` environment variable
13
- * 2. `GITHUB_TOKEN` environment variable
14
- *
15
- * If neither variable is set the layer constructs an unauthenticated Octokit
16
- * instance (lower rate limits apply). This layer never fails.
17
- *
18
- * Use {@link GitHubTokenAuthFromToken} when you have the token value available
19
- * programmatically at construction time.
20
- *
21
- * @see {@link OctokitInstance}
22
- * @see {@link GitHubTokenAuthFromToken}
23
- * @see {@link GitHubAutoAuth}
24
- * @see {@link GitHubAppAuth}
25
- * @public
26
- */
27
- const GitHubTokenAuth = Layer.effect(OctokitInstance, Effect.gen(function* () {
28
- const token = yield* resolveToken;
29
- return new Octokit(token ? { auth: token } : {});
30
- }));
31
- /**
32
- * Provides an {@link OctokitInstance} authenticated with the given personal
33
- * access token string.
34
- *
35
- * Use this variant when the token is available as a value in your program
36
- * rather than read from an environment variable. The resulting layer never
37
- * fails.
38
- *
39
- * @param token - A GitHub personal access token string.
40
- *
41
- * @see {@link OctokitInstance}
42
- * @see {@link GitHubTokenAuth}
43
- * @see {@link GitHubAutoAuth}
44
- * @see {@link GitHubAppAuth}
45
- * @public
46
- */
47
- const GitHubTokenAuthFromToken = (token) => Layer.succeed(OctokitInstance, new Octokit({ auth: token }));
48
-
49
- //#endregion
50
- export { GitHubTokenAuth, GitHubTokenAuthFromToken };
@@ -1,77 +0,0 @@
1
- import { createRuntimeCache } from "./RuntimeCacheLive.js";
2
- import { NodeReleaseCache } from "../services/NodeReleaseCache.js";
3
- import { NodeRelease } from "../schemas/node-release.js";
4
- import { NodeSchedule } from "../schemas/node-schedule.js";
5
- import { Effect, Layer, Ref } from "effect";
6
-
7
- //#region src/layers/NodeReleaseCacheLive.ts
8
- /**
9
- * Low-level layer that constructs the {@link NodeReleaseCache} service backed by
10
- * a `SemVerVersionCache` instance from `semver-effect`.
11
- *
12
- * This layer is more complex than the Bun and Deno equivalents because it manages
13
- * additional LTS schedule state via an internal `Ref`. The schedule is stored
14
- * separately from the version list so that calling `updateSchedule` can
15
- * transparently rebuild all release objects with the latest phase information
16
- * without reloading data from the network.
17
- *
18
- * This layer wires up the cache storage but does not populate it with any
19
- * release data. Callers are responsible for calling `updateSchedule` and
20
- * `loadFromInputs` after construction. In normal usage you should prefer the
21
- * higher-level cache strategy layers instead of using this layer directly:
22
- * - {@link AutoNodeCacheLive} — API with fallback to bundled defaults
23
- * - {@link FreshNodeCacheLive} — API only, fails if unavailable
24
- * - {@link OfflineNodeCacheLive} — bundled defaults only
25
- *
26
- * @see {@link NodeReleaseCache}
27
- * @see {@link createRuntimeCache}
28
- * @internal
29
- */
30
- const NodeReleaseCacheLive = Layer.effect(NodeReleaseCache, Effect.gen(function* () {
31
- const scheduleRef = yield* Ref.make(NodeSchedule.fromData({}));
32
- const inner = yield* createRuntimeCache();
33
- let currentInputs = [];
34
- const buildAndLoad = (inputs) => Effect.gen(function* () {
35
- const releases = [];
36
- for (const input of inputs) {
37
- const release = yield* NodeRelease.fromInput(input, scheduleRef).pipe(Effect.catchAll(() => Effect.succeed(null)));
38
- if (release) releases.push(release);
39
- }
40
- yield* inner.load(releases);
41
- });
42
- return {
43
- load: (releases) => inner.load(releases),
44
- resolve: (range) => inner.resolve(range),
45
- releases: () => inner.releases(),
46
- filter: (range) => inner.filter(range),
47
- latest: () => inner.latest(),
48
- latestByMajor: () => inner.latestByMajor(),
49
- latestByMinor: () => inner.latestByMinor(),
50
- updateSchedule: (data) => Effect.gen(function* () {
51
- yield* Ref.set(scheduleRef, NodeSchedule.fromData(data));
52
- if (currentInputs.length > 0) yield* buildAndLoad(currentInputs);
53
- }),
54
- loadFromInputs: (inputs) => Effect.gen(function* () {
55
- currentInputs = inputs;
56
- yield* buildAndLoad(inputs);
57
- }),
58
- ltsReleases: (now) => Effect.gen(function* () {
59
- const all = yield* inner.releases();
60
- const results = [];
61
- for (const r of all) {
62
- const phase = yield* r.phase(now);
63
- if (phase === "active-lts" || phase === "maintenance-lts") results.push(r);
64
- }
65
- return results;
66
- }),
67
- currentReleases: (now) => Effect.gen(function* () {
68
- const all = yield* inner.releases();
69
- const results = [];
70
- for (const r of all) if ((yield* r.phase(now)) === "current") results.push(r);
71
- return results;
72
- })
73
- };
74
- }));
75
-
76
- //#endregion
77
- export { NodeReleaseCacheLive };
@@ -1,107 +0,0 @@
1
- import { NodeReleaseCache } from "../services/NodeReleaseCache.js";
2
- import { VersionNotFoundError } from "../errors/VersionNotFoundError.js";
3
- import { NodeResolver } from "../services/NodeResolver.js";
4
- import { DateTime, Effect, Layer } from "effect";
5
- import { SemVer } from "semver-effect";
6
-
7
- //#region src/layers/NodeResolverLive.ts
8
- /**
9
- * Provides the {@link NodeResolver} service backed by a {@link NodeReleaseCache}.
10
- *
11
- * This layer composes with any of the three Node cache strategy layers to form
12
- * a complete resolver stack. In addition to semver range filtering and increment
13
- * grouping, it supports filtering by Node.js release phase (e.g., `"current"`,
14
- * `"active-lts"`, `"maintenance-lts"`, `"end-of-life"`) and automatically
15
- * determines the current LTS version from the loaded schedule data.
16
- *
17
- * @example
18
- * ```ts
19
- * import {
20
- * NodeResolverLive, AutoNodeCacheLive,
21
- * NodeVersionFetcherLive, NodeScheduleFetcherLive,
22
- * GitHubClientLive, GitHubAutoAuth,
23
- * } from "runtime-resolver";
24
- * import { NodeResolver } from "runtime-resolver";
25
- * import { Effect, Layer } from "effect";
26
- *
27
- * const GitHubLayer = GitHubClientLive.pipe(Layer.provide(GitHubAutoAuth));
28
- * const FetchersLayer = Layer.merge(
29
- * NodeVersionFetcherLive.pipe(Layer.provide(GitHubLayer)),
30
- * NodeScheduleFetcherLive.pipe(Layer.provide(GitHubLayer)),
31
- * );
32
- * const CacheLayer = AutoNodeCacheLive.pipe(Layer.provide(FetchersLayer));
33
- * const ResolverLayer = NodeResolverLive.pipe(Layer.provide(CacheLayer));
34
- *
35
- * const program = Effect.gen(function* () {
36
- * const resolver = yield* NodeResolver;
37
- * // Resolve only active-LTS and maintenance-LTS releases in the ^20 range
38
- * const result = yield* resolver.resolve({
39
- * semverRange: "^20.0.0",
40
- * phases: ["active-lts", "maintenance-lts"],
41
- * });
42
- * console.log(result.lts);
43
- * });
44
- *
45
- * Effect.runPromise(program.pipe(Effect.provide(ResolverLayer)));
46
- * ```
47
- *
48
- * @see {@link NodeResolver}
49
- * @see {@link NodeReleaseCache}
50
- * @see {@link AutoNodeCacheLive}
51
- * @see {@link FreshNodeCacheLive}
52
- * @see {@link OfflineNodeCacheLive}
53
- * @public
54
- */
55
- const NodeResolverLive = Layer.effect(NodeResolver, Effect.gen(function* () {
56
- const cache = yield* NodeReleaseCache;
57
- return { resolve: (options) => Effect.gen(function* () {
58
- const semverRange = options?.semverRange ?? "*";
59
- const phases = options?.phases ?? ["current", "active-lts"];
60
- const increments = options?.increments ?? "latest";
61
- const now = options?.date ? DateTime.unsafeMake(options.date) : DateTime.unsafeMake(/* @__PURE__ */ new Date());
62
- const matching = yield* cache.filter(semverRange).pipe(Effect.catchAll(() => Effect.succeed([])));
63
- const phaseFiltered = [];
64
- for (const r of matching) {
65
- const phase = yield* r.phase(now);
66
- if (phase && phases.includes(phase)) phaseFiltered.push(r);
67
- }
68
- let resultReleases;
69
- if (increments === "latest") {
70
- const groups = /* @__PURE__ */ new Map();
71
- for (const r of phaseFiltered) {
72
- const existing = groups.get(r.version.major);
73
- if (!existing || SemVer.gt(r.version, existing.version)) groups.set(r.version.major, r);
74
- }
75
- resultReleases = [...groups.values()];
76
- } else if (increments === "minor") {
77
- const groups = /* @__PURE__ */ new Map();
78
- for (const r of phaseFiltered) {
79
- const key = `${r.version.major}.${r.version.minor}`;
80
- const existing = groups.get(key);
81
- if (!existing || SemVer.gt(r.version, existing.version)) groups.set(key, r);
82
- }
83
- resultReleases = [...groups.values()];
84
- } else resultReleases = phaseFiltered;
85
- if (resultReleases.length === 0) return yield* Effect.fail(new VersionNotFoundError({
86
- runtime: "node",
87
- constraint: semverRange,
88
- message: `No Node.js versions found matching "${semverRange}" with phases [${phases.join(", ")}]`
89
- }));
90
- const versions = SemVer.rsort(resultReleases.map((r) => r.version)).map((v) => resultReleases.find((r) => SemVer.equal(r.version, v))).filter((r) => r !== void 0).map((r) => r.version.toString());
91
- const latest = versions[0];
92
- const ltsVersions = (yield* cache.ltsReleases(now)).filter((r) => versions.includes(r.version.toString())).map((r) => r.version);
93
- const lts = ltsVersions.length > 0 ? SemVer.rsort(ltsVersions)[0].toString() : void 0;
94
- let resolvedDefault;
95
- if (options?.defaultVersion) resolvedDefault = yield* cache.resolve(options.defaultVersion).pipe(Effect.map((r) => r.version.toString()), Effect.catchAll(() => Effect.succeed(void 0)));
96
- return {
97
- source: "api",
98
- versions,
99
- latest,
100
- ...lts ? { lts } : {},
101
- ...resolvedDefault ? { default: resolvedDefault } : { ...lts ? { default: lts } : {} }
102
- };
103
- }) };
104
- }));
105
-
106
- //#endregion
107
- export { NodeResolverLive };