@lbdudc/linea-git 0.0.0-stage → 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/README.md +47 -2
- package/dist/access.d.ts +18 -0
- package/dist/access.js +18 -0
- package/dist/access.js.map +1 -0
- package/dist/auth.d.ts +11 -0
- package/dist/auth.js +16 -0
- package/dist/auth.js.map +1 -0
- package/dist/changelog/generate.d.ts +18 -0
- package/dist/changelog/generate.js +166 -0
- package/dist/changelog/generate.js.map +1 -0
- package/dist/changelog/index.d.ts +5 -0
- package/dist/changelog/index.js +3 -0
- package/dist/changelog/index.js.map +1 -0
- package/dist/changelog/parse.d.ts +43 -0
- package/dist/changelog/parse.js +91 -0
- package/dist/changelog/parse.js.map +1 -0
- package/dist/changelog/types.d.ts +85 -0
- package/dist/changelog/types.js +2 -0
- package/dist/changelog/types.js.map +1 -0
- package/dist/checkout/credential.d.ts +14 -0
- package/dist/checkout/credential.js +29 -0
- package/dist/checkout/credential.js.map +1 -0
- package/dist/checkout/git.d.ts +78 -0
- package/dist/checkout/git.js +191 -0
- package/dist/checkout/git.js.map +1 -0
- package/dist/checkout/index.d.ts +3 -0
- package/dist/checkout/index.js +4 -0
- package/dist/checkout/index.js.map +1 -0
- package/dist/checkout/sync.d.ts +156 -0
- package/dist/checkout/sync.js +211 -0
- package/dist/checkout/sync.js.map +1 -0
- package/dist/closing.d.ts +1 -0
- package/dist/closing.js +14 -0
- package/dist/closing.js.map +1 -0
- package/dist/config.d.ts +53 -0
- package/dist/config.js +40 -0
- package/dist/config.js.map +1 -0
- package/dist/deletion.d.ts +19 -0
- package/dist/deletion.js +27 -0
- package/dist/deletion.js.map +1 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.js +47 -0
- package/dist/errors.js.map +1 -0
- package/dist/factory.d.ts +20 -0
- package/dist/factory.js +46 -0
- package/dist/factory.js.map +1 -0
- package/dist/github/client.d.ts +44 -0
- package/dist/github/client.js +145 -0
- package/dist/github/client.js.map +1 -0
- package/dist/github/config.d.ts +24 -0
- package/dist/github/config.js +11 -0
- package/dist/github/config.js.map +1 -0
- package/dist/github/provider.d.ts +510 -0
- package/dist/github/provider.js +1009 -0
- package/dist/github/provider.js.map +1 -0
- package/dist/gitlab/client.d.ts +50 -0
- package/dist/gitlab/client.js +228 -0
- package/dist/gitlab/client.js.map +1 -0
- package/dist/gitlab/provider.d.ts +487 -0
- package/dist/gitlab/provider.js +719 -0
- package/dist/gitlab/provider.js.map +1 -0
- package/dist/host.d.ts +27 -0
- package/dist/host.js +45 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/local/diff.d.ts +3 -0
- package/dist/local/diff.js +43 -0
- package/dist/local/diff.js.map +1 -0
- package/dist/local/git.d.ts +24 -0
- package/dist/local/git.js +51 -0
- package/dist/local/git.js.map +1 -0
- package/dist/local/health.d.ts +36 -0
- package/dist/local/health.js +57 -0
- package/dist/local/health.js.map +1 -0
- package/dist/local/hooks.d.ts +2 -0
- package/dist/local/hooks.js +44 -0
- package/dist/local/hooks.js.map +1 -0
- package/dist/local/http.d.ts +35 -0
- package/dist/local/http.js +160 -0
- package/dist/local/http.js.map +1 -0
- package/dist/local/provider.d.ts +571 -0
- package/dist/local/provider.js +1237 -0
- package/dist/local/provider.js.map +1 -0
- package/dist/local/store.d.ts +136 -0
- package/dist/local/store.js +171 -0
- package/dist/local/store.js.map +1 -0
- package/dist/packages/github-source.d.ts +69 -0
- package/dist/packages/github-source.js +133 -0
- package/dist/packages/github-source.js.map +1 -0
- package/dist/packages/gitlab-source.d.ts +59 -0
- package/dist/packages/gitlab-source.js +214 -0
- package/dist/packages/gitlab-source.js.map +1 -0
- package/dist/packages/index.d.ts +30 -0
- package/dist/packages/index.js +45 -0
- package/dist/packages/index.js.map +1 -0
- package/dist/packages/provider-source.d.ts +34 -0
- package/dist/packages/provider-source.js +57 -0
- package/dist/packages/provider-source.js.map +1 -0
- package/dist/packages/repository-files.d.ts +12 -0
- package/dist/packages/repository-files.js +16 -0
- package/dist/packages/repository-files.js.map +1 -0
- package/dist/provider.d.ts +888 -0
- package/dist/provider.js +29 -0
- package/dist/provider.js.map +1 -0
- package/dist/read-cache.d.ts +5 -0
- package/dist/read-cache.js +101 -0
- package/dist/read-cache.js.map +1 -0
- package/dist/registry/catalog.d.ts +55 -0
- package/dist/registry/catalog.js +143 -0
- package/dist/registry/catalog.js.map +1 -0
- package/dist/registry/kinds.d.ts +21 -0
- package/dist/registry/kinds.js +43 -0
- package/dist/registry/kinds.js.map +1 -0
- package/dist/registry/packages.d.ts +165 -0
- package/dist/registry/packages.js +290 -0
- package/dist/registry/packages.js.map +1 -0
- package/dist/registry/publish.d.ts +35 -0
- package/dist/registry/publish.js +155 -0
- package/dist/registry/publish.js.map +1 -0
- package/dist/registry/release.d.ts +63 -0
- package/dist/registry/release.js +79 -0
- package/dist/registry/release.js.map +1 -0
- package/dist/restoration.d.ts +14 -0
- package/dist/restoration.js +33 -0
- package/dist/restoration.js.map +1 -0
- package/dist/templates.d.ts +8 -0
- package/dist/templates.js +39 -0
- package/dist/templates.js.map +1 -0
- package/dist/testing/contract.d.ts +43 -0
- package/dist/testing/contract.js +713 -0
- package/dist/testing/contract.js.map +1 -0
- package/dist/testing/diff.d.ts +1 -0
- package/dist/testing/diff.js +65 -0
- package/dist/testing/diff.js.map +1 -0
- package/dist/testing/git-http.d.ts +12 -0
- package/dist/testing/git-http.js +308 -0
- package/dist/testing/git-http.js.map +1 -0
- package/dist/testing/github-double.d.ts +151 -0
- package/dist/testing/github-double.js +1129 -0
- package/dist/testing/github-double.js.map +1 -0
- package/dist/testing/gitlab-double.d.ts +161 -0
- package/dist/testing/gitlab-double.js +1554 -0
- package/dist/testing/gitlab-double.js.map +1 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.js +8 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +12 -0
- package/dist/version.js.map +1 -0
- package/package.json +66 -4
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
const EMPTY = { next: 1, namespaces: [], repositories: [] };
|
|
4
|
+
const deepFreeze = (value) => {
|
|
5
|
+
if (value && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
6
|
+
Object.freeze(value);
|
|
7
|
+
for (const child of Object.values(value))
|
|
8
|
+
deepFreeze(child);
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
};
|
|
12
|
+
// operations on one folder run one after another, whoever asks (the file is rewritten whole)
|
|
13
|
+
const queues = new Map();
|
|
14
|
+
// Another process on the same folder (the CLI, a second server) must not write at the same time: a lock file next to the state, taken
|
|
15
|
+
// for each change. A lock left by a process that died is taken over after STALE_MS.
|
|
16
|
+
export const STALE_MS = 30_000;
|
|
17
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
18
|
+
export class LocalStore {
|
|
19
|
+
dir;
|
|
20
|
+
file;
|
|
21
|
+
lock;
|
|
22
|
+
constructor(dataDir) {
|
|
23
|
+
this.dir = path.resolve(dataDir);
|
|
24
|
+
this.file = path.join(this.dir, 'state.json');
|
|
25
|
+
this.lock = `${this.file}.lock`;
|
|
26
|
+
}
|
|
27
|
+
/** Where the bare repository of `id` is. */
|
|
28
|
+
repositoryDir(id) {
|
|
29
|
+
return path.join(this.dir, 'repos', `${id}.git`);
|
|
30
|
+
}
|
|
31
|
+
// The state as it was last read, and which file that was (a rewrite is a new inode, so another process's write is seen too): a read that
|
|
32
|
+
// finds the file as it was does not parse it again. Frozen, because it is shared: whoever changes the state does it in `update`, on a copy.
|
|
33
|
+
cached = null;
|
|
34
|
+
recovered = false;
|
|
35
|
+
parse(file) {
|
|
36
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
37
|
+
}
|
|
38
|
+
signature() {
|
|
39
|
+
try {
|
|
40
|
+
const stat = fs.statSync(this.file);
|
|
41
|
+
return `${stat.ino}:${stat.size}:${stat.mtimeMs}`;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
load() {
|
|
48
|
+
const signature = this.signature();
|
|
49
|
+
if (signature && this.cached?.signature === signature)
|
|
50
|
+
return this.cached.state;
|
|
51
|
+
this.recovered = false;
|
|
52
|
+
const state = this.read_();
|
|
53
|
+
// (a copy recovered from a file that could not be read is not remembered: the file is still damaged)
|
|
54
|
+
if (signature && !this.recovered && this.signature() === signature)
|
|
55
|
+
this.cached = { signature, state: deepFreeze(state) };
|
|
56
|
+
else
|
|
57
|
+
this.cached = null;
|
|
58
|
+
return this.cached?.state ?? state;
|
|
59
|
+
}
|
|
60
|
+
read_() {
|
|
61
|
+
try {
|
|
62
|
+
return this.parse(this.file);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (error.code === 'ENOENT')
|
|
66
|
+
return structuredClone(EMPTY);
|
|
67
|
+
// a file that cannot be read (a write cut short, a disk that lied): the last good copy, if there is one, rather than a host that is down
|
|
68
|
+
try {
|
|
69
|
+
const recovered = this.parse(`${this.file}.bak`);
|
|
70
|
+
this.recovered = true;
|
|
71
|
+
console.error(`[local git] ${this.file} could not be read (${error.message}): using the last good copy`);
|
|
72
|
+
return recovered;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
throw new Error(`${this.file} is damaged and there is no copy to recover from: ${error.message}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
read(fn) {
|
|
80
|
+
return this.queue(() => fn(this.load()));
|
|
81
|
+
}
|
|
82
|
+
async lockFile() {
|
|
83
|
+
fs.mkdirSync(this.dir, { recursive: true });
|
|
84
|
+
for (let attempt = 0;; attempt += 1) {
|
|
85
|
+
try {
|
|
86
|
+
const fd = fs.openSync(this.lock, 'wx');
|
|
87
|
+
fs.writeSync(fd, String(process.pid));
|
|
88
|
+
fs.closeSync(fd);
|
|
89
|
+
return () => fs.rmSync(this.lock, { force: true });
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (error.code !== 'EEXIST')
|
|
93
|
+
throw error;
|
|
94
|
+
let age = 0;
|
|
95
|
+
try {
|
|
96
|
+
age = Date.now() - fs.statSync(this.lock).mtimeMs;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (age > STALE_MS) {
|
|
102
|
+
fs.rmSync(this.lock, { force: true });
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (attempt > 600)
|
|
106
|
+
throw new Error(`${this.lock} is held by another process`);
|
|
107
|
+
await sleep(20);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Writes the state so that a cut leaves the old file or the new one, never half: to a temporary file, to disk, over the old. */
|
|
112
|
+
write(state) {
|
|
113
|
+
const tmp = `${this.file}.${process.pid}.tmp`;
|
|
114
|
+
const fd = fs.openSync(tmp, 'w');
|
|
115
|
+
try {
|
|
116
|
+
fs.writeSync(fd, JSON.stringify(state, null, 2));
|
|
117
|
+
fs.fsyncSync(fd);
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
fs.closeSync(fd);
|
|
121
|
+
}
|
|
122
|
+
// the file that is about to be replaced is the last good one
|
|
123
|
+
if (fs.existsSync(this.file))
|
|
124
|
+
fs.copyFileSync(this.file, `${this.file}.bak`);
|
|
125
|
+
fs.renameSync(tmp, this.file);
|
|
126
|
+
this.cached = null;
|
|
127
|
+
try {
|
|
128
|
+
const directory = fs.openSync(this.dir, 'r');
|
|
129
|
+
fs.fsyncSync(directory);
|
|
130
|
+
fs.closeSync(directory);
|
|
131
|
+
}
|
|
132
|
+
catch { /* a platform that cannot sync a folder */ }
|
|
133
|
+
}
|
|
134
|
+
/** Changes the state: `fn` gets it and returns what the caller wants back; what it changed is saved when it is done. */
|
|
135
|
+
update(fn) {
|
|
136
|
+
return this.queue(async () => {
|
|
137
|
+
const release = await this.lockFile();
|
|
138
|
+
try {
|
|
139
|
+
const state = structuredClone(this.load()); // a copy: `fn` may change it and then fail
|
|
140
|
+
const before = JSON.stringify(state);
|
|
141
|
+
const result = await fn(state);
|
|
142
|
+
if (JSON.stringify(state) !== before)
|
|
143
|
+
this.write(state);
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
release();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
queue(run) {
|
|
152
|
+
const previous = queues.get(this.file) ?? Promise.resolve();
|
|
153
|
+
const current = previous.then(run, run);
|
|
154
|
+
queues.set(this.file, current.catch(() => undefined));
|
|
155
|
+
return current;
|
|
156
|
+
}
|
|
157
|
+
/** Adds (or raises) a person's access to a repository: how an administrator lets someone else in. */
|
|
158
|
+
addMember({ repositoryId, username, accessLevel }) {
|
|
159
|
+
return this.update((state) => {
|
|
160
|
+
const repository = state.repositories.find((candidate) => candidate.id === Number(repositoryId));
|
|
161
|
+
if (!repository)
|
|
162
|
+
throw Object.assign(new Error('There is no such repository'), { status: 404 });
|
|
163
|
+
const known = repository.members.find((member) => member.username === username);
|
|
164
|
+
if (known)
|
|
165
|
+
known.accessLevel = accessLevel;
|
|
166
|
+
else
|
|
167
|
+
repository.members.push({ username, accessLevel });
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/local/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AA2G5B,MAAM,KAAK,GAAU,EAAE,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,YAAY,EAAE,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AAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QACvC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;QACrD,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,qGAAqG;IACrG,SAAS,CAAC,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAA4E;QACzH,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YAC3B,MAAM,UAAU,GAAG,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;YAChG,IAAI,CAAC,UAAU;gBAAE,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,6BAA6B,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;YAC/F,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAA;YAC/E,IAAI,KAAK;gBAAE,KAAK,CAAC,WAAW,GAAG,WAAW,CAAA;;gBACrC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAA;QACzD,CAAC,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\n/**\n * What the `local` host knows about its repositories besides what git keeps: the namespaces (groups), who is in a repository, its\n * topics, its change requests and webhooks. One JSON file next to the repositories, read and written whole, one operation at a time.\n * (A host with many writers would use a database; this one is the server of one team.)\n */\n\nexport interface ThreadRecord {\n id: number\n position?: { path: string, line: number, side: 'new' | 'old' }\n resolved: boolean\n comments: CommentRecord[]\n}\n\nexport interface ChangeRequestRecord {\n number: number\n title: string\n sourceBranch: string\n targetBranch: string\n state: 'opened' | 'merged' | 'closed'\n createdAt: string\n // (absent in a state written before the pages of merge requests existed)\n description?: string\n author?: string\n labels?: string[]\n reviewers?: string[]\n updatedAt?: string\n mergedAt?: string | null\n threads?: ThreadRecord[]\n nextThread?: number\n nextComment?: number\n}\n\nexport interface CommentRecord {\n id: number\n author: string\n body: string\n createdAt: string\n updatedAt: string\n}\n\nexport interface IssueRecord {\n number: number\n title: string\n description: string\n state: 'opened' | 'closed'\n author: string\n assignees: string[]\n labels: string[]\n milestone: string | null\n createdAt: string\n updatedAt: string\n closedAt: string | null\n comments: CommentRecord[]\n nextComment: number\n}\n\nexport interface TemplateRecord {\n name: string\n content: string\n}\n\nexport interface ReleaseRecord {\n tag: string\n name: string\n description: string\n prerelease: boolean\n createdAt: string\n}\n\nexport interface NamespaceRecord {\n id: number\n name: string\n /** `group/sub`: what the host shows as the path. */\n path: string\n parentId: number | null\n owner: string\n}\n\nexport interface RepositoryRecord {\n id: number\n name: string\n namespaceId: number\n description: string\n topics: string[]\n defaultBranch: string\n owner: string\n members: { username: string, accessLevel: number }[]\n changeRequests: ChangeRequestRecord[]\n nextChangeRequest: number\n /** (absent in a state written before issues existed) */\n issues?: IssueRecord[]\n nextIssue?: number\n /** (absent in a state written before releases existed) */\n releases?: ReleaseRecord[]\n templates?: { issue: TemplateRecord[], mergeRequest: TemplateRecord[] }\n hooks: { url: string, secret: string, branch: string | null }[]\n createdAt: string\n}\n\nexport interface State {\n next: number\n namespaces: NamespaceRecord[]\n repositories: RepositoryRecord[]\n}\n\nconst EMPTY: State = { next: 1, namespaces: [], repositories: [] }\n\nconst deepFreeze = <T>(value: T): T => {\n if (value && typeof value === 'object' && !Object.isFrozen(value)) {\n Object.freeze(value)\n for (const child of Object.values(value)) deepFreeze(child)\n }\n return value\n}\n\n// operations on one folder run one after another, whoever asks (the file is rewritten whole)\nconst queues = new Map<string, Promise<unknown>>()\n\n// Another process on the same folder (the CLI, a second server) must not write at the same time: a lock file next to the state, taken\n// for each change. A lock left by a process that died is taken over after STALE_MS.\nexport const STALE_MS = 30_000\nconst sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms))\n\nexport class LocalStore {\n readonly dir: string\n private readonly file: string\n private readonly lock: string\n\n constructor(dataDir: string) {\n this.dir = path.resolve(dataDir)\n this.file = path.join(this.dir, 'state.json')\n this.lock = `${this.file}.lock`\n }\n\n /** Where the bare repository of `id` is. */\n repositoryDir(id: number): string {\n return path.join(this.dir, 'repos', `${id}.git`)\n }\n\n // The state as it was last read, and which file that was (a rewrite is a new inode, so another process's write is seen too): a read that\n // finds the file as it was does not parse it again. Frozen, because it is shared: whoever changes the state does it in `update`, on a copy.\n private cached: { signature: string, state: State } | null = null\n private recovered = false\n\n private parse(file: string): State {\n return JSON.parse(fs.readFileSync(file, 'utf8')) as State\n }\n\n private signature(): string | null {\n try {\n const stat = fs.statSync(this.file)\n return `${stat.ino}:${stat.size}:${stat.mtimeMs}`\n } catch {\n return null\n }\n }\n\n private load(): State {\n const signature = this.signature()\n if (signature && this.cached?.signature === signature) return this.cached.state\n this.recovered = false\n const state = this.read_()\n // (a copy recovered from a file that could not be read is not remembered: the file is still damaged)\n if (signature && !this.recovered && this.signature() === signature) this.cached = { signature, state: deepFreeze(state) }\n else this.cached = null\n return this.cached?.state ?? state\n }\n\n private read_(): State {\n try {\n return this.parse(this.file)\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return structuredClone(EMPTY)\n // a file that cannot be read (a write cut short, a disk that lied): the last good copy, if there is one, rather than a host that is down\n try {\n const recovered = this.parse(`${this.file}.bak`)\n this.recovered = true\n console.error(`[local git] ${this.file} could not be read (${(error as Error).message}): using the last good copy`)\n return recovered\n } catch {\n throw new Error(`${this.file} is damaged and there is no copy to recover from: ${(error as Error).message}`)\n }\n }\n }\n\n read<T>(fn: (state: State) => T): Promise<T> {\n return this.queue(() => fn(this.load()))\n }\n\n private async lockFile(): Promise<() => void> {\n fs.mkdirSync(this.dir, { recursive: true })\n for (let attempt = 0; ; attempt += 1) {\n try {\n const fd = fs.openSync(this.lock, 'wx')\n fs.writeSync(fd, String(process.pid))\n fs.closeSync(fd)\n return () => fs.rmSync(this.lock, { force: true })\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error\n let age = 0\n try { age = Date.now() - fs.statSync(this.lock).mtimeMs } catch { continue }\n if (age > STALE_MS) { fs.rmSync(this.lock, { force: true }); continue }\n if (attempt > 600) throw new Error(`${this.lock} is held by another process`)\n await sleep(20)\n }\n }\n }\n\n /** Writes the state so that a cut leaves the old file or the new one, never half: to a temporary file, to disk, over the old. */\n private write(state: State): void {\n const tmp = `${this.file}.${process.pid}.tmp`\n const fd = fs.openSync(tmp, 'w')\n try {\n fs.writeSync(fd, JSON.stringify(state, null, 2))\n fs.fsyncSync(fd)\n } finally {\n fs.closeSync(fd)\n }\n // the file that is about to be replaced is the last good one\n if (fs.existsSync(this.file)) fs.copyFileSync(this.file, `${this.file}.bak`)\n fs.renameSync(tmp, this.file)\n this.cached = null\n try {\n const directory = fs.openSync(this.dir, 'r')\n fs.fsyncSync(directory)\n fs.closeSync(directory)\n } catch { /* a platform that cannot sync a folder */ }\n }\n\n /** Changes the state: `fn` gets it and returns what the caller wants back; what it changed is saved when it is done. */\n update<T>(fn: (state: State) => T | Promise<T>): Promise<T> {\n return this.queue(async () => {\n const release = await this.lockFile()\n try {\n const state = structuredClone(this.load()) // a copy: `fn` may change it and then fail\n const before = JSON.stringify(state)\n const result = await fn(state)\n if (JSON.stringify(state) !== before) this.write(state)\n return result\n } finally {\n release()\n }\n })\n }\n\n private queue<T>(run: () => T | Promise<T>): Promise<T> {\n const previous = queues.get(this.file) ?? Promise.resolve()\n const current = previous.then(run, run)\n queues.set(this.file, current.catch(() => undefined))\n return current\n }\n\n /** Adds (or raises) a person's access to a repository: how an administrator lets someone else in. */\n addMember({ repositoryId, username, accessLevel }: { repositoryId: number | string, username: string, accessLevel: number }): Promise<void> {\n return this.update((state) => {\n const repository = state.repositories.find((candidate) => candidate.id === Number(repositoryId))\n if (!repository) throw Object.assign(new Error('There is no such repository'), { status: 404 })\n const known = repository.members.find((member) => member.username === username)\n if (known) known.accessLevel = accessLevel\n else repository.members.push({ username, accessLevel })\n })\n }\n}\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { PackageFiles, PackageSource } from '@lbdudc/linea-core';
|
|
2
|
+
import { GitHubClient } from '../github/client.js';
|
|
3
|
+
import { type GitHubConfig } from '../github/config.js';
|
|
4
|
+
export declare const isGitHubLocation: (location: unknown) => location is string;
|
|
5
|
+
export declare const githubLocationOf: (fullName: string) => string;
|
|
6
|
+
/** The files of a repository at `ref`, as linea-core's `PackageFiles`. */
|
|
7
|
+
export declare const githubFiles: ({ client, token, userId, fullName, ref, immutable }: {
|
|
8
|
+
client: GitHubClient;
|
|
9
|
+
token: string | undefined;
|
|
10
|
+
userId: string;
|
|
11
|
+
fullName: string;
|
|
12
|
+
ref: string;
|
|
13
|
+
immutable?: boolean;
|
|
14
|
+
}) => PackageFiles;
|
|
15
|
+
export interface GitHubSourceOptions {
|
|
16
|
+
config?: GitHubConfig;
|
|
17
|
+
/** The user's own token; without it `config.token`, and without that, no token at all (public repositories). */
|
|
18
|
+
token?: string | undefined;
|
|
19
|
+
userId?: string | number;
|
|
20
|
+
client?: GitHubClient;
|
|
21
|
+
/** `null`: the list exists but names no GitHub owner, so nothing is trusted. Empty: anywhere. */
|
|
22
|
+
allowedOwners?: string[] | null;
|
|
23
|
+
overrides?: Record<string, {
|
|
24
|
+
version: string;
|
|
25
|
+
ref: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
export declare class GitHubPackageSource implements PackageSource {
|
|
29
|
+
private readonly client;
|
|
30
|
+
private readonly token;
|
|
31
|
+
private readonly userId;
|
|
32
|
+
private readonly allowed;
|
|
33
|
+
private readonly overrides;
|
|
34
|
+
private readonly refOf;
|
|
35
|
+
constructor({ config, token, userId, client, allowedOwners, overrides }?: GitHubSourceOptions);
|
|
36
|
+
private guard;
|
|
37
|
+
listVersions({ location }: {
|
|
38
|
+
location: string;
|
|
39
|
+
}): Promise<string[]>;
|
|
40
|
+
private ref;
|
|
41
|
+
open({ location, version }: {
|
|
42
|
+
location: string;
|
|
43
|
+
version: string;
|
|
44
|
+
}): Promise<PackageFiles>;
|
|
45
|
+
revision({ location, version }: {
|
|
46
|
+
location: string;
|
|
47
|
+
version: string;
|
|
48
|
+
}): Promise<string | undefined>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The repositories of `owners` (users or organisations) that carry a topic (`linea-module`, `linea-metamodel`), with their versions:
|
|
52
|
+
* what the registry page lists next to the GitLab packages.
|
|
53
|
+
*/
|
|
54
|
+
export declare const discoverGitHubPackages: ({ topic, owners, source, client, token }: {
|
|
55
|
+
topic: string;
|
|
56
|
+
owners: string[];
|
|
57
|
+
source: GitHubPackageSource;
|
|
58
|
+
client: GitHubClient;
|
|
59
|
+
token?: string | undefined;
|
|
60
|
+
}) => Promise<{
|
|
61
|
+
repo: {
|
|
62
|
+
full_name: string;
|
|
63
|
+
name: string;
|
|
64
|
+
description: string | null;
|
|
65
|
+
html_url: string;
|
|
66
|
+
};
|
|
67
|
+
location: string;
|
|
68
|
+
versions: string[];
|
|
69
|
+
}[]>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { PackageNotAllowedError } from '../errors.js';
|
|
2
|
+
import { GitHubClient } from '../github/client.js';
|
|
3
|
+
import { githubApiUrl } from '../github/config.js';
|
|
4
|
+
/**
|
|
5
|
+
* Where the modules and metamodels of an SPL can also come from: GitHub repositories, one version per git tag (`v1.2.3`).
|
|
6
|
+
* A package's location is `github:<owner>/<repo>`, and `../x` in a manifest means the sibling repository of the same owner, exactly as
|
|
7
|
+
* it does on GitLab. It implements linea-core's `PackageSource`.
|
|
8
|
+
*
|
|
9
|
+
* It needs no account for public repositories (GitHub allows 60 requests an hour without a token); a token raises that and
|
|
10
|
+
* gives access to private ones.
|
|
11
|
+
*/
|
|
12
|
+
const PREFIX = 'github:';
|
|
13
|
+
const VERSION_TAG = /^v?(\d+\.\d+\.\d+)$/;
|
|
14
|
+
export const isGitHubLocation = (location) => typeof location === 'string' && /^github:[^/]+\/[^/]+$/.test(location);
|
|
15
|
+
export const githubLocationOf = (fullName) => `${PREFIX}${fullName}`;
|
|
16
|
+
const pathOf = (location) => location.slice(PREFIX.length);
|
|
17
|
+
const CACHE_LIMIT = 2000;
|
|
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, value);
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
const encodePath = (path) => path.split('/').map(encodeURIComponent).join('/');
|
|
26
|
+
/** The files of a repository at `ref`, as linea-core's `PackageFiles`. */
|
|
27
|
+
export const githubFiles = ({ client, token, userId, fullName, ref, immutable = false }) => {
|
|
28
|
+
const scope = `${userId}|${fullName}|${ref}`;
|
|
29
|
+
return {
|
|
30
|
+
read: async ({ path }) => {
|
|
31
|
+
const key = `${scope}|file|${path}`;
|
|
32
|
+
if (immutable && cache.has(key))
|
|
33
|
+
return cache.get(key) ?? undefined;
|
|
34
|
+
const bytes = await client.raw({ token, path: `/repos/${fullName}/contents/${encodePath(path)}?ref=${encodeURIComponent(ref)}` });
|
|
35
|
+
const value = bytes === null ? null : new Uint8Array(bytes);
|
|
36
|
+
if (immutable)
|
|
37
|
+
remember(key, value);
|
|
38
|
+
return value ?? undefined;
|
|
39
|
+
},
|
|
40
|
+
list: async ({ dir }) => {
|
|
41
|
+
const key = `${scope}|tree`;
|
|
42
|
+
let paths = immutable ? cache.get(key) : undefined;
|
|
43
|
+
if (!paths) {
|
|
44
|
+
const tree = await client.json({ token, path: `/repos/${fullName}/git/trees/${encodeURIComponent(ref)}?recursive=1` });
|
|
45
|
+
paths = tree.tree.filter((entry) => entry.type === 'blob').map((entry) => entry.path);
|
|
46
|
+
if (immutable)
|
|
47
|
+
remember(key, paths);
|
|
48
|
+
}
|
|
49
|
+
const prefix = dir.replace(/^\/+|\/+$/g, '');
|
|
50
|
+
return prefix === '' ? paths : paths.filter((file) => file.startsWith(`${prefix}/`));
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export class GitHubPackageSource {
|
|
55
|
+
client;
|
|
56
|
+
token;
|
|
57
|
+
userId;
|
|
58
|
+
allowed;
|
|
59
|
+
overrides;
|
|
60
|
+
refOf = new Map();
|
|
61
|
+
constructor({ config = {}, token, userId = 'anonymous', client, allowedOwners = [], overrides = {} } = {}) {
|
|
62
|
+
this.client = client ?? new GitHubClient({ apiUrl: githubApiUrl(config) });
|
|
63
|
+
this.token = token ?? config.token;
|
|
64
|
+
// (kept by who and where: two GitHub servers can have a repository of the same name)
|
|
65
|
+
this.userId = `${githubApiUrl(config)}|${String(userId)}`;
|
|
66
|
+
this.allowed = allowedOwners;
|
|
67
|
+
this.overrides = overrides;
|
|
68
|
+
}
|
|
69
|
+
guard(location) {
|
|
70
|
+
if (!isGitHubLocation(location))
|
|
71
|
+
throw new PackageNotAllowedError(`"${location}" is not a GitHub location (github:owner/repo).`);
|
|
72
|
+
const fullName = pathOf(location);
|
|
73
|
+
const owner = fullName.split('/')[0];
|
|
74
|
+
if (this.allowed === null || (this.allowed.length > 0 && !this.allowed.some((entry) => entry === owner || entry === fullName))) {
|
|
75
|
+
throw new PackageNotAllowedError(`${location} is outside the trusted namespaces.`);
|
|
76
|
+
}
|
|
77
|
+
return fullName;
|
|
78
|
+
}
|
|
79
|
+
async listVersions({ location }) {
|
|
80
|
+
const fullName = this.guard(location);
|
|
81
|
+
const override = this.overrides[location];
|
|
82
|
+
if (override)
|
|
83
|
+
return [override.version];
|
|
84
|
+
const versions = [];
|
|
85
|
+
try {
|
|
86
|
+
const tags = await this.client.paginate({ token: this.token, path: `/repos/${fullName}/tags` });
|
|
87
|
+
for (const tag of tags) {
|
|
88
|
+
const match = VERSION_TAG.exec(tag.name);
|
|
89
|
+
if (!match)
|
|
90
|
+
continue;
|
|
91
|
+
this.refOf.set(`${location}@${match[1]}`, tag.name);
|
|
92
|
+
versions.push(match[1]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (error.status === 404)
|
|
97
|
+
return [];
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
return versions;
|
|
101
|
+
}
|
|
102
|
+
ref(location, version) {
|
|
103
|
+
return this.overrides[location]?.ref ?? this.refOf.get(`${location}@${version}`) ?? `v${version}`;
|
|
104
|
+
}
|
|
105
|
+
async open({ location, version }) {
|
|
106
|
+
const fullName = this.guard(location);
|
|
107
|
+
return githubFiles({ client: this.client, token: this.token, userId: this.userId, fullName, ref: this.ref(location, version), immutable: !this.overrides[location] });
|
|
108
|
+
}
|
|
109
|
+
async revision({ location, version }) {
|
|
110
|
+
const fullName = this.guard(location);
|
|
111
|
+
if (this.overrides[location])
|
|
112
|
+
return undefined;
|
|
113
|
+
const commit = await this.client.json({ token: this.token, path: `/repos/${fullName}/commits/${encodeURIComponent(this.ref(location, version))}` });
|
|
114
|
+
return commit?.sha;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The repositories of `owners` (users or organisations) that carry a topic (`linea-module`, `linea-metamodel`), with their versions:
|
|
119
|
+
* what the registry page lists next to the GitLab packages.
|
|
120
|
+
*/
|
|
121
|
+
export const discoverGitHubPackages = async ({ topic, owners, source, client, token }) => {
|
|
122
|
+
const found = [];
|
|
123
|
+
for (const owner of owners) {
|
|
124
|
+
const result = await client.json({ token, path: `/search/repositories?q=${encodeURIComponent(`topic:${topic} user:${owner}`)}&per_page=100` });
|
|
125
|
+
for (const repo of (result.items ?? [])) {
|
|
126
|
+
const location = githubLocationOf(repo.full_name);
|
|
127
|
+
const versions = await source.listVersions({ location }).catch(() => []);
|
|
128
|
+
found.push({ repo, location, versions });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return found;
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=github-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-source.js","sourceRoot":"","sources":["../../src/packages/github-source.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAqB,MAAM,qBAAqB,CAAA;AAErE;;;;;;;GAOG;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,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AACjJ,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAU,EAAE,CAAC,GAAG,MAAM,GAAG,QAAQ,EAAE,CAAA;AACpF,MAAM,MAAM,GAAG,CAAC,QAAgB,EAAU,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;AAE1E,MAAM,WAAW,GAAG,IAAI,CAAA;AACxB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAmB,CAAA;AACxC,MAAM,QAAQ,GAAG,CAAI,GAAW,EAAE,KAAQ,EAAK,EAAE;IAC/C,IAAI,KAAK,CAAC,IAAI,IAAI,WAAW;QAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAe,CAAC,CAAA;IAChF,KAAK,CAAC,GAA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AE,CAAwF,EAAE,CAAC;YAC/H,MAAM,QAAQ,GAAG,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YACjD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAc,CAAC,CAAA;YACpF,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAA;QAC1C,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import type { PackageFiles, PackageSource } from '@lbdudc/linea-core'\nimport { PackageNotAllowedError } from '../errors.js'\nimport { GitHubClient } from '../github/client.js'\nimport { githubApiUrl, type GitHubConfig } from '../github/config.js'\n\n/**\n * Where the modules and metamodels of an SPL can also come from: GitHub repositories, one version per git tag (`v1.2.3`).\n * A package's location is `github:<owner>/<repo>`, and `../x` in a manifest means the sibling repository of the same owner, exactly as\n * it does on GitLab. It implements linea-core's `PackageSource`.\n *\n * It needs no account for public repositories (GitHub allows 60 requests an hour without a token); a token raises that and\n * gives access to private ones.\n */\n\nconst PREFIX = 'github:'\nconst VERSION_TAG = /^v?(\\d+\\.\\d+\\.\\d+)$/\n\nexport const isGitHubLocation = (location: unknown): location is string => typeof location === 'string' && /^github:[^/]+\\/[^/]+$/.test(location)\nexport const githubLocationOf = (fullName: string): string => `${PREFIX}${fullName}`\nconst pathOf = (location: string): string => location.slice(PREFIX.length)\n\nconst CACHE_LIMIT = 2000\nconst cache = new Map<string, 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, value)\n return value\n}\nconst encodePath = (path: string): string => path.split('/').map(encodeURIComponent).join('/')\n\n/** The files of a repository at `ref`, as linea-core's `PackageFiles`. */\nexport const githubFiles = ({ client, token, userId, fullName, ref, immutable = false }: { client: GitHubClient, token: string | undefined, userId: string, fullName: string, ref: string, immutable?: boolean }): PackageFiles => {\n const scope = `${userId}|${fullName}|${ref}`\n return {\n read: async ({ path }) => {\n const key = `${scope}|file|${path}`\n if (immutable && cache.has(key)) return (cache.get(key) as Uint8Array | null) ?? undefined\n const bytes = await client.raw({ token, path: `/repos/${fullName}/contents/${encodePath(path)}?ref=${encodeURIComponent(ref)}` })\n const value = bytes === null ? null : new Uint8Array(bytes)\n if (immutable) remember(key, value)\n return value ?? undefined\n },\n list: async ({ dir }) => {\n const key = `${scope}|tree`\n let paths = immutable ? (cache.get(key) as string[] | undefined) : undefined\n if (!paths) {\n const tree = await client.json({ token, path: `/repos/${fullName}/git/trees/${encodeURIComponent(ref)}?recursive=1` })\n paths = (tree.tree as { type: string, path: string }[]).filter((entry) => entry.type === 'blob').map((entry) => entry.path)\n if (immutable) remember(key, paths)\n }\n const prefix = dir.replace(/^\\/+|\\/+$/g, '')\n return prefix === '' ? paths : paths.filter((file) => file.startsWith(`${prefix}/`))\n }\n }\n}\n\nexport interface GitHubSourceOptions {\n config?: GitHubConfig\n /** The user's own token; without it `config.token`, and without that, no token at all (public repositories). */\n token?: string | undefined\n userId?: string | number\n client?: GitHubClient\n /** `null`: the list exists but names no GitHub owner, so nothing is trusted. Empty: anywhere. */\n allowedOwners?: string[] | null\n overrides?: Record<string, { version: string, ref: string }>\n}\n\nexport class GitHubPackageSource implements PackageSource {\n private readonly client: GitHubClient\n private readonly token: string | undefined\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\n constructor({ config = {}, token, userId = 'anonymous', client, allowedOwners = [], overrides = {} }: GitHubSourceOptions = {}) {\n this.client = client ?? new GitHubClient({ apiUrl: githubApiUrl(config) })\n this.token = token ?? config.token\n // (kept by who and where: two GitHub servers can have a repository of the same name)\n this.userId = `${githubApiUrl(config)}|${String(userId)}`\n this.allowed = allowedOwners\n this.overrides = overrides\n }\n\n private guard(location: string): string {\n if (!isGitHubLocation(location)) throw new PackageNotAllowedError(`\"${location}\" is not a GitHub location (github:owner/repo).`)\n const fullName = pathOf(location)\n const owner = fullName.split('/')[0] as string\n if (this.allowed === null || (this.allowed.length > 0 && !this.allowed.some((entry) => entry === owner || entry === fullName))) {\n throw new PackageNotAllowedError(`${location} is outside the trusted namespaces.`)\n }\n return fullName\n }\n\n async listVersions({ location }: { location: string }): Promise<string[]> {\n const fullName = this.guard(location)\n const override = this.overrides[location]\n if (override) return [override.version]\n const versions: string[] = []\n try {\n const tags = await this.client.paginate({ token: this.token, path: `/repos/${fullName}/tags` })\n for (const tag of tags) {\n const match = VERSION_TAG.exec(tag.name as string)\n if (!match) continue\n this.refOf.set(`${location}@${match[1]}`, tag.name as string)\n versions.push(match[1] as string)\n }\n } catch (error) {\n if ((error as { status?: number }).status === 404) return []\n throw error\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 const fullName = this.guard(location)\n return githubFiles({ client: this.client, token: this.token, userId: this.userId, fullName, ref: this.ref(location, version), immutable: !this.overrides[location] })\n }\n\n async revision({ location, version }: { location: string, version: string }): Promise<string | undefined> {\n const fullName = this.guard(location)\n if (this.overrides[location]) return undefined\n const commit = await this.client.json({ token: this.token, path: `/repos/${fullName}/commits/${encodeURIComponent(this.ref(location, version))}` })\n return commit?.sha as string | undefined\n }\n}\n\n/**\n * The repositories of `owners` (users or organisations) that carry a topic (`linea-module`, `linea-metamodel`), with their versions:\n * what the registry page lists next to the GitLab packages.\n */\nexport const discoverGitHubPackages = async ({ topic, owners, source, client, token }: { topic: string, owners: string[], source: GitHubPackageSource, client: GitHubClient, token?: string | undefined }): Promise<{ repo: { full_name: string, name: string, description: string | null, html_url: string }, location: string, versions: string[] }[]> => {\n const found = []\n for (const owner of owners) {\n const result = await client.json({ token, path: `/search/repositories?q=${encodeURIComponent(`topic:${topic} user:${owner}`)}&per_page=100` })\n for (const repo of (result.items ?? []) as { full_name: string, name: string, description: string | null, html_url: string }[]) {\n const location = githubLocationOf(repo.full_name)\n const versions = await source.listVersions({ location }).catch(() => [] as string[])\n found.push({ repo, location, versions })\n }\n }\n return found\n}\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type PackageFiles, type PackageSource } from '@lbdudc/linea-core';
|
|
2
|
+
import { type GitLabClient } from '../gitlab/client.js';
|
|
3
|
+
export declare const isGitLabLocation: (location: unknown) => location is string;
|
|
4
|
+
export declare const gitlabLocationOf: (pathWithNamespace: string) => string;
|
|
5
|
+
/** 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). */
|
|
6
|
+
export declare const forgetPackageTags: (location: string) => void;
|
|
7
|
+
/**
|
|
8
|
+
* 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.
|
|
9
|
+
* `id` is the numeric project id, or the URL-encoded path.
|
|
10
|
+
*/
|
|
11
|
+
export declare const gitlabFiles: ({ client, token, userId, id, ref, immutable }: {
|
|
12
|
+
client: GitLabClient;
|
|
13
|
+
token: string;
|
|
14
|
+
userId: string;
|
|
15
|
+
id: string | number;
|
|
16
|
+
ref: string;
|
|
17
|
+
immutable?: boolean;
|
|
18
|
+
}) => PackageFiles;
|
|
19
|
+
export interface GitLabSourceOptions {
|
|
20
|
+
url: string;
|
|
21
|
+
token: string;
|
|
22
|
+
userId: string | number;
|
|
23
|
+
/** `null`: the list exists but names no GitLab path, so nothing is trusted. Empty: anywhere. */
|
|
24
|
+
allowedNamespaces?: string[] | null;
|
|
25
|
+
/** Packages read from a branch as one version, instead of from their tags: to check what has not been published yet. */
|
|
26
|
+
overrides?: Record<string, {
|
|
27
|
+
version: string;
|
|
28
|
+
ref: string;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Whoever asked has gone (the browser closed the request): the source takes no further step. It is checked between GitLab calls, not
|
|
32
|
+
* 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.
|
|
33
|
+
*/
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
}
|
|
36
|
+
export declare class GitLabPackageSource implements PackageSource {
|
|
37
|
+
private readonly client;
|
|
38
|
+
private readonly token;
|
|
39
|
+
private readonly userId;
|
|
40
|
+
private readonly allowed;
|
|
41
|
+
private readonly overrides;
|
|
42
|
+
private readonly refOf;
|
|
43
|
+
private readonly signal;
|
|
44
|
+
constructor({ url, token, userId, allowedNamespaces, overrides, signal }: GitLabSourceOptions);
|
|
45
|
+
private guard;
|
|
46
|
+
listVersions({ location }: {
|
|
47
|
+
location: string;
|
|
48
|
+
}): Promise<string[]>;
|
|
49
|
+
private ref;
|
|
50
|
+
open({ location, version }: {
|
|
51
|
+
location: string;
|
|
52
|
+
version: string;
|
|
53
|
+
}): Promise<PackageFiles>;
|
|
54
|
+
revision({ location, version }: {
|
|
55
|
+
location: string;
|
|
56
|
+
version: string;
|
|
57
|
+
}): Promise<string | undefined>;
|
|
58
|
+
}
|
|
59
|
+
export { withOverlay } from '@lbdudc/linea-core';
|