@lbdudc/linea-git 0.0.0-stage → 0.1.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 (152) hide show
  1. package/README.md +47 -2
  2. package/dist/access.d.ts +18 -0
  3. package/dist/access.js +18 -0
  4. package/dist/access.js.map +1 -0
  5. package/dist/auth.d.ts +11 -0
  6. package/dist/auth.js +16 -0
  7. package/dist/auth.js.map +1 -0
  8. package/dist/changelog/generate.d.ts +18 -0
  9. package/dist/changelog/generate.js +166 -0
  10. package/dist/changelog/generate.js.map +1 -0
  11. package/dist/changelog/index.d.ts +5 -0
  12. package/dist/changelog/index.js +3 -0
  13. package/dist/changelog/index.js.map +1 -0
  14. package/dist/changelog/parse.d.ts +43 -0
  15. package/dist/changelog/parse.js +91 -0
  16. package/dist/changelog/parse.js.map +1 -0
  17. package/dist/changelog/types.d.ts +85 -0
  18. package/dist/changelog/types.js +2 -0
  19. package/dist/changelog/types.js.map +1 -0
  20. package/dist/checkout/credential.d.ts +14 -0
  21. package/dist/checkout/credential.js +29 -0
  22. package/dist/checkout/credential.js.map +1 -0
  23. package/dist/checkout/git.d.ts +78 -0
  24. package/dist/checkout/git.js +191 -0
  25. package/dist/checkout/git.js.map +1 -0
  26. package/dist/checkout/index.d.ts +3 -0
  27. package/dist/checkout/index.js +4 -0
  28. package/dist/checkout/index.js.map +1 -0
  29. package/dist/checkout/sync.d.ts +156 -0
  30. package/dist/checkout/sync.js +211 -0
  31. package/dist/checkout/sync.js.map +1 -0
  32. package/dist/closing.d.ts +1 -0
  33. package/dist/closing.js +14 -0
  34. package/dist/closing.js.map +1 -0
  35. package/dist/config.d.ts +53 -0
  36. package/dist/config.js +40 -0
  37. package/dist/config.js.map +1 -0
  38. package/dist/deletion.d.ts +19 -0
  39. package/dist/deletion.js +27 -0
  40. package/dist/deletion.js.map +1 -0
  41. package/dist/errors.d.ts +26 -0
  42. package/dist/errors.js +47 -0
  43. package/dist/errors.js.map +1 -0
  44. package/dist/factory.d.ts +20 -0
  45. package/dist/factory.js +46 -0
  46. package/dist/factory.js.map +1 -0
  47. package/dist/github/client.d.ts +44 -0
  48. package/dist/github/client.js +145 -0
  49. package/dist/github/client.js.map +1 -0
  50. package/dist/github/config.d.ts +24 -0
  51. package/dist/github/config.js +11 -0
  52. package/dist/github/config.js.map +1 -0
  53. package/dist/github/provider.d.ts +510 -0
  54. package/dist/github/provider.js +1009 -0
  55. package/dist/github/provider.js.map +1 -0
  56. package/dist/gitlab/client.d.ts +50 -0
  57. package/dist/gitlab/client.js +228 -0
  58. package/dist/gitlab/client.js.map +1 -0
  59. package/dist/gitlab/provider.d.ts +487 -0
  60. package/dist/gitlab/provider.js +719 -0
  61. package/dist/gitlab/provider.js.map +1 -0
  62. package/dist/host.d.ts +27 -0
  63. package/dist/host.js +45 -0
  64. package/dist/host.js.map +1 -0
  65. package/dist/index.d.ts +46 -0
  66. package/dist/index.js +31 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/local/diff.d.ts +3 -0
  69. package/dist/local/diff.js +43 -0
  70. package/dist/local/diff.js.map +1 -0
  71. package/dist/local/git.d.ts +24 -0
  72. package/dist/local/git.js +51 -0
  73. package/dist/local/git.js.map +1 -0
  74. package/dist/local/health.d.ts +36 -0
  75. package/dist/local/health.js +57 -0
  76. package/dist/local/health.js.map +1 -0
  77. package/dist/local/hooks.d.ts +2 -0
  78. package/dist/local/hooks.js +44 -0
  79. package/dist/local/hooks.js.map +1 -0
  80. package/dist/local/http.d.ts +35 -0
  81. package/dist/local/http.js +160 -0
  82. package/dist/local/http.js.map +1 -0
  83. package/dist/local/provider.d.ts +571 -0
  84. package/dist/local/provider.js +1237 -0
  85. package/dist/local/provider.js.map +1 -0
  86. package/dist/local/store.d.ts +136 -0
  87. package/dist/local/store.js +171 -0
  88. package/dist/local/store.js.map +1 -0
  89. package/dist/packages/github-source.d.ts +69 -0
  90. package/dist/packages/github-source.js +133 -0
  91. package/dist/packages/github-source.js.map +1 -0
  92. package/dist/packages/gitlab-source.d.ts +59 -0
  93. package/dist/packages/gitlab-source.js +214 -0
  94. package/dist/packages/gitlab-source.js.map +1 -0
  95. package/dist/packages/index.d.ts +30 -0
  96. package/dist/packages/index.js +45 -0
  97. package/dist/packages/index.js.map +1 -0
  98. package/dist/packages/provider-source.d.ts +34 -0
  99. package/dist/packages/provider-source.js +57 -0
  100. package/dist/packages/provider-source.js.map +1 -0
  101. package/dist/packages/repository-files.d.ts +12 -0
  102. package/dist/packages/repository-files.js +16 -0
  103. package/dist/packages/repository-files.js.map +1 -0
  104. package/dist/provider.d.ts +888 -0
  105. package/dist/provider.js +29 -0
  106. package/dist/provider.js.map +1 -0
  107. package/dist/read-cache.d.ts +5 -0
  108. package/dist/read-cache.js +101 -0
  109. package/dist/read-cache.js.map +1 -0
  110. package/dist/registry/catalog.d.ts +55 -0
  111. package/dist/registry/catalog.js +143 -0
  112. package/dist/registry/catalog.js.map +1 -0
  113. package/dist/registry/kinds.d.ts +21 -0
  114. package/dist/registry/kinds.js +43 -0
  115. package/dist/registry/kinds.js.map +1 -0
  116. package/dist/registry/packages.d.ts +165 -0
  117. package/dist/registry/packages.js +290 -0
  118. package/dist/registry/packages.js.map +1 -0
  119. package/dist/registry/publish.d.ts +35 -0
  120. package/dist/registry/publish.js +155 -0
  121. package/dist/registry/publish.js.map +1 -0
  122. package/dist/registry/release.d.ts +63 -0
  123. package/dist/registry/release.js +79 -0
  124. package/dist/registry/release.js.map +1 -0
  125. package/dist/restoration.d.ts +14 -0
  126. package/dist/restoration.js +33 -0
  127. package/dist/restoration.js.map +1 -0
  128. package/dist/templates.d.ts +8 -0
  129. package/dist/templates.js +39 -0
  130. package/dist/templates.js.map +1 -0
  131. package/dist/testing/contract.d.ts +43 -0
  132. package/dist/testing/contract.js +713 -0
  133. package/dist/testing/contract.js.map +1 -0
  134. package/dist/testing/diff.d.ts +1 -0
  135. package/dist/testing/diff.js +65 -0
  136. package/dist/testing/diff.js.map +1 -0
  137. package/dist/testing/git-http.d.ts +12 -0
  138. package/dist/testing/git-http.js +308 -0
  139. package/dist/testing/git-http.js.map +1 -0
  140. package/dist/testing/github-double.d.ts +151 -0
  141. package/dist/testing/github-double.js +1129 -0
  142. package/dist/testing/github-double.js.map +1 -0
  143. package/dist/testing/gitlab-double.d.ts +161 -0
  144. package/dist/testing/gitlab-double.js +1554 -0
  145. package/dist/testing/gitlab-double.js.map +1 -0
  146. package/dist/testing/index.d.ts +7 -0
  147. package/dist/testing/index.js +8 -0
  148. package/dist/testing/index.js.map +1 -0
  149. package/dist/version.d.ts +2 -0
  150. package/dist/version.js +12 -0
  151. package/dist/version.js.map +1 -0
  152. package/package.json +66 -4
@@ -0,0 +1,214 @@
1
+ import { ModuleResolutionError } from '@lbdudc/linea-core';
2
+ import { PackageNotAllowedError } from '../errors.js';
3
+ import { createGitLabClient } from '../gitlab/client.js';
4
+ /**
5
+ * Where the modules and metamodels of an SPL come from on GitLab: projects, one version per git tag (`v1.2.3`).
6
+ * A package's location is `gitlab:<path_with_namespace>`. It implements linea-core's `PackageSource`: linea-core never fetches anything.
7
+ */
8
+ const PREFIX = 'gitlab:';
9
+ const VERSION_TAG = /^v?(\d+\.\d+\.\d+)$/;
10
+ export const isGitLabLocation = (location) => typeof location === 'string' && location.startsWith(PREFIX) && location.length > PREFIX.length;
11
+ export const gitlabLocationOf = (pathWithNamespace) => `${PREFIX}${pathWithNamespace}`;
12
+ const pathOf = (location) => location.slice(PREFIX.length);
13
+ const projectIdOf = (location) => encodeURIComponent(pathOf(location));
14
+ // What a tag holds does not change, so what was read from it is kept. Per user: a private repository's contents must not be served to
15
+ // someone who cannot read it. Not forever: a tag can be deleted and made again on another commit.
16
+ const CACHE_LIMIT = 2000;
17
+ const CONTENT_TTL_MS = 10 * 60_000;
18
+ const cache = new Map();
19
+ const remember = (key, value) => {
20
+ if (cache.size >= CACHE_LIMIT)
21
+ cache.delete(cache.keys().next().value);
22
+ cache.set(key, { at: Date.now(), value });
23
+ return value;
24
+ };
25
+ const recall = (key) => {
26
+ const hit = cache.get(key);
27
+ if (hit === undefined)
28
+ return undefined;
29
+ if (Date.now() - hit.at >= CONTENT_TTL_MS) {
30
+ cache.delete(key);
31
+ return undefined;
32
+ }
33
+ return hit;
34
+ };
35
+ /** Forgets what was read of the tags of a package: a version was just published, and the next resolution has to see it (not a minute later). */
36
+ export const forgetPackageTags = (location) => {
37
+ if (!isGitLabLocation(location))
38
+ return;
39
+ const id = projectIdOf(location);
40
+ for (const key of [...volatile.keys()])
41
+ if (key.includes(`|${id}|tag`))
42
+ volatile.delete(key);
43
+ };
44
+ // Resolutions of the same package at once (the health of every product of a page) would each read the same files before the first one
45
+ // could be remembered: a call on its way is shared by whoever asks for the same thing, per user and version.
46
+ const inflight = new Map();
47
+ const once = (key, load) => {
48
+ const running = inflight.get(key);
49
+ if (running)
50
+ return running;
51
+ const call = load().finally(() => { if (inflight.get(key) === call)
52
+ inflight.delete(key); });
53
+ inflight.set(key, call);
54
+ return call;
55
+ };
56
+ /** `load` for a tagged version (`immutable`): what was read is kept, and a read on its way is joined. Any other ref is read every time. */
57
+ const readThrough = (immutable, key, load) => {
58
+ if (!immutable)
59
+ return load();
60
+ const hit = recall(key);
61
+ if (hit)
62
+ return Promise.resolve(hit.value);
63
+ return once(key, async () => remember(key, await load()));
64
+ };
65
+ // A resolution reads every file of a package one after another (linea-core), a round trip each on a remote GitLab. Once a tagged version
66
+ // is listed its files are fetched a few at a time ahead of the reads, which then find them done (or join the call still running).
67
+ const PREFETCH_CONCURRENCY = 8;
68
+ const PREFETCH_LIMIT = 600;
69
+ /**
70
+ * The files of a GitLab repository at `ref`, as linea-core's `PackageFiles`. `immutable`: the ref is a tag, so what is read can be kept.
71
+ * `id` is the numeric project id, or the URL-encoded path.
72
+ */
73
+ export const gitlabFiles = ({ client, token, userId, id, ref, immutable = false }) => {
74
+ const scope = `${userId}|${id}|${ref}`;
75
+ const fetchFile = async (path) => {
76
+ const bytes = await readThrough(immutable, `${scope}|file|${path}`, async () => {
77
+ const raw = await client.getRawFile(token, id, path, ref);
78
+ return raw === null ? null : new Uint8Array(raw);
79
+ });
80
+ return bytes ?? undefined;
81
+ };
82
+ // one call per file at a time, whoever asks: a read that arrives while its prefetch is on the way waits for that call
83
+ const running = new Map();
84
+ const readOnce = (path) => {
85
+ let call = running.get(path);
86
+ if (call === undefined) {
87
+ call = fetchFile(path).finally(() => running.delete(path));
88
+ running.set(path, call);
89
+ }
90
+ return call;
91
+ };
92
+ const prefetch = (paths) => {
93
+ const queue = paths.slice(0, PREFETCH_LIMIT);
94
+ const worker = async () => {
95
+ for (let path = queue.shift(); path !== undefined; path = queue.shift())
96
+ await readOnce(path).catch(() => undefined);
97
+ };
98
+ for (let i = 0; i < Math.min(PREFETCH_CONCURRENCY, queue.length); i++)
99
+ void worker();
100
+ };
101
+ return {
102
+ read: ({ path }) => readOnce(path),
103
+ list: async ({ dir }) => {
104
+ const paths = await readThrough(immutable, `${scope}|tree`, () => client.getFilePaths(token, id, ref));
105
+ const prefix = dir.replace(/^\/+|\/+$/g, '');
106
+ return prefix === '' ? paths : paths.filter((file) => file.startsWith(`${prefix}/`));
107
+ },
108
+ // asked by whoever is about to read all of them (a derivation); a check only reads the few files that decide something
109
+ ...(immutable ? { prefetch } : {})
110
+ };
111
+ };
112
+ // Tags can be created (a release) or moved, so what lists them is kept only briefly: long enough that the many resolutions one
113
+ // session asks for (each change to the chosen modules resolves them all again) do not repeat the same GitLab calls.
114
+ const TAGS_TTL_MS = 60_000;
115
+ const volatile = new Map();
116
+ const recent = (key, load) => {
117
+ const now = Date.now();
118
+ const hit = volatile.get(key);
119
+ if (hit && now - hit.at < TAGS_TTL_MS)
120
+ return hit.value;
121
+ if (volatile.size >= CACHE_LIMIT)
122
+ volatile.delete(volatile.keys().next().value);
123
+ const value = load();
124
+ volatile.set(key, { at: now, value });
125
+ // a failure is not kept: the next call asks again
126
+ value.catch(() => { if (volatile.get(key)?.value === value)
127
+ volatile.delete(key); });
128
+ return value;
129
+ };
130
+ const assertLive = (signal) => {
131
+ if (signal?.aborted)
132
+ throw Object.assign(new Error('The request was cancelled'), { name: 'AbortError' });
133
+ };
134
+ export class GitLabPackageSource {
135
+ client;
136
+ token;
137
+ userId;
138
+ allowed;
139
+ overrides;
140
+ refOf = new Map();
141
+ signal;
142
+ constructor({ url, token, userId, allowedNamespaces = [], overrides = {}, signal }) {
143
+ this.signal = signal;
144
+ this.client = createGitLabClient({ url });
145
+ this.token = token;
146
+ // (kept by who and where: two GitLabs can have a project of the same path, and the same person name on both)
147
+ this.userId = `${url.replace(/\/+$/, '')}|${String(userId)}`;
148
+ this.allowed = allowedNamespaces;
149
+ this.overrides = overrides;
150
+ }
151
+ guard(location) {
152
+ if (!isGitLabLocation(location))
153
+ throw new PackageNotAllowedError(`"${location}" is not a GitLab location (gitlab:group/project).`);
154
+ const path = pathOf(location);
155
+ if (this.allowed === null || (this.allowed.length > 0 && !this.allowed.some((prefix) => path === prefix || path.startsWith(`${prefix}/`)))) {
156
+ throw new PackageNotAllowedError(`${location} is outside the trusted namespaces (${(this.allowed ?? []).join(', ')}).`);
157
+ }
158
+ return projectIdOf(location);
159
+ }
160
+ async listVersions({ location }) {
161
+ assertLive(this.signal);
162
+ const id = this.guard(location);
163
+ const override = this.overrides[location];
164
+ if (override)
165
+ return [override.version];
166
+ let tags;
167
+ try {
168
+ tags = await recent(`${this.userId}|${id}|tags`, () => this.client.getTags(this.token, id));
169
+ }
170
+ catch (error) {
171
+ // GitLab answers 404 both for a project that does not exist and for one this user's token cannot see: a package with no tags yet
172
+ // answers 200 with an empty list, so a 404 is never "no versions". Said as it is, instead of as "no version satisfies".
173
+ if (error.status === 404) {
174
+ throw new ModuleResolutionError(`${location} does not exist, or your GitLab account has no access to it.`);
175
+ }
176
+ throw error;
177
+ }
178
+ const versions = [];
179
+ for (const tag of tags) {
180
+ const match = VERSION_TAG.exec(tag.name);
181
+ if (!match)
182
+ continue;
183
+ this.refOf.set(`${location}@${match[1]}`, tag.name);
184
+ versions.push(match[1]);
185
+ }
186
+ return versions;
187
+ }
188
+ ref(location, version) {
189
+ return this.overrides[location]?.ref ?? this.refOf.get(`${location}@${version}`) ?? `v${version}`;
190
+ }
191
+ async open({ location, version }) {
192
+ assertLive(this.signal);
193
+ const id = this.guard(location);
194
+ const files = gitlabFiles({ client: this.client, token: this.token, userId: this.userId, id, ref: this.ref(location, version), immutable: !this.overrides[location] });
195
+ const signal = this.signal;
196
+ return {
197
+ read: async (query) => { assertLive(signal); return files.read(query); },
198
+ list: async (query) => { assertLive(signal); return files.list(query); },
199
+ ...(files.prefetch ? { prefetch: (paths) => { if (!signal?.aborted)
200
+ files.prefetch?.(paths); } } : {})
201
+ };
202
+ }
203
+ async revision({ location, version }) {
204
+ assertLive(this.signal);
205
+ const id = this.guard(location);
206
+ if (this.overrides[location])
207
+ return undefined;
208
+ const ref = this.ref(location, version);
209
+ const tag = await recent(`${this.userId}|${id}|tag|${ref}`, () => this.client.getTag(this.token, id, ref));
210
+ return tag?.commit?.id;
211
+ }
212
+ }
213
+ export { withOverlay } from '@lbdudc/linea-core';
214
+ //# sourceMappingURL=gitlab-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitlab-source.js","sourceRoot":"","sources":["../../src/packages/gitlab-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAyC,MAAM,oBAAoB,CAAA;AACjG,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAE,kBAAkB,EAAqB,MAAM,qBAAqB,CAAA;AAE3E;;;GAGG;AAEH,MAAM,MAAM,GAAG,SAAS,CAAA;AACxB,MAAM,WAAW,GAAG,qBAAqB,CAAA;AAEzC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAiB,EAAsB,EAAE,CAAC,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,MAAM,G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,CAAC,CAAA,CAAC,CAAC;YACvE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA,CAAC,CAAC;YACvE,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAe,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,OAAO;oBAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAA,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChH,CAAA;IACH,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAyC;QACzE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACvB,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC/B,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;YAAE,OAAO,SAAS,CAAA;QAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QACvC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,GAAG,CAAC,CAAwC,CAAA;QACjJ,OAAO,GAAG,EAAE,MAAM,EAAE,EAAE,CAAA;IACxB,CAAC;CACF;AAED,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA","sourcesContent":["import { ModuleResolutionError, type PackageFiles, type PackageSource } from '@lbdudc/linea-core'\nimport { PackageNotAllowedError } from '../errors.js'\nimport { createGitLabClient, type GitLabClient } from '../gitlab/client.js'\n\n/**\n * Where the modules and metamodels of an SPL come from on GitLab: projects, one version per git tag (`v1.2.3`).\n * A package's location is `gitlab:<path_with_namespace>`. It implements linea-core's `PackageSource`: linea-core never fetches anything.\n */\n\nconst PREFIX = 'gitlab:'\nconst VERSION_TAG = /^v?(\\d+\\.\\d+\\.\\d+)$/\n\nexport const isGitLabLocation = (location: unknown): location is string => typeof location === 'string' && location.startsWith(PREFIX) && location.length > PREFIX.length\nexport const gitlabLocationOf = (pathWithNamespace: string): string => `${PREFIX}${pathWithNamespace}`\nconst pathOf = (location: string): string => location.slice(PREFIX.length)\nconst projectIdOf = (location: string): string => encodeURIComponent(pathOf(location))\n\n// What a tag holds does not change, so what was read from it is kept. Per user: a private repository's contents must not be served to\n// someone who cannot read it. Not forever: a tag can be deleted and made again on another commit.\nconst CACHE_LIMIT = 2000\nconst CONTENT_TTL_MS = 10 * 60_000\nconst cache = new Map<string, { at: number, value: unknown }>()\nconst remember = <T>(key: string, value: T): T => {\n if (cache.size >= CACHE_LIMIT) cache.delete(cache.keys().next().value as string)\n cache.set(key, { at: Date.now(), value })\n return value\n}\nconst recall = (key: string): { value: unknown } | undefined => {\n const hit = cache.get(key)\n if (hit === undefined) return undefined\n if (Date.now() - hit.at >= CONTENT_TTL_MS) {\n cache.delete(key)\n return undefined\n }\n return hit\n}\n\n/** Forgets what was read of the tags of a package: a version was just published, and the next resolution has to see it (not a minute later). */\nexport const forgetPackageTags = (location: string): void => {\n if (!isGitLabLocation(location)) return\n const id = projectIdOf(location)\n for (const key of [...volatile.keys()]) if (key.includes(`|${id}|tag`)) volatile.delete(key)\n}\n\n// Resolutions of the same package at once (the health of every product of a page) would each read the same files before the first one\n// could be remembered: a call on its way is shared by whoever asks for the same thing, per user and version.\nconst inflight = new Map<string, Promise<unknown>>()\nconst once = <T>(key: string, load: () => Promise<T>): Promise<T> => {\n const running = inflight.get(key)\n if (running) return running as Promise<T>\n const call = load().finally(() => { if (inflight.get(key) === call) inflight.delete(key) })\n inflight.set(key, call)\n return call\n}\n\n/** `load` for a tagged version (`immutable`): what was read is kept, and a read on its way is joined. Any other ref is read every time. */\nconst readThrough = <T>(immutable: boolean, key: string, load: () => Promise<T>): Promise<T> => {\n if (!immutable) return load()\n const hit = recall(key)\n if (hit) return Promise.resolve(hit.value as T)\n return once(key, async () => remember(key, await load()))\n}\n\n// A resolution reads every file of a package one after another (linea-core), a round trip each on a remote GitLab. Once a tagged version\n// is listed its files are fetched a few at a time ahead of the reads, which then find them done (or join the call still running).\nconst PREFETCH_CONCURRENCY = 8\nconst PREFETCH_LIMIT = 600\n\n/**\n * The files of a GitLab repository at `ref`, as linea-core's `PackageFiles`. `immutable`: the ref is a tag, so what is read can be kept.\n * `id` is the numeric project id, or the URL-encoded path.\n */\nexport const gitlabFiles = ({ client, token, userId, id, ref, immutable = false }: { client: GitLabClient, token: string, userId: string, id: string | number, ref: string, immutable?: boolean }): PackageFiles => {\n const scope = `${userId}|${id}|${ref}`\n const fetchFile = async (path: string): Promise<Uint8Array | undefined> => {\n const bytes = await readThrough(immutable, `${scope}|file|${path}`, async () => {\n const raw = await client.getRawFile(token, id, path, ref)\n return raw === null ? null : new Uint8Array(raw)\n })\n return bytes ?? undefined\n }\n // one call per file at a time, whoever asks: a read that arrives while its prefetch is on the way waits for that call\n const running = new Map<string, Promise<Uint8Array | undefined>>()\n const readOnce = (path: string): Promise<Uint8Array | undefined> => {\n let call = running.get(path)\n if (call === undefined) {\n call = fetchFile(path).finally(() => running.delete(path))\n running.set(path, call)\n }\n return call\n }\n const prefetch = (paths: string[]): void => {\n const queue = paths.slice(0, PREFETCH_LIMIT)\n const worker = async (): Promise<void> => {\n for (let path = queue.shift(); path !== undefined; path = queue.shift()) await readOnce(path).catch(() => undefined)\n }\n for (let i = 0; i < Math.min(PREFETCH_CONCURRENCY, queue.length); i++) void worker()\n }\n return {\n read: ({ path }) => readOnce(path),\n list: async ({ dir }) => {\n const paths = await readThrough(immutable, `${scope}|tree`, () => client.getFilePaths(token, id, ref))\n const prefix = dir.replace(/^\\/+|\\/+$/g, '')\n return prefix === '' ? paths : paths.filter((file) => file.startsWith(`${prefix}/`))\n },\n // asked by whoever is about to read all of them (a derivation); a check only reads the few files that decide something\n ...(immutable ? { prefetch } : {})\n }\n}\n\n// Tags can be created (a release) or moved, so what lists them is kept only briefly: long enough that the many resolutions one\n// session asks for (each change to the chosen modules resolves them all again) do not repeat the same GitLab calls.\nconst TAGS_TTL_MS = 60_000\nconst volatile = new Map<string, { at: number, value: Promise<unknown> }>()\nconst recent = <T>(key: string, load: () => Promise<T>): Promise<T> => {\n const now = Date.now()\n const hit = volatile.get(key)\n if (hit && now - hit.at < TAGS_TTL_MS) return hit.value as Promise<T>\n if (volatile.size >= CACHE_LIMIT) volatile.delete(volatile.keys().next().value as string)\n const value = load()\n volatile.set(key, { at: now, value })\n // a failure is not kept: the next call asks again\n value.catch(() => { if (volatile.get(key)?.value === value) volatile.delete(key) })\n return value\n}\n\nexport interface GitLabSourceOptions {\n url: string\n token: string\n userId: string | number\n /** `null`: the list exists but names no GitLab path, so nothing is trusted. Empty: anywhere. */\n allowedNamespaces?: string[] | null\n /** Packages read from a branch as one version, instead of from their tags: to check what has not been published yet. */\n overrides?: Record<string, { version: string, ref: string }>\n /**\n * Whoever asked has gone (the browser closed the request): the source takes no further step. It is checked between GitLab calls, not\n * passed into them, because the calls are shared with other resolutions of the same user and one of them leaving must not fail the rest.\n */\n signal?: AbortSignal\n}\n\nconst assertLive = (signal: AbortSignal | undefined): void => {\n if (signal?.aborted) throw Object.assign(new Error('The request was cancelled'), { name: 'AbortError' })\n}\n\nexport class GitLabPackageSource implements PackageSource {\n private readonly client: GitLabClient\n private readonly token: string\n private readonly userId: string\n private readonly allowed: string[] | null\n private readonly overrides: Record<string, { version: string, ref: string }>\n private readonly refOf = new Map<string, string>()\n private readonly signal: AbortSignal | undefined\n\n constructor({ url, token, userId, allowedNamespaces = [], overrides = {}, signal }: GitLabSourceOptions) {\n this.signal = signal\n this.client = createGitLabClient({ url })\n this.token = token\n // (kept by who and where: two GitLabs can have a project of the same path, and the same person name on both)\n this.userId = `${url.replace(/\\/+$/, '')}|${String(userId)}`\n this.allowed = allowedNamespaces\n this.overrides = overrides\n }\n\n private guard(location: string): string {\n if (!isGitLabLocation(location)) throw new PackageNotAllowedError(`\"${location}\" is not a GitLab location (gitlab:group/project).`)\n const path = pathOf(location)\n if (this.allowed === null || (this.allowed.length > 0 && !this.allowed.some((prefix) => path === prefix || path.startsWith(`${prefix}/`)))) {\n throw new PackageNotAllowedError(`${location} is outside the trusted namespaces (${(this.allowed ?? []).join(', ')}).`)\n }\n return projectIdOf(location)\n }\n\n async listVersions({ location }: { location: string }): Promise<string[]> {\n assertLive(this.signal)\n const id = this.guard(location)\n const override = this.overrides[location]\n if (override) return [override.version]\n let tags: { name: string }[]\n try {\n tags = await recent(`${this.userId}|${id}|tags`, () => this.client.getTags(this.token, id))\n } catch (error) {\n // GitLab answers 404 both for a project that does not exist and for one this user's token cannot see: a package with no tags yet\n // answers 200 with an empty list, so a 404 is never \"no versions\". Said as it is, instead of as \"no version satisfies\".\n if ((error as { status?: number }).status === 404) {\n throw new ModuleResolutionError(`${location} does not exist, or your GitLab account has no access to it.`)\n }\n throw error\n }\n const versions: string[] = []\n for (const tag of tags) {\n const match = VERSION_TAG.exec(tag.name)\n if (!match) continue\n this.refOf.set(`${location}@${match[1]}`, tag.name)\n versions.push(match[1] as string)\n }\n return versions\n }\n\n private ref(location: string, version: string): string {\n return this.overrides[location]?.ref ?? this.refOf.get(`${location}@${version}`) ?? `v${version}`\n }\n\n async open({ location, version }: { location: string, version: string }): Promise<PackageFiles> {\n assertLive(this.signal)\n const id = this.guard(location)\n const files = gitlabFiles({ client: this.client, token: this.token, userId: this.userId, id, ref: this.ref(location, version), immutable: !this.overrides[location] })\n const signal = this.signal\n return {\n read: async (query) => { assertLive(signal); return files.read(query) },\n list: async (query) => { assertLive(signal); return files.list(query) },\n ...(files.prefetch ? { prefetch: (paths: string[]) => { if (!signal?.aborted) files.prefetch?.(paths) } } : {})\n }\n }\n\n async revision({ location, version }: { location: string, version: string }): Promise<string | undefined> {\n assertLive(this.signal)\n const id = this.guard(location)\n if (this.overrides[location]) return undefined\n const ref = this.ref(location, version)\n const tag = await recent(`${this.userId}|${id}|tag|${ref}`, () => this.client.getTag(this.token, id, ref)) as { commit?: { id?: string } } | null\n return tag?.commit?.id\n }\n}\n\nexport { withOverlay } from '@lbdudc/linea-core'\n"]}
@@ -0,0 +1,30 @@
1
+ import { type PackageSource } from '@lbdudc/linea-core';
2
+ import type { GitConfig } from '../config.js';
3
+ import type { GitHostKind } from '../provider.js';
4
+ export { GitHubPackageSource, discoverGitHubPackages, githubFiles, githubLocationOf, isGitHubLocation } from './github-source.js';
5
+ export { ProviderPackageSource } from './provider-source.js';
6
+ export { GitLabPackageSource, gitlabFiles, gitlabLocationOf, isGitLabLocation, withOverlay } from './gitlab-source.js';
7
+ export interface PackageSourceOptions {
8
+ /** The user's token: it reads GitLab, and GitHub when GitHub is the host of the deployment. */
9
+ token: string;
10
+ /** The user's token on each host they signed in to: it wins over `token` for that host (a person on both reads both). */
11
+ tokens?: Partial<Record<GitHostKind, string | undefined>>;
12
+ userId: string | number;
13
+ /** Packages read from a branch as one version, instead of from their tags (to check a working copy that is not published). */
14
+ overrides?: Record<string, {
15
+ version: string;
16
+ ref: string;
17
+ }>;
18
+ /** Aborted when whoever asked has gone: the GitLab source takes no further step. */
19
+ signal?: AbortSignal;
20
+ }
21
+ /**
22
+ * The source linea-core reads packages through: one per host, chosen by the scheme of a location (`gitlab:`, `github:`). A module on
23
+ * GitHub can require a metamodel on GitLab and the other way round.
24
+ */
25
+ export declare const createPackageSource: (config: GitConfig, { token, tokens, userId, overrides, signal }: PackageSourceOptions) => PackageSource;
26
+ /** The location of a repository of the host: `gitlab:group/project`, `github:owner/repo`. */
27
+ export declare const locationOf: ({ kind, path }: {
28
+ kind: GitHostKind;
29
+ path: string;
30
+ }) => string;
@@ -0,0 +1,45 @@
1
+ import { createRoutingSource } from '@lbdudc/linea-core';
2
+ import { createGitProvider } from '../factory.js';
3
+ import { ProviderPackageSource } from './provider-source.js';
4
+ import { GitHubPackageSource } from './github-source.js';
5
+ import { GitLabPackageSource } from './gitlab-source.js';
6
+ export { GitHubPackageSource, discoverGitHubPackages, githubFiles, githubLocationOf, isGitHubLocation } from './github-source.js';
7
+ export { ProviderPackageSource } from './provider-source.js';
8
+ export { GitLabPackageSource, gitlabFiles, gitlabLocationOf, isGitLabLocation, withOverlay } from './gitlab-source.js';
9
+ /** The entries of `config.trustedNamespaces` that apply to a host: `github:<owner>` ones to GitHub, the others to GitLab. */
10
+ const trustedFor = (config, host) => {
11
+ const entries = config.trustedNamespaces ?? [];
12
+ if (entries.length === 0)
13
+ return [];
14
+ const mine = entries
15
+ .filter((entry) => entry.startsWith('github:') === (host === 'github'))
16
+ .map((entry) => (host === 'github' ? entry.slice('github:'.length) : entry).replace(/^\/+|\/+$/g, ''));
17
+ return mine.length > 0 ? mine : null;
18
+ };
19
+ /**
20
+ * The source linea-core reads packages through: one per host, chosen by the scheme of a location (`gitlab:`, `github:`). A module on
21
+ * GitHub can require a metamodel on GitLab and the other way round.
22
+ */
23
+ export const createPackageSource = (config, { token, tokens = {}, userId, overrides = {}, signal }) => createRoutingSource({
24
+ sources: {
25
+ // the packages on this server's own repositories; the user's token on `local` is theirs, as on any host
26
+ ...(config.local?.dataDir || config.provider === 'local' || tokens.local
27
+ ? { local: new ProviderPackageSource({ scheme: 'local', provider: createGitProvider({ ...config, provider: 'local' }), token: tokens.local ?? (config.provider === 'local' ? token : ''), overrides }) }
28
+ : {}),
29
+ // a GitLab that is not set up has no packages to read: its locations are refused as ones no registry here reads
30
+ ...(config.gitlab?.url
31
+ ? { gitlab: new GitLabPackageSource({ url: config.gitlab.url, token: tokens.gitlab ?? token, userId, allowedNamespaces: trustedFor(config, 'gitlab'), overrides, signal }) }
32
+ : {}),
33
+ // on a GitHub deployment the user's own token reads GitHub; otherwise only the configured token (or none, for public repositories) does
34
+ github: new GitHubPackageSource({
35
+ config: config.github ?? {},
36
+ token: tokens.github ?? (config.provider === 'github' ? token : undefined),
37
+ userId,
38
+ allowedOwners: trustedFor(config, 'github'),
39
+ overrides
40
+ })
41
+ }
42
+ });
43
+ /** The location of a repository of the host: `gitlab:group/project`, `github:owner/repo`. */
44
+ export const locationOf = ({ kind, path }) => `${kind}:${path}`;
45
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/packages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAsB,MAAM,oBAAoB,CAAA;AAE5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACjI,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEtH,6HAA6H;AAC7H,MAAM,UAAU,GAAG,CAAC,MAAiB,EAAE,IAAyB,EAAmB,EAAE;IACnF,MAAM,OAAO,GAAG,MAAM,CAAC,iBAAiB,IAAI,EAAE,CAAA;IAC9C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IACnC,MAAM,IAAI,GAAG,OAAO;SACjB,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,K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AM,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,IAAI,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE;YAC5K,CAAC,CAAC,EAAE,CAAC;QACP,wIAAwI;QACxI,MAAM,EAAE,IAAI,mBAAmB,CAAC;YAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE;YAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;YAC1E,MAAM;YACN,aAAa,EAAE,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC;YAC3C,SAAS;SACV,CAAC;KACH;CACF,CAAC,CAAA;AAEJ,6FAA6F;AAC7F,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,EAAuC,EAAU,EAAE,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAA","sourcesContent":["import { createRoutingSource, type PackageSource } from '@lbdudc/linea-core'\nimport type { GitConfig } from '../config.js'\nimport { createGitProvider } from '../factory.js'\nimport type { GitHostKind } from '../provider.js'\nimport { ProviderPackageSource } from './provider-source.js'\nimport { GitHubPackageSource } from './github-source.js'\nimport { GitLabPackageSource } from './gitlab-source.js'\n\nexport { GitHubPackageSource, discoverGitHubPackages, githubFiles, githubLocationOf, isGitHubLocation } from './github-source.js'\nexport { ProviderPackageSource } from './provider-source.js'\nexport { GitLabPackageSource, gitlabFiles, gitlabLocationOf, isGitLabLocation, withOverlay } from './gitlab-source.js'\n\n/** The entries of `config.trustedNamespaces` that apply to a host: `github:<owner>` ones to GitHub, the others to GitLab. */\nconst trustedFor = (config: GitConfig, host: 'gitlab' | 'github'): string[] | null => {\n const entries = config.trustedNamespaces ?? []\n if (entries.length === 0) return []\n const mine = entries\n .filter((entry) => entry.startsWith('github:') === (host === 'github'))\n .map((entry) => (host === 'github' ? entry.slice('github:'.length) : entry).replace(/^\\/+|\\/+$/g, ''))\n return mine.length > 0 ? mine : null\n}\n\nexport interface PackageSourceOptions {\n /** The user's token: it reads GitLab, and GitHub when GitHub is the host of the deployment. */\n token: string\n /** The user's token on each host they signed in to: it wins over `token` for that host (a person on both reads both). */\n tokens?: Partial<Record<GitHostKind, string | undefined>>\n userId: string | number\n /** Packages read from a branch as one version, instead of from their tags (to check a working copy that is not published). */\n overrides?: Record<string, { version: string, ref: string }>\n /** Aborted when whoever asked has gone: the GitLab source takes no further step. */\n signal?: AbortSignal\n}\n\n/**\n * The source linea-core reads packages through: one per host, chosen by the scheme of a location (`gitlab:`, `github:`). A module on\n * GitHub can require a metamodel on GitLab and the other way round.\n */\nexport const createPackageSource = (config: GitConfig, { token, tokens = {}, userId, overrides = {}, signal }: PackageSourceOptions): PackageSource =>\n createRoutingSource({\n sources: {\n // the packages on this server's own repositories; the user's token on `local` is theirs, as on any host\n ...(config.local?.dataDir || config.provider === 'local' || tokens.local\n ? { local: new ProviderPackageSource({ scheme: 'local', provider: createGitProvider({ ...config, provider: 'local' }), token: tokens.local ?? (config.provider === 'local' ? token : ''), overrides }) }\n : {}),\n // a GitLab that is not set up has no packages to read: its locations are refused as ones no registry here reads\n ...(config.gitlab?.url\n ? { gitlab: new GitLabPackageSource({ url: config.gitlab.url, token: tokens.gitlab ?? token, userId, allowedNamespaces: trustedFor(config, 'gitlab'), overrides, signal }) }\n : {}),\n // on a GitHub deployment the user's own token reads GitHub; otherwise only the configured token (or none, for public repositories) does\n github: new GitHubPackageSource({\n config: config.github ?? {},\n token: tokens.github ?? (config.provider === 'github' ? token : undefined),\n userId,\n allowedOwners: trustedFor(config, 'github'),\n overrides\n })\n }\n })\n\n/** The location of a repository of the host: `gitlab:group/project`, `github:owner/repo`. */\nexport const locationOf = ({ kind, path }: { kind: GitHostKind, path: string }): string => `${kind}:${path}`\n"]}
@@ -0,0 +1,34 @@
1
+ import { type PackageFiles, type PackageSource } from '@lbdudc/linea-core';
2
+ import type { GitProvider } from '../provider.js';
3
+ /**
4
+ * Where the packages of a host that is read through its own `GitProvider` come from (the `local` host): a package's location is
5
+ * `<scheme>:<path>`, its versions the git tags `vX.Y.Z`. There is nothing to cache: the repositories are on this machine.
6
+ */
7
+ export declare class ProviderPackageSource implements PackageSource {
8
+ private readonly options;
9
+ private readonly refOf;
10
+ constructor(options: {
11
+ scheme: string;
12
+ provider: GitProvider;
13
+ token: string;
14
+ /** Packages read from a branch as one version, instead of from their tags: to check what has not been published yet. */
15
+ overrides?: Record<string, {
16
+ version: string;
17
+ ref: string;
18
+ }>;
19
+ });
20
+ private pathOf;
21
+ private repository;
22
+ listVersions({ location }: {
23
+ location: string;
24
+ }): Promise<string[]>;
25
+ private ref;
26
+ open({ location, version }: {
27
+ location: string;
28
+ version: string;
29
+ }): Promise<PackageFiles>;
30
+ revision({ location, version }: {
31
+ location: string;
32
+ version: string;
33
+ }): Promise<string | undefined>;
34
+ }
@@ -0,0 +1,57 @@
1
+ import { ModuleResolutionError } from '@lbdudc/linea-core';
2
+ import { repositoryFiles } from './repository-files.js';
3
+ const VERSION_TAG = /^v?(\d+\.\d+\.\d+)$/;
4
+ /**
5
+ * Where the packages of a host that is read through its own `GitProvider` come from (the `local` host): a package's location is
6
+ * `<scheme>:<path>`, its versions the git tags `vX.Y.Z`. There is nothing to cache: the repositories are on this machine.
7
+ */
8
+ export class ProviderPackageSource {
9
+ options;
10
+ refOf = new Map();
11
+ constructor(options) {
12
+ this.options = options;
13
+ }
14
+ pathOf(location) {
15
+ const prefix = `${this.options.scheme}:`;
16
+ if (!location.startsWith(prefix) || location.length === prefix.length) {
17
+ throw new ModuleResolutionError(`"${location}" is not a ${this.options.scheme} location (${prefix}group/project).`);
18
+ }
19
+ return location.slice(prefix.length);
20
+ }
21
+ async repository(location) {
22
+ const repository = await this.options.provider.findRepository({ token: this.options.token, path: this.pathOf(location) });
23
+ if (!repository)
24
+ throw new ModuleResolutionError(`${location} does not exist, or your account has no access to it.`);
25
+ return repository;
26
+ }
27
+ async listVersions({ location }) {
28
+ const override = this.options.overrides?.[location];
29
+ if (override)
30
+ return [override.version];
31
+ const repository = await this.repository(location);
32
+ const versions = [];
33
+ for (const tag of await this.options.provider.listTags({ token: this.options.token, id: repository.id })) {
34
+ const match = VERSION_TAG.exec(tag.name);
35
+ if (!match)
36
+ continue;
37
+ this.refOf.set(`${location}@${match[1]}`, tag.name);
38
+ versions.push(match[1]);
39
+ }
40
+ return versions;
41
+ }
42
+ ref(location, version) {
43
+ return this.options.overrides?.[location]?.ref ?? this.refOf.get(`${location}@${version}`) ?? `v${version}`;
44
+ }
45
+ async open({ location, version }) {
46
+ const repository = await this.repository(location);
47
+ return repositoryFiles({ provider: this.options.provider, token: this.options.token, id: repository.id, ref: this.ref(location, version) });
48
+ }
49
+ async revision({ location, version }) {
50
+ if (this.options.overrides?.[location])
51
+ return undefined;
52
+ const repository = await this.repository(location);
53
+ const tag = await this.options.provider.getTag({ token: this.options.token, id: repository.id, tag: this.ref(location, version) });
54
+ return tag?.commitId;
55
+ }
56
+ }
57
+ //# sourceMappingURL=provider-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-source.js","sourceRoot":"","sources":["../../src/packages/provider-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAyC,MAAM,oBAAoB,CAAA;AAEjG,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,MAAM,WAAW,GAAG,qBAAqB,CAAA;AAEzC;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IAGH;IAFZ,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAA;IAElD,YAA6B,OAM5B;QAN4B,YAAO,GAAP,OAAO,CAMnC;IAAG,CAAC;IAEG,MAAM,CAAC,QAAgB;QAC7B,MAAM,MAAM,GAAG,GAAG,IAAI,CAAC,O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GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC,CAAA;QAClI,OAAO,GAAG,EAAE,QAAQ,CAAA;IACtB,CAAC;CACF","sourcesContent":["import { ModuleResolutionError, type PackageFiles, type PackageSource } from '@lbdudc/linea-core'\nimport type { GitProvider } from '../provider.js'\nimport { repositoryFiles } from './repository-files.js'\n\nconst VERSION_TAG = /^v?(\\d+\\.\\d+\\.\\d+)$/\n\n/**\n * Where the packages of a host that is read through its own `GitProvider` come from (the `local` host): a package's location is\n * `<scheme>:<path>`, its versions the git tags `vX.Y.Z`. There is nothing to cache: the repositories are on this machine.\n */\nexport class ProviderPackageSource implements PackageSource {\n private readonly refOf = new Map<string, string>()\n\n constructor(private readonly options: {\n scheme: string\n provider: GitProvider\n token: string\n /** Packages read from a branch as one version, instead of from their tags: to check what has not been published yet. */\n overrides?: Record<string, { version: string, ref: string }>\n }) {}\n\n private pathOf(location: string): string {\n const prefix = `${this.options.scheme}:`\n if (!location.startsWith(prefix) || location.length === prefix.length) {\n throw new ModuleResolutionError(`\"${location}\" is not a ${this.options.scheme} location (${prefix}group/project).`)\n }\n return location.slice(prefix.length)\n }\n\n private async repository(location: string) {\n const repository = await this.options.provider.findRepository({ token: this.options.token, path: this.pathOf(location) })\n if (!repository) throw new ModuleResolutionError(`${location} does not exist, or your account has no access to it.`)\n return repository\n }\n\n async listVersions({ location }: { location: string }): Promise<string[]> {\n const override = this.options.overrides?.[location]\n if (override) return [override.version]\n const repository = await this.repository(location)\n const versions: string[] = []\n for (const tag of await this.options.provider.listTags({ token: this.options.token, id: repository.id })) {\n const match = VERSION_TAG.exec(tag.name)\n if (!match) continue\n this.refOf.set(`${location}@${match[1]}`, tag.name)\n versions.push(match[1] as string)\n }\n return versions\n }\n\n private ref(location: string, version: string): string {\n return this.options.overrides?.[location]?.ref ?? this.refOf.get(`${location}@${version}`) ?? `v${version}`\n }\n\n async open({ location, version }: { location: string, version: string }): Promise<PackageFiles> {\n const repository = await this.repository(location)\n return repositoryFiles({ provider: this.options.provider, token: this.options.token, id: repository.id, ref: this.ref(location, version) })\n }\n\n async revision({ location, version }: { location: string, version: string }): Promise<string | undefined> {\n if (this.options.overrides?.[location]) return undefined\n const repository = await this.repository(location)\n const tag = await this.options.provider.getTag({ token: this.options.token, id: repository.id, tag: this.ref(location, version) })\n return tag?.commitId\n }\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import type { PackageFiles } from '@lbdudc/linea-core';
2
+ import type { GitProvider, Id } from '../provider.js';
3
+ /**
4
+ * The files of a repository at `ref` as linea-core's `PackageFiles`, on whatever git host the provider is for. Used for the
5
+ * repository of an SPL (its `spl.json`, lockfile and platform), which is read as it is on `main`.
6
+ */
7
+ export declare const repositoryFiles: ({ provider, token, id, ref }: {
8
+ provider: GitProvider;
9
+ token: string;
10
+ id: Id;
11
+ ref: string;
12
+ }) => PackageFiles;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The files of a repository at `ref` as linea-core's `PackageFiles`, on whatever git host the provider is for. Used for the
3
+ * repository of an SPL (its `spl.json`, lockfile and platform), which is read as it is on `main`.
4
+ */
5
+ export const repositoryFiles = ({ provider, token, id, ref }) => ({
6
+ read: async ({ path }) => {
7
+ const bytes = await provider.readFile({ token, id, path, ref });
8
+ return bytes === null ? undefined : new Uint8Array(bytes);
9
+ },
10
+ list: async ({ dir }) => {
11
+ const paths = await provider.listFiles({ token, id, ref });
12
+ const prefix = dir.replace(/^\/+|\/+$/g, '');
13
+ return prefix === '' ? paths : paths.filter((file) => file.startsWith(`${prefix}/`));
14
+ }
15
+ });
16
+ //# sourceMappingURL=repository-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository-files.js","sourceRoot":"","sources":["../../src/packages/repository-files.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAiE,EAAgB,EAAE,CAAC,CAAC;IAC7I,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QACvB,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAA;QAC/D,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAA;IAC3D,CAAC;IACD,IAAI,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;QACtB,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAA;QAC1D,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;QAC5C,OAAO,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAA;IACtF,CAAC;CACF,CAAC,CAAA","sourcesContent":["import type { PackageFiles } from '@lbdudc/linea-core'\nimport type { GitProvider, Id } from '../provider.js'\n\n/**\n * The files of a repository at `ref` as linea-core's `PackageFiles`, on whatever git host the provider is for. Used for the\n * repository of an SPL (its `spl.json`, lockfile and platform), which is read as it is on `main`.\n */\nexport const repositoryFiles = ({ provider, token, id, ref }: { provider: GitProvider, token: string, id: Id, ref: string }): PackageFiles => ({\n read: async ({ path }) => {\n const bytes = await provider.readFile({ token, id, path, ref })\n return bytes === null ? undefined : new Uint8Array(bytes)\n },\n list: async ({ dir }) => {\n const paths = await provider.listFiles({ token, id, ref })\n const prefix = dir.replace(/^\\/+|\\/+$/g, '')\n return prefix === '' ? paths : paths.filter((file) => file.startsWith(`${prefix}/`))\n }\n})\n"]}