@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.
- 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
package/dist/provider.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The git host LINEA works on (GitLab, or GitHub): everything LINEA needs from it, in the host's own words left out.
|
|
3
|
+
*
|
|
4
|
+
* A deployment talks to ONE host. The server and the CLI never speak a host's API: they take a `GitProvider` (`createGitProvider`) and
|
|
5
|
+
* use only the methods below, with the shapes below. What differs between hosts is hidden in the provider: GitLab calls the same things
|
|
6
|
+
* groups, projects and merge requests; GitHub calls them organisations, repositories and pull requests, and has no groups inside
|
|
7
|
+
* groups (see docs/git-provider.md for how each difference is absorbed).
|
|
8
|
+
*
|
|
9
|
+
* A provider object is also a unit of work: what it creates (namespaces, repositories, files, commits, branches, tags) is remembered,
|
|
10
|
+
* and `rollback()` undoes it, newest first. Make one per operation.
|
|
11
|
+
*
|
|
12
|
+
* Every method takes the user's access `token` first. `id` is the repository id (or its `path`), `namespaceId` the id of a namespace.
|
|
13
|
+
*/
|
|
14
|
+
/** The methods a provider has to have: what the contract test checks and what a new host has to fill in. */
|
|
15
|
+
export const GIT_PROVIDER_METHODS = [
|
|
16
|
+
'authConfig', 'exchangeCode', 'refreshToken', 'getUser',
|
|
17
|
+
'listNamespaces', 'findNamespace', 'createNamespace', 'deleteNamespace', 'renameNamespace',
|
|
18
|
+
'createRepository', 'deleteRepository', 'listPendingDeletion', 'restoreRepository', 'restoreNamespace', 'renameRepository', 'getRepository', 'findRepository', 'listRepositories', 'addTopic',
|
|
19
|
+
'setDefaultBranch', 'getMembers', 'getAccessLevel',
|
|
20
|
+
'getFile', 'getFileRevision', 'readFile', 'listFiles', 'createFile', 'saveFile', 'commit', 'downloadArchive', 'getCommits', 'compare',
|
|
21
|
+
'createBranch', 'listBranches', 'getBranch', 'listTags', 'getTag', 'createTag',
|
|
22
|
+
'createRelease', 'getRelease', 'listReleases', 'updateRelease',
|
|
23
|
+
'createChangeRequest', 'createOrRenameChangeRequest', 'listChangeRequests', 'listChangeRequestPipelines', 'mergeChangeRequest',
|
|
24
|
+
'getLatestPipeline', 'listPipelines', 'getPipelineJobs', 'retryPipeline', 'cancelPipeline', 'cancelJob', 'enablePipelines', 'disablePipelines', 'pipelinesEnabled', 'getCiRunners', 'setInstanceRunners', 'getJobTrace', 'ensureWebhook', 'verifyWebhook', 'parsePushEvent',
|
|
25
|
+
'listMergeRequests', 'getMergeRequest', 'createMergeRequest', 'updateMergeRequest', 'getMergeRequestDiff', 'listMergeRequestThreads', 'addMergeRequestComment', 'setThreadResolved', 'mergeMergeRequest', 'approveMergeRequest',
|
|
26
|
+
'capabilities', 'listIssues', 'getIssue', 'createIssue', 'updateIssue', 'listIssueComments', 'addIssueComment', 'listLabels', 'listMilestones', 'listTemplates', 'saveTemplate', 'deleteTemplate',
|
|
27
|
+
'rollback', 'isAuthError', 'isAlreadyExistsError'
|
|
28
|
+
];
|
|
29
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAmjBH,4GAA4G;AAC5G,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,SAAS;IACvD,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB;IAC1F,kBAAkB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,UAAU;IAC7L,kBAAkB,EAAE,YAAY,EAAE,gBAAgB;IAClD,SAAS,EAAE,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,iBAAiB,EAAE,YAAY,EAAE,SAAS;IACrI,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW;IAC9E,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe;IAC9D,qBAAqB,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,oBAAoB;IAC9H,mBAAmB,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,cAAc,EAAE,oBAAoB,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB;IAC3Q,mBAAmB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,qBAAqB;IAC/N,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB;IACjM,UAAU,EAAE,aAAa,EAAE,sBAAsB;CACzC,CAAA","sourcesContent":["/**\n * The git host LINEA works on (GitLab, or GitHub): everything LINEA needs from it, in the host's own words left out.\n *\n * A deployment talks to ONE host. The server and the CLI never speak a host's API: they take a `GitProvider` (`createGitProvider`) and\n * use only the methods below, with the shapes below. What differs between hosts is hidden in the provider: GitLab calls the same things\n * groups, projects and merge requests; GitHub calls them organisations, repositories and pull requests, and has no groups inside\n * groups (see docs/git-provider.md for how each difference is absorbed).\n *\n * A provider object is also a unit of work: what it creates (namespaces, repositories, files, commits, branches, tags) is remembered,\n * and `rollback()` undoes it, newest first. Make one per operation.\n *\n * Every method takes the user's access `token` first. `id` is the repository id (or its `path`), `namespaceId` the id of a namespace.\n */\n\nexport type Id = number | string\n\nexport interface Repository {\n id: Id\n name: string\n /** Full path as the host shows it: `group/sub/name`, `owner/name`. */\n path: string\n description: string\n webUrl: string\n webIdeUrl: string\n namespaceId: Id | undefined\n /** The namespace that contains this repository's namespace (for a product: the one that is its line). */\n parentNamespaceId?: Id | undefined\n defaultBranch?: string | undefined\n topics: string[]\n /** When the host made it (a host that does not keep it says nothing). */\n createdAt?: string | undefined\n}\n\nexport interface Namespace {\n id: Id\n fullPath: string\n name: string\n /** Made by `createNamespace` but not yet on the host: the repository that follows is what creates it. */\n pending?: boolean\n}\n\nexport interface Member {\n username: string\n /** 10 guest, 20 reporter/read, 30 developer/write, 40 maintainer, 50 owner/admin. */\n accessLevel: number\n}\n\nexport interface RepositoryFile {\n path: string\n name: string\n /** base64 */\n content: string\n encoding: 'base64'\n /** What to quote to say \"I changed this file starting from this version\" (GitLab: last commit id; GitHub: blob sha). */\n revision: string\n}\n\nexport interface CommitSummary {\n shortId: string\n title: string\n authorName: string\n createdAt: string\n webUrl?: string | undefined\n /** The whole message (title, blank line, body), when the host gives it. */\n message?: string | undefined\n}\n\n/** A merge request (GitLab) or a pull request (GitHub). */\nexport interface ChangeRequest {\n number: number\n title: string\n sourceBranch: string\n targetBranch: string\n webUrl: string\n hasConflicts: boolean\n /** `opened`, `merged` or `closed`. Only the lists that ask for every state fill what follows. */\n state?: 'opened' | 'merged' | 'closed' | undefined\n author?: string | undefined\n createdAt?: string | undefined\n mergedAt?: string | null | undefined\n /** The commit at the tip of the source branch: the one its checks are for. */\n headSha?: string | undefined\n}\n\n/** An issue, as every host shows it. `number` is the one of the repository (GitLab `iid`, GitHub `number`). */\n/** The difference between two refs: what `to` brought since it left `from`. */\nexport interface Comparison {\n commits: CommitSummary[]\n files: FileDiff[]\n}\n\nexport interface Issue {\n number: number\n title: string\n /** Markdown. */\n description: string\n state: 'opened' | 'closed'\n author: string | undefined\n assignees: string[]\n labels: string[]\n /** The title of the milestone it belongs to. */\n milestone: string | null\n createdAt: string\n updatedAt: string\n closedAt: string | null\n /** The page of the issue on the host (empty for a host that has no pages). */\n webUrl: string\n commentCount: number\n}\n\n/** One message of the thread of an issue. */\nexport interface Comment {\n id: Id\n author: string | undefined\n /** Markdown. */\n body: string\n createdAt: string\n updatedAt: string\n}\n\n/** A release of a tag: what the host shows as the release notes of a version. `tag` is its key (one release per tag). */\nexport interface Release {\n tag: string\n name: string\n /** Markdown. */\n description: string\n createdAt: string\n /** The page of it on the host (empty for a host that has no pages). */\n url: string\n prerelease: boolean\n}\n\nexport interface ReleaseChanges {\n name?: string\n description?: string\n prerelease?: boolean\n}\n\nexport interface Label {\n name: string\n /** `#rrggbb`, when the host has colours for labels. */\n color?: string | undefined\n}\n\nexport interface Milestone {\n title: string\n state: 'opened' | 'closed'\n dueDate?: string | null | undefined\n}\n\nexport interface IssueFilter {\n /** Default `opened`. */\n state?: 'opened' | 'closed' | 'all'\n author?: string\n assignee?: string\n /** All of them. */\n labels?: string[]\n /** The title of a milestone. */\n milestone?: string\n /** Text in the title or the description. */\n search?: string\n /** From 1. */\n page?: number\n /** Default 20, at most 100. */\n perPage?: number\n}\n\n/** One page of a list. A host does not always know how many there are in all: `hasMore` is what every host can say. */\nexport interface Page<T> {\n items: T[]\n page: number\n perPage: number\n hasMore: boolean\n}\n\nexport interface IssueChanges {\n title?: string\n description?: string\n labels?: string[]\n assignees?: string[]\n /** The title of a milestone; `null` takes the issue out of its milestone. */\n milestone?: string | null\n state?: 'opened' | 'closed'\n}\n\n/**\n * What a host can do beyond the common part. The UI offers only what is `true`, and a call for something that is not is refused with\n * status 400 rather than ignored.\n */\n/** A repository the host is about to delete for good. */\nexport interface PendingDeletion {\n id: Id\n name: string\n /** Where it was, as it was called before the host renamed it for the deletion. */\n path: string\n /** Its page now, with whatever name the host gave it for the deletion: the only address that opens. */\n webUrl: string\n namespaceId: Id | undefined\n /** The namespace that contains this repository's namespace (for a product: the one that is its line). */\n parentNamespaceId?: Id | undefined\n /** The day the host deletes it for good; `null` when the host does not say. */\n deletesOn: string | null\n /** When the host made the repository, if it says. */\n createdAt?: string\n repositoryScheduled: boolean\n namespaceScheduled: boolean\n /** Something above its namespace waits to be deleted: it cannot come back before that does. */\n ancestorScheduled: boolean\n}\n\nexport type TemplateKind = 'issue' | 'mergeRequest'\n\nexport interface Template {\n name: string\n content: string\n}\n\nexport interface Capabilities {\n issues: {\n labels: boolean\n milestones: boolean\n assignees: boolean\n closingWords: boolean\n }\n templates: {\n editable: boolean\n }\n mergeRequests: {\n labels: boolean\n reviewers: boolean\n /** Approvals can be given (and counted). */\n approvals: boolean\n /** A thread of the code can be marked resolved. */\n resolvableThreads: boolean\n /** A merge can leave one commit. */\n squash: boolean\n }\n deletion: {\n namespaceIsRepository: boolean\n delayed: boolean\n }\n releases: {\n /** A release can be marked as a prerelease (GitLab has no such mark: it ignores it and always says `false`). */\n prerelease: boolean\n }\n}\n\n/** A merge request (GitLab) or a pull request (GitHub) as the pages of LINEA show it: more than `ChangeRequest`, which is what the code needs. */\nexport interface MergeRequest {\n number: number\n title: string\n /** Markdown. */\n description: string\n state: 'opened' | 'merged' | 'closed'\n author: string | undefined\n sourceBranch: string\n targetBranch: string\n labels: string[]\n reviewers: string[]\n assignees: string[]\n createdAt: string\n updatedAt: string\n mergedAt: string | null\n /** The page of it on the host (empty for a host that has no pages). */\n webUrl: string\n hasConflicts: boolean\n /** The commit at the tip of the source branch: the one its checks are for. */\n headSha: string | undefined\n /** Messages of people in all its threads. */\n commentCount: number\n /** Who approved it, and how many approvals it asks for (`null`: it does not say). Only on a host that has approvals. */\n approvals?: { required: number | null, given: string[] } | undefined\n}\n\nexport interface MergeRequestFilter {\n /** Default `opened`. */\n state?: 'opened' | 'merged' | 'closed' | 'all'\n author?: string\n reviewer?: string\n labels?: string[]\n search?: string\n sourceBranch?: string\n targetBranch?: string\n page?: number\n perPage?: number\n}\n\n/** One file of the code a merge request proposes. `patch` is the unified diff from the first `@@` on (empty for a file git cannot show, as a binary one). */\nexport interface FileDiff {\n oldPath: string\n newPath: string\n status: 'added' | 'modified' | 'deleted' | 'renamed'\n additions: number\n deletions: number\n patch: string\n}\n\n/** A line of the code of a merge request: of the new version of the file, or (`old`) of the one it replaces. */\nexport interface DiffPosition {\n path: string\n line: number\n side: 'new' | 'old'\n}\n\n/** A conversation of a merge request: a message of its own, or a line of the code with what was said about it. */\nexport interface Thread {\n id: Id\n /** The host can mark it resolved (GitHub can only through an API LINEA does not use). */\n resolvable: boolean\n resolved: boolean\n /** The line it is about; none for a general message. */\n position?: DiffPosition | undefined\n comments: Comment[]\n}\n\nexport interface MergeOptions {\n /** One commit in the target instead of the history of the branch. */\n squash?: boolean\n deleteSourceBranch?: boolean\n /** The message of the commit that is made. */\n message?: string\n}\n\nexport interface MergeRequestChanges {\n title?: string\n description?: string\n labels?: string[]\n reviewers?: string[]\n /** Closing and reopening are `state`. */\n state?: 'opened' | 'closed'\n}\n\nexport interface FileAction {\n action: 'create' | 'update' | 'delete'\n path: string\n content?: string\n /** How `content` is written (default text). */\n encoding?: 'text' | 'base64'\n /** Refuse the change when the file moved on from this revision (status 409). */\n expectedRevision?: string\n}\n\nexport interface Pipeline {\n /** The id the host gives it, for asking about its jobs or running it again. */\n id?: Id\n /** The commit it ran for. */\n sha?: string\n /** `success`, `failed`, `running`, `pending`, `canceled`, `skipped`. */\n status: string\n ref: string\n createdAt: string\n webUrl: string\n}\n\n/** One step of a pipeline (a job of GitLab, a job of a workflow run of GitHub). */\nexport interface PipelineJob {\n id: Id\n name: string\n /** The stage it belongs to (GitHub has none: its jobs are all `jobs`). */\n stage: string\n /** `success`, `failed`, `running`, `pending`, `canceled`, `skipped`. */\n status: string\n /** Seconds, when it has started. */\n duration: number | null\n webUrl: string\n}\n\n/** A runner of the host's CI, as it shows for a repository. */\nexport interface Runner {\n id: Id\n description: string\n online: boolean\n paused: boolean\n /** A runner shared by the whole instance (not one of the repository). */\n shared: boolean\n /** Jobs that ask for none of these tags are not run by it, unless it takes untagged jobs. */\n tags: string[]\n runsUntagged: boolean\n}\n\n/** What the host's CI offers a repository: whether it has runners to take its jobs. */\nexport interface CiRunners {\n /** `false` for a host that runs no pipelines (or whose runners cannot be asked for). */\n supported: boolean\n /** Whether the runners of the whole instance take this repository's jobs (`null`: not asked, or not a thing of this host). */\n instanceRunners: boolean | null\n /** `false` when the host would not list them for this token: `runners` being empty then says nothing. */\n listed?: boolean\n runners: Runner[]\n}\n\nexport interface Tokens {\n accessToken: string\n refreshToken: string | null\n}\n\nexport interface AuthConfig {\n kind: GitHostKind\n clientId: string | undefined\n redirectUri: string\n /** The address of the host's website. */\n url: string\n /** Where a browser is sent to log in; add `client_id`, `redirect_uri`, `response_type=code`, `scope` and `state`. */\n authorizeUrl: string\n /** What to ask the user to allow. */\n scope: string\n}\n\nexport type GitHostKind = 'local' | 'gitlab' | 'github'\n\nexport interface Delivery {\n headers: Record<string, string | undefined>\n rawBody?: Buffer | string\n secret?: string\n}\n\nexport interface GitProvider {\n readonly kind: GitHostKind\n /** Whether a namespace can hold namespaces (GitLab groups do; a GitHub account cannot). */\n readonly nestsNamespaces: boolean\n readonly webhookPath: string\n\n // Identity\n authConfig(): AuthConfig\n exchangeCode(args: { code: string, redirectUri: string }): Promise<Tokens>\n /** Keeps `accessToken` when the host's tokens do not expire. */\n refreshToken(args: { refreshToken: string | null, accessToken: string }): Promise<Tokens>\n getUser(args: { token: string }): Promise<{ username: string, avatarUrl: string }>\n\n // Namespaces: the place repositories live in\n /** Where the user may create things. */\n listNamespaces(args: { token: string }): Promise<Namespace[]>\n findNamespace(args: { token: string, fullPath: string }): Promise<Namespace | null>\n createNamespace(args: { token: string, name: string, parentId?: Id | undefined }): Promise<Namespace>\n /** With everything in it. */\n deleteNamespace(args: { token: string, id: Id }): Promise<unknown>\n renameNamespace(args: { token: string, id: Id, name: string }): Promise<unknown>\n\n // Repositories\n createRepository(args: { token: string, name: string, namespaceId?: Id | undefined, topics?: string[], defaultBranch?: string | undefined }): Promise<Repository>\n deleteRepository(args: { token: string, id: Id }): Promise<unknown>\n /** The repositories with this topic the user reaches that wait to be deleted; a host that deletes at once has none. */\n listPendingDeletion(args: { token: string, topic: string }): Promise<PendingDeletion[]>\n restoreRepository(args: { token: string, id: Id }): Promise<unknown>\n restoreNamespace(args: { token: string, id: Id }): Promise<unknown>\n renameRepository(args: { token: string, id: Id, name: string }): Promise<Repository>\n getRepository(args: { token: string, id: Id }): Promise<Repository>\n /** By its full path; `null` when there is none. */\n findRepository(args: { token: string, path: string }): Promise<Repository | null>\n /** The live repositories of the user that have a topic. */\n listRepositories(args: { token: string, topic: string }): Promise<Repository[]>\n addTopic(args: { token: string, id: Id, topic: string }): Promise<void>\n setDefaultBranch(args: { token: string, id: Id, branch: string }): Promise<unknown>\n getMembers(args: { token: string, id: Id }): Promise<Member[]>\n /** The level of the user of `token` on the repository (0: none). */\n getAccessLevel(args: { token: string, id: Id, username: string }): Promise<number>\n\n // Files, commits, archives\n getFile(args: { token: string, id: Id, path: string, ref: string }): Promise<RepositoryFile>\n /** Like `getFile`, never remembered for rollback. */\n getFileRevision(args: { token: string, id: Id, path: string, ref: string }): Promise<RepositoryFile>\n /** The bytes, or `null` when there is no such file. */\n readFile(args: { token: string, id: Id, path: string, ref: string }): Promise<Buffer | null>\n /** Every file of a repository at `ref`. */\n listFiles(args: { token: string, id: Id, ref: string }): Promise<string[]>\n createFile(args: { token: string, id: Id, path: string, branch: string, content: string }): Promise<unknown>\n saveFile(args: { token: string, id: Id, path: string, branch: string, content: string }): Promise<unknown>\n commit(args: { token: string, id: Id, branch: string, message: string, actions: FileAction[], track?: boolean }): Promise<{ id: string }>\n /** A zip of the repository at `ref`. */\n downloadArchive(args: { token: string, id: Id, ref?: string }): Promise<NodeJS.ReadableStream>\n getCommits(args: { token: string, id: Id, ref: string, perPage?: number }): Promise<CommitSummary[]>\n /** What `to` has that `from` has not: its commits (newest first) and the files they change, as the host's own comparison shows them. */\n compare(args: { token: string, id: Id, from: string, to: string }): Promise<Comparison>\n\n // Branches and tags\n createBranch(args: { token: string, id: Id, branch: string, ref: string, track?: boolean }): Promise<unknown>\n /** The names of the branches of a repository. */\n listBranches(args: { token: string, id: Id }): Promise<string[]>\n getBranch(args: { token: string, id: Id, branch: string }): Promise<{ name: string, lastCommit: CommitSummary | null }>\n listTags(args: { token: string, id: Id }): Promise<{ name: string }[]>\n /** `message` is the annotation of the tag (null for one that has none): what `createTag` was given. */\n getTag(args: { token: string, id: Id, tag: string }): Promise<{ name: string, commitId: string, message: string | null } | null>\n createTag(args: { token: string, id: Id, tag: string, ref: string, message?: string }): Promise<unknown>\n\n // Releases: one per tag. Creating the release of a tag that has one fails with an \"already exists\" error (`isAlreadyExistsError`) and\n // leaves it as it was; `updateRelease` is the way to change it. A tag that does not exist is refused with status 404.\n /** `name` defaults to the tag. `prerelease` is ignored by a host whose `capabilities().releases.prerelease` is `false`. */\n createRelease(args: { token: string, id: Id, tag: string, name?: string, description?: string, prerelease?: boolean }): Promise<Release>\n /** `null` when the tag has no release. */\n getRelease(args: { token: string, id: Id, tag: string }): Promise<Release | null>\n /** Newest first. */\n listReleases(args: { token: string, id: Id }): Promise<Release[]>\n /** Only what is in `changes` is touched (`prerelease` only where the host has it); status 404 when the tag has no release. */\n updateRelease(args: { token: string, id: Id, tag: string, changes: ReleaseChanges }): Promise<Release>\n\n // Change requests\n createChangeRequest(args: { token: string, id: Id, title: string, sourceBranch: string, targetBranch: string }): Promise<ChangeRequest>\n createOrRenameChangeRequest(args: { token: string, id: Id, title: string, sourceBranch: string, targetBranch?: string }): Promise<ChangeRequest>\n listChangeRequests(args: { token: string, id: Id, state?: 'opened' | 'merged' | 'closed' | 'all', targetBranch?: string }): Promise<ChangeRequest[]>\n /** The pipelines that ran for a change request (its checks), newest first. */\n listChangeRequestPipelines(args: { token: string, id: Id, number: number }): Promise<Pipeline[]>\n /** Merges it when it can; `true` when it has conflicts (or is not open). */\n mergeChangeRequest(args: { token: string, id: Id, number: number, deleteSourceBranch?: boolean }): Promise<boolean>\n\n // Issues\n capabilities(): Capabilities\n listIssues(args: { token: string, id: Id, filter?: IssueFilter }): Promise<Page<Issue>>\n getIssue(args: { token: string, id: Id, number: number }): Promise<Issue>\n createIssue(args: { token: string, id: Id, title: string, description?: string, labels?: string[], assignees?: string[], milestone?: string | null }): Promise<Issue>\n /** Only what is in `changes` is touched. Closing and reopening are `state`. */\n updateIssue(args: { token: string, id: Id, number: number, changes: IssueChanges }): Promise<Issue>\n /** The messages the people wrote, oldest first (what the host writes by itself, \"changed the label\", is left out). */\n listIssueComments(args: { token: string, id: Id, number: number }): Promise<Comment[]>\n addIssueComment(args: { token: string, id: Id, number: number, body: string }): Promise<Comment>\n listLabels(args: { token: string, id: Id }): Promise<Label[]>\n listMilestones(args: { token: string, id: Id }): Promise<Milestone[]>\n\n listTemplates(args: { token: string, id: Id, kind: TemplateKind }): Promise<Template[]>\n saveTemplate(args: { token: string, id: Id, kind: TemplateKind, name: string, content: string }): Promise<Template>\n deleteTemplate(args: { token: string, id: Id, kind: TemplateKind, name: string }): Promise<void>\n\n // Merge requests (the part of them the pages need; `createChangeRequest` and the rest are what the code needs)\n listMergeRequests(args: { token: string, id: Id, filter?: MergeRequestFilter }): Promise<Page<MergeRequest>>\n getMergeRequest(args: { token: string, id: Id, number: number }): Promise<MergeRequest>\n createMergeRequest(args: { token: string, id: Id, title: string, description?: string, sourceBranch: string, targetBranch: string, labels?: string[], reviewers?: string[] }): Promise<MergeRequest>\n /** Only what is in `changes` is touched. */\n updateMergeRequest(args: { token: string, id: Id, number: number, changes: MergeRequestChanges }): Promise<MergeRequest>\n /** The files it changes, as the target would see them after the merge. */\n getMergeRequestDiff(args: { token: string, id: Id, number: number }): Promise<FileDiff[]>\n /** Every conversation, oldest first: the general messages and the ones about lines of the code. */\n listMergeRequestThreads(args: { token: string, id: Id, number: number }): Promise<Thread[]>\n /** A general message, one about a line (`position`), or an answer in a thread (`threadId`). Answers with the thread it is in. */\n addMergeRequestComment(args: { token: string, id: Id, number: number, body: string, position?: DiffPosition, threadId?: Id }): Promise<Thread>\n setThreadResolved(args: { token: string, id: Id, number: number, threadId: Id, resolved: boolean }): Promise<Thread>\n /** Merges it; `true` when it has conflicts (or is not open), as `mergeChangeRequest`. */\n mergeMergeRequest(args: { token: string, id: Id, number: number, options?: MergeOptions }): Promise<boolean>\n /** Gives the approval of the user of `token` (a host with no approvals refuses with status 400). */\n approveMergeRequest(args: { token: string, id: Id, number: number }): Promise<void>\n\n // CI and hooks\n getLatestPipeline(args: { token: string, id: Id, ref: string }): Promise<Pipeline | null>\n /** The last pipelines of a branch (or of the repository, without `ref`), newest first. */\n listPipelines(args: { token: string, id: Id, ref?: string, perPage?: number }): Promise<Pipeline[]>\n /** The jobs of a pipeline, in the order they run. */\n getPipelineJobs(args: { token: string, id: Id, pipelineId: Id }): Promise<PipelineJob[]>\n /** Runs the failed jobs of a pipeline again. */\n retryPipeline(args: { token: string, id: Id, pipelineId: Id }): Promise<void>\n /** Stops a pipeline that has not finished: its running and waiting jobs are canceled. */\n cancelPipeline(args: { token: string, id: Id, pipelineId: Id }): Promise<void>\n /** Makes sure a repository can run pipelines (a project made with CI/CD switched off gets it switched on). Answers whether it changed anything. */\n enablePipelines(args: { token: string, id: Id }): Promise<boolean>\n /** Turns CI/CD off for a repository; `true` when it had to be changed. A host where that is not the repository's to choose does nothing. */\n disablePipelines(args: { token: string, id: Id }): Promise<boolean>\n /** Whether CI/CD is on for a repository; `null` when the host does not say, or it is not a thing of this host. */\n pipelinesEnabled(args: { token: string, id: Id }): Promise<boolean | null>\n /** Stops one job that has not finished (hosts that cannot cancel a single job say so). */\n cancelJob(args: { token: string, id: Id, jobId: Id }): Promise<void>\n /** The runners that can take the jobs of a repository, and whether the instance's own are turned on for it. */\n getCiRunners(args: { token: string, id: Id }): Promise<CiRunners>\n /** Turns on (or off) the runners of the whole instance for a repository. */\n setInstanceRunners(args: { token: string, id: Id, enabled: boolean }): Promise<void>\n /** The end of what a job printed (the last `lines`). */\n getJobTrace(args: { token: string, id: Id, jobId: Id, lines?: number }): Promise<string>\n ensureWebhook(args: { token: string, id: Id, url: string, secret: string, branch?: string }): Promise<{ status: 'created' | 'already_exists', hookId?: Id | null }>\n verifyWebhook(args: Required<Delivery>): boolean\n parsePushEvent(args: { headers: Record<string, string | undefined>, body: any }): { repositoryId: Id, branch: string } | null\n\n // Unit of work, errors\n rollback(): Promise<void>\n /** The token is expired or revoked. */\n isAuthError(error: unknown): boolean\n /** A branch (or other ref) that exists already. */\n isAlreadyExistsError(error: unknown): boolean\n}\n\n/** The methods a provider has to have: what the contract test checks and what a new host has to fill in. */\nexport const GIT_PROVIDER_METHODS = [\n 'authConfig', 'exchangeCode', 'refreshToken', 'getUser',\n 'listNamespaces', 'findNamespace', 'createNamespace', 'deleteNamespace', 'renameNamespace',\n 'createRepository', 'deleteRepository', 'listPendingDeletion', 'restoreRepository', 'restoreNamespace', 'renameRepository', 'getRepository', 'findRepository', 'listRepositories', 'addTopic',\n 'setDefaultBranch', 'getMembers', 'getAccessLevel',\n 'getFile', 'getFileRevision', 'readFile', 'listFiles', 'createFile', 'saveFile', 'commit', 'downloadArchive', 'getCommits', 'compare',\n 'createBranch', 'listBranches', 'getBranch', 'listTags', 'getTag', 'createTag',\n 'createRelease', 'getRelease', 'listReleases', 'updateRelease',\n 'createChangeRequest', 'createOrRenameChangeRequest', 'listChangeRequests', 'listChangeRequestPipelines', 'mergeChangeRequest',\n 'getLatestPipeline', 'listPipelines', 'getPipelineJobs', 'retryPipeline', 'cancelPipeline', 'cancelJob', 'enablePipelines', 'disablePipelines', 'pipelinesEnabled', 'getCiRunners', 'setInstanceRunners', 'getJobTrace', 'ensureWebhook', 'verifyWebhook', 'parsePushEvent',\n 'listMergeRequests', 'getMergeRequest', 'createMergeRequest', 'updateMergeRequest', 'getMergeRequestDiff', 'listMergeRequestThreads', 'addMergeRequestComment', 'setThreadResolved', 'mergeMergeRequest', 'approveMergeRequest',\n 'capabilities', 'listIssues', 'getIssue', 'createIssue', 'updateIssue', 'listIssueComments', 'addIssueComment', 'listLabels', 'listMilestones', 'listTemplates', 'saveTemplate', 'deleteTemplate',\n 'rollback', 'isAuthError', 'isAlreadyExistsError'\n] as const\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { GitProvider } from './provider.js';
|
|
2
|
+
/** Forgets what was kept (a write to the host, or a test that wants a clean start). */
|
|
3
|
+
export declare const clearReadCache: () => void;
|
|
4
|
+
/** `provider` with the reads above kept. `host` tells apart the hosts of one process (its address). */
|
|
5
|
+
export declare const withReadCache: (provider: GitProvider, host: string) => GitProvider;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a page asks the git host over and over, kept for a while: who is a member of a repository (asked by every permission
|
|
3
|
+
* check, several times in one request) and which repositories a user has with a topic (asked by each list of lines, of products and
|
|
4
|
+
* by the summary of the home page). Per host and per user token. A failure is not kept, and anything that writes to the host
|
|
5
|
+
* (creating, renaming or deleting a repository or a namespace, changing topics, undoing a session) drops everything, so a change made
|
|
6
|
+
* through this process is seen by the next read.
|
|
7
|
+
*
|
|
8
|
+
* A change made somewhere else (somebody added to a project in GitLab's own page) is seen after the time-to-live.
|
|
9
|
+
*/
|
|
10
|
+
const MEMBERS_TTL_MS = 5 * 60_000;
|
|
11
|
+
const LISTS_TTL_MS = 90_000;
|
|
12
|
+
// past its time-to-live a list is still answered at once (and refreshed in the background) for this long: a page never waits for
|
|
13
|
+
// GitLab's slowest read just because nobody asked for a minute
|
|
14
|
+
const LISTS_STALE_MS = 10 * 60_000;
|
|
15
|
+
const LIMIT = 500;
|
|
16
|
+
class Recent {
|
|
17
|
+
ttl;
|
|
18
|
+
staleTtl;
|
|
19
|
+
entries = new Map();
|
|
20
|
+
constructor(ttl, staleTtl = 0) {
|
|
21
|
+
this.ttl = ttl;
|
|
22
|
+
this.staleTtl = staleTtl;
|
|
23
|
+
}
|
|
24
|
+
get(key, load) {
|
|
25
|
+
const now = Date.now();
|
|
26
|
+
const hit = this.entries.get(key);
|
|
27
|
+
if (hit && now - hit.at < this.ttl)
|
|
28
|
+
return hit.value;
|
|
29
|
+
if (hit && now - hit.at < this.ttl + this.staleTtl) {
|
|
30
|
+
// stale: answer with what is kept and look again in the background; a failed look leaves the old value for the next ask. What
|
|
31
|
+
// the look finds is dropped when the entry is no longer this one (a write cleared the cache, or a newer read replaced it)
|
|
32
|
+
if (!hit.refreshing) {
|
|
33
|
+
hit.refreshing = true;
|
|
34
|
+
load().then((value) => { if (this.entries.get(key) === hit)
|
|
35
|
+
this.entries.set(key, { at: Date.now(), value: Promise.resolve(value) }); }, () => { hit.refreshing = false; });
|
|
36
|
+
}
|
|
37
|
+
return hit.value;
|
|
38
|
+
}
|
|
39
|
+
if (this.entries.size >= LIMIT)
|
|
40
|
+
this.entries.delete(this.entries.keys().next().value);
|
|
41
|
+
const value = load();
|
|
42
|
+
const entry = { at: now, value };
|
|
43
|
+
this.entries.set(key, entry);
|
|
44
|
+
value.catch(() => { if (this.entries.get(key) === entry)
|
|
45
|
+
this.entries.delete(key); });
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
clear() { this.entries.clear(); }
|
|
49
|
+
}
|
|
50
|
+
const members = new Recent(MEMBERS_TTL_MS);
|
|
51
|
+
const lists = new Recent(LISTS_TTL_MS, LISTS_STALE_MS);
|
|
52
|
+
/** Forgets what was kept (a write to the host, or a test that wants a clean start). */
|
|
53
|
+
export const clearReadCache = () => {
|
|
54
|
+
members.clear();
|
|
55
|
+
lists.clear();
|
|
56
|
+
};
|
|
57
|
+
// the calls that change what the reads above answer
|
|
58
|
+
const WRITES = new Set([
|
|
59
|
+
'createNamespace', 'deleteNamespace', 'renameNamespace',
|
|
60
|
+
'createRepository', 'deleteRepository', 'renameRepository', 'addTopic', 'setMember', 'removeMember',
|
|
61
|
+
'restoreRepository', 'restoreNamespace',
|
|
62
|
+
'rollback'
|
|
63
|
+
]);
|
|
64
|
+
/** `provider` with the reads above kept. `host` tells apart the hosts of one process (its address). */
|
|
65
|
+
export const withReadCache = (provider, host) => new Proxy(provider, {
|
|
66
|
+
get(target, property, receiver) {
|
|
67
|
+
const original = Reflect.get(target, property, receiver);
|
|
68
|
+
if (typeof original !== 'function')
|
|
69
|
+
return original;
|
|
70
|
+
const call = original.bind(target);
|
|
71
|
+
const cachedMembers = (args) => members.get(`${host}|${args.token}|${args.id}`, () => target.getMembers(args));
|
|
72
|
+
switch (property) {
|
|
73
|
+
case 'getMembers':
|
|
74
|
+
return cachedMembers;
|
|
75
|
+
case 'getAccessLevel':
|
|
76
|
+
// GitLab answers from the same kept member list as getMembers: one members/all call serves both. GitHub answers for the token's
|
|
77
|
+
// own user whoever `username` is, and a member list does not hold everyone who can read a repository: it keeps its own answer
|
|
78
|
+
if (target.kind !== 'gitlab')
|
|
79
|
+
return call;
|
|
80
|
+
return async (args) => {
|
|
81
|
+
const list = await cachedMembers(args);
|
|
82
|
+
return list.find((member) => member.username === args.username)?.accessLevel ?? 0;
|
|
83
|
+
};
|
|
84
|
+
case 'listRepositories':
|
|
85
|
+
return (args) => lists.get(`${host}|${args.token}|${args.topic}`, () => call(args));
|
|
86
|
+
default:
|
|
87
|
+
if (typeof property === 'string' && WRITES.has(property)) {
|
|
88
|
+
return async (...args) => {
|
|
89
|
+
try {
|
|
90
|
+
return await call(...args);
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
clearReadCache();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return call;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
//# sourceMappingURL=read-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-cache.js","sourceRoot":"","sources":["../src/read-cache.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,MAAM,cAAc,GAAG,CAAC,GAAG,MAAM,CAAA;AACjC,MAAM,YAAY,GAAG,MAAM,CAAA;AAC3B,iIAAiI;AACjI,+DAA+D;AAC/D,MAAM,cAAc,GAAG,EAAE,GAAG,MAAM,CAAA;AAClC,MAAM,KAAK,GAAG,GA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gBACE,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;oBACzD,OAAO,KAAK,EAAE,GAAG,IAAe,EAAE,EAAE;wBAClC,IAAI,CAAC;4BACH,OAAO,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;wBAC5B,CAAC;gCAAS,CAAC;4BACT,cAAc,EAAE,CAAA;wBAClB,CAAC;oBACH,CAAC,CAAA;gBACH,CAAC;gBACD,OAAO,IAAI,CAAA;QACf,CAAC;IACH,CAAC;CACF,CAAC,CAAA","sourcesContent":["import type { GitProvider } from './provider.js'\n\n/**\n * What a page asks the git host over and over, kept for a while: who is a member of a repository (asked by every permission\n * check, several times in one request) and which repositories a user has with a topic (asked by each list of lines, of products and\n * by the summary of the home page). Per host and per user token. A failure is not kept, and anything that writes to the host\n * (creating, renaming or deleting a repository or a namespace, changing topics, undoing a session) drops everything, so a change made\n * through this process is seen by the next read.\n *\n * A change made somewhere else (somebody added to a project in GitLab's own page) is seen after the time-to-live.\n */\n\nconst MEMBERS_TTL_MS = 5 * 60_000\nconst LISTS_TTL_MS = 90_000\n// past its time-to-live a list is still answered at once (and refreshed in the background) for this long: a page never waits for\n// GitLab's slowest read just because nobody asked for a minute\nconst LISTS_STALE_MS = 10 * 60_000\nconst LIMIT = 500\n\ninterface Entry { at: number, value: Promise<unknown>, refreshing?: boolean }\n\nclass Recent {\n private readonly entries = new Map<string, Entry>()\n constructor(private readonly ttl: number, private readonly staleTtl = 0) {}\n\n get<T>(key: string, load: () => Promise<T>): Promise<T> {\n const now = Date.now()\n const hit = this.entries.get(key)\n if (hit && now - hit.at < this.ttl) return hit.value as Promise<T>\n if (hit && now - hit.at < this.ttl + this.staleTtl) {\n // stale: answer with what is kept and look again in the background; a failed look leaves the old value for the next ask. What\n // the look finds is dropped when the entry is no longer this one (a write cleared the cache, or a newer read replaced it)\n if (!hit.refreshing) {\n hit.refreshing = true\n load().then(\n (value) => { if (this.entries.get(key) === hit) this.entries.set(key, { at: Date.now(), value: Promise.resolve(value) }) },\n () => { hit.refreshing = false }\n )\n }\n return hit.value as Promise<T>\n }\n if (this.entries.size >= LIMIT) this.entries.delete(this.entries.keys().next().value as string)\n const value = load()\n const entry: Entry = { at: now, value }\n this.entries.set(key, entry)\n value.catch(() => { if (this.entries.get(key) === entry) this.entries.delete(key) })\n return value\n }\n\n clear(): void { this.entries.clear() }\n}\n\nconst members = new Recent(MEMBERS_TTL_MS)\nconst lists = new Recent(LISTS_TTL_MS, LISTS_STALE_MS)\n\n/** Forgets what was kept (a write to the host, or a test that wants a clean start). */\nexport const clearReadCache = (): void => {\n members.clear()\n lists.clear()\n}\n\n// the calls that change what the reads above answer\nconst WRITES = new Set([\n 'createNamespace', 'deleteNamespace', 'renameNamespace',\n 'createRepository', 'deleteRepository', 'renameRepository', 'addTopic', 'setMember', 'removeMember',\n 'restoreRepository', 'restoreNamespace',\n 'rollback'\n])\n\n/** `provider` with the reads above kept. `host` tells apart the hosts of one process (its address). */\nexport const withReadCache = (provider: GitProvider, host: string): GitProvider => new Proxy(provider, {\n get(target, property, receiver) {\n const original = Reflect.get(target, property, receiver) as unknown\n if (typeof original !== 'function') return original\n const call = (original as (...args: unknown[]) => unknown).bind(target)\n const cachedMembers = (args: { token: string, id: string | number }): Promise<Array<{ username: string, accessLevel: number }>> =>\n members.get(`${host}|${args.token}|${args.id}`, () => target.getMembers(args) as Promise<Array<{ username: string, accessLevel: number }>>)\n switch (property) {\n case 'getMembers':\n return cachedMembers\n case 'getAccessLevel':\n // GitLab answers from the same kept member list as getMembers: one members/all call serves both. GitHub answers for the token's\n // own user whoever `username` is, and a member list does not hold everyone who can read a repository: it keeps its own answer\n if (target.kind !== 'gitlab') return call\n return async (args: { token: string, id: string | number, username: string }) => {\n const list = await cachedMembers(args)\n return list.find((member) => member.username === args.username)?.accessLevel ?? 0\n }\n case 'listRepositories':\n return (args: { token: string, topic: string }) => lists.get(`${host}|${args.token}|${args.topic}`, () => call(args) as Promise<unknown>)\n default:\n if (typeof property === 'string' && WRITES.has(property)) {\n return async (...args: unknown[]) => {\n try {\n return await call(...args)\n } finally {\n clearReadCache()\n }\n }\n }\n return call\n }\n }\n})\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type PackageCatalog, type PackageSource, type RegistryEntry } from '@lbdudc/linea-core';
|
|
2
|
+
import type { GitHostKind, GitProvider, Id } from '../provider.js';
|
|
3
|
+
import { listPackages, type PackageSummary } from './packages.js';
|
|
4
|
+
import type { PackageKind } from './kinds.js';
|
|
5
|
+
/**
|
|
6
|
+
* The catalog of a LINEA installation, kept in ONE git repository: `registry.json` on its `main` branch (a location such as
|
|
7
|
+
* `gitlab:linea/registry`). Whoever may push there may register; the history of the file is the history of the registry.
|
|
8
|
+
* It lists what is registered; it does not decide what an SPL may use (that is what the source and `trustedNamespaces` do).
|
|
9
|
+
*/
|
|
10
|
+
export declare const REGISTRY_TOPIC = "linea-registry";
|
|
11
|
+
interface Host {
|
|
12
|
+
provider: GitProvider;
|
|
13
|
+
token: string;
|
|
14
|
+
}
|
|
15
|
+
/** The host a location is on: `local:`, `github:`, else GitLab (`gitlab:` and the locations that were written before there were schemes). */
|
|
16
|
+
export declare const hostOfLocation: (location: string) => GitHostKind;
|
|
17
|
+
/** `gitlab:linea/registry` -> `linea/registry`, for the host that is being used. */
|
|
18
|
+
export declare const registryPathOf: ({ location, host }: {
|
|
19
|
+
location: string;
|
|
20
|
+
host: GitHostKind;
|
|
21
|
+
}) => string;
|
|
22
|
+
/** The repository of the registry, created with an empty `registry.json` when there is none. */
|
|
23
|
+
export declare const ensureRegistryRepository: ({ provider, token, location }: Host & {
|
|
24
|
+
location: string;
|
|
25
|
+
}) => Promise<{
|
|
26
|
+
id: Id;
|
|
27
|
+
path: string;
|
|
28
|
+
created: boolean;
|
|
29
|
+
}>;
|
|
30
|
+
export declare const createGitCatalog: ({ provider, token, location }: Host & {
|
|
31
|
+
location: string;
|
|
32
|
+
}) => PackageCatalog;
|
|
33
|
+
/** The entry of a package that was just made or published by the caller, so there is no need to read it back. */
|
|
34
|
+
export declare const entryFor: ({ kind, provider, path, name, description, now }: {
|
|
35
|
+
kind: PackageKind;
|
|
36
|
+
provider: GitProvider;
|
|
37
|
+
path: string;
|
|
38
|
+
name: string;
|
|
39
|
+
description?: string | undefined;
|
|
40
|
+
now?: () => Date;
|
|
41
|
+
}) => RegistryEntry;
|
|
42
|
+
/**
|
|
43
|
+
* The registered packages of one kind, with their versions. An entry that cannot be reached (deleted, private, or its host is down)
|
|
44
|
+
* is still listed, marked `unavailable`, so that one broken entry does not hide the rest.
|
|
45
|
+
*/
|
|
46
|
+
export declare const listRegisteredPackages: ({ provider, token, kind, catalog, source }: Host & {
|
|
47
|
+
kind: PackageKind;
|
|
48
|
+
catalog: PackageCatalog;
|
|
49
|
+
source: PackageSource;
|
|
50
|
+
}) => Promise<PackageSummary[]>;
|
|
51
|
+
/** Packages found by their topic that are not registered yet: what a "register a package" dialog offers. */
|
|
52
|
+
export declare const suggestPackages: ({ catalog, ...rest }: Parameters<typeof listPackages>[0] & {
|
|
53
|
+
catalog: PackageCatalog;
|
|
54
|
+
}) => Promise<PackageSummary[]>;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
import { REGISTRY_INDEX_PATH, createFileCatalog, emptyRegistryIndex, serializeRegistryIndex } from '@lbdudc/linea-core';
|
|
3
|
+
import { locationOf } from '../packages/index.js';
|
|
4
|
+
import { listPackages } from './packages.js';
|
|
5
|
+
/**
|
|
6
|
+
* The catalog of a LINEA installation, kept in ONE git repository: `registry.json` on its `main` branch (a location such as
|
|
7
|
+
* `gitlab:linea/registry`). Whoever may push there may register; the history of the file is the history of the registry.
|
|
8
|
+
* It lists what is registered; it does not decide what an SPL may use (that is what the source and `trustedNamespaces` do).
|
|
9
|
+
*/
|
|
10
|
+
export const REGISTRY_TOPIC = 'linea-registry';
|
|
11
|
+
const CATALOG_CONCURRENCY = 5;
|
|
12
|
+
const PENDING_DELETION = /-deletion_scheduled-\d+/;
|
|
13
|
+
/** The host a location is on: `local:`, `github:`, else GitLab (`gitlab:` and the locations that were written before there were schemes). */
|
|
14
|
+
export const hostOfLocation = (location) => (location.startsWith('local:') ? 'local' : location.startsWith('github:') ? 'github' : 'gitlab');
|
|
15
|
+
/** `gitlab:linea/registry` -> `linea/registry`, for the host that is being used. */
|
|
16
|
+
export const registryPathOf = ({ location, host }) => {
|
|
17
|
+
const prefix = `${host}:`;
|
|
18
|
+
if (!location.startsWith(prefix) || location.length === prefix.length) {
|
|
19
|
+
throw new Error(`The registry "${location}" is not on ${host}: write it as ${prefix}<path>.`);
|
|
20
|
+
}
|
|
21
|
+
return location.slice(prefix.length);
|
|
22
|
+
};
|
|
23
|
+
/** The text of `registry.json`, or `undefined` when the repository or the file is not there. */
|
|
24
|
+
const readIndex = async ({ provider, token, path }) => {
|
|
25
|
+
const repository = await provider.findRepository({ token, path });
|
|
26
|
+
if (repository === null)
|
|
27
|
+
return undefined;
|
|
28
|
+
try {
|
|
29
|
+
return (await provider.readFile({ token, id: repository.id, path: REGISTRY_INDEX_PATH, ref: 'main' }))?.toString('utf8');
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error.status === 404)
|
|
33
|
+
return undefined; // an empty repository has no `main` yet
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/** The repository of the registry, created with an empty `registry.json` when there is none. */
|
|
38
|
+
export const ensureRegistryRepository = async ({ provider, token, location }) => {
|
|
39
|
+
const path = registryPathOf({ location, host: provider.kind });
|
|
40
|
+
const found = await provider.findRepository({ token, path });
|
|
41
|
+
if (found !== null)
|
|
42
|
+
return { id: found.id, path: found.path, created: false };
|
|
43
|
+
const parts = path.split('/');
|
|
44
|
+
const name = parts.pop();
|
|
45
|
+
const group = parts.join('/');
|
|
46
|
+
const namespace = await provider.findNamespace({ token, fullPath: group });
|
|
47
|
+
if (namespace === null)
|
|
48
|
+
throw new Error(`${group} does not exist on ${provider.kind}: the group (or owner) of the registry has to be there already.`);
|
|
49
|
+
const repository = await provider.createRepository({ token, name, namespaceId: namespace.id, topics: [REGISTRY_TOPIC], defaultBranch: 'main' });
|
|
50
|
+
await provider.commit({
|
|
51
|
+
token,
|
|
52
|
+
id: repository.id,
|
|
53
|
+
branch: 'main',
|
|
54
|
+
message: 'Start the registry',
|
|
55
|
+
track: false,
|
|
56
|
+
actions: [{ action: 'create', path: REGISTRY_INDEX_PATH, content: serializeRegistryIndex({ index: emptyRegistryIndex() }) }]
|
|
57
|
+
});
|
|
58
|
+
return { id: repository.id, path: repository.path, created: true };
|
|
59
|
+
};
|
|
60
|
+
/** Changes to one registry run one after another in this process; two processes writing at once can still lose one change. */
|
|
61
|
+
const queues = new Map();
|
|
62
|
+
const inTurn = (key, task) => {
|
|
63
|
+
const run = (queues.get(key) ?? Promise.resolve()).then(task, task);
|
|
64
|
+
queues.set(key, run.catch(() => { }));
|
|
65
|
+
return run;
|
|
66
|
+
};
|
|
67
|
+
export const createGitCatalog = ({ provider, token, location }) => {
|
|
68
|
+
const path = registryPathOf({ location, host: provider.kind });
|
|
69
|
+
const catalog = createFileCatalog({
|
|
70
|
+
read: () => readIndex({ provider, token, path }),
|
|
71
|
+
write: async ({ content, message }) => {
|
|
72
|
+
const { id } = await ensureRegistryRepository({ provider, token, location });
|
|
73
|
+
const exists = (await provider.readFile({ token, id, path: REGISTRY_INDEX_PATH, ref: 'main' })) !== null;
|
|
74
|
+
await provider.commit({
|
|
75
|
+
token,
|
|
76
|
+
id,
|
|
77
|
+
branch: 'main',
|
|
78
|
+
message,
|
|
79
|
+
track: false,
|
|
80
|
+
actions: [{ action: exists ? 'update' : 'create', path: REGISTRY_INDEX_PATH, content }]
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
list: (args) => catalog.list(args),
|
|
86
|
+
get: (args) => catalog.get(args),
|
|
87
|
+
add: (args) => inTurn(path, () => catalog.add(args)),
|
|
88
|
+
remove: (args) => inTurn(path, () => catalog.remove(args))
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
/** The entry of a package that was just made or published by the caller, so there is no need to read it back. */
|
|
92
|
+
export const entryFor = ({ kind, provider, path, name, description, now = () => new Date() }) => ({
|
|
93
|
+
kind,
|
|
94
|
+
location: locationOf({ kind: provider.kind, path }),
|
|
95
|
+
name,
|
|
96
|
+
...(description ? { description } : {}),
|
|
97
|
+
addedAt: now().toISOString()
|
|
98
|
+
});
|
|
99
|
+
/**
|
|
100
|
+
* The registered packages of one kind, with their versions. An entry that cannot be reached (deleted, private, or its host is down)
|
|
101
|
+
* is still listed, marked `unavailable`, so that one broken entry does not hide the rest.
|
|
102
|
+
*/
|
|
103
|
+
export const listRegisteredPackages = async ({ provider, token, kind, catalog, source }) => {
|
|
104
|
+
// GitLab renames the group of a project scheduled for deletion to `<name>-deletion_scheduled-<id>` at once, and the project goes on
|
|
105
|
+
// answering until the group is purged: an entry there is registered but gone, so it is not offered (the same rule the lines use)
|
|
106
|
+
const entries = (await catalog.list({ kind })).filter((entry) => !PENDING_DELETION.test(entry.location));
|
|
107
|
+
const summarize = async (entry) => {
|
|
108
|
+
const host = hostOfLocation(entry.location);
|
|
109
|
+
const path = entry.location.slice(host.length + 1);
|
|
110
|
+
const base = { id: null, host, kind, location: entry.location, name: entry.name, path, description: entry.description ?? '', webUrl: '', versions: [], latest: null };
|
|
111
|
+
try {
|
|
112
|
+
const sameHost = host === provider.kind;
|
|
113
|
+
const [versions, repository] = await Promise.all([
|
|
114
|
+
source.listVersions({ location: entry.location }),
|
|
115
|
+
sameHost ? provider.findRepository({ token, path }) : Promise.resolve(null)
|
|
116
|
+
]);
|
|
117
|
+
if (sameHost && repository === null)
|
|
118
|
+
return { ...base, unavailable: true };
|
|
119
|
+
const sorted = semver.rsort([...versions]);
|
|
120
|
+
return {
|
|
121
|
+
...base,
|
|
122
|
+
...(repository === null ? { readOnly: true } : { id: repository.id, name: repository.name, description: repository.description || base.description, webUrl: repository.webUrl }),
|
|
123
|
+
versions: sorted,
|
|
124
|
+
latest: sorted[0] ?? null
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return { ...base, unavailable: true };
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
// a few at a time: every entry costs a tags request and a repository lookup, and on a slow host all of them at once only queue up
|
|
132
|
+
const summaries = [];
|
|
133
|
+
for (let i = 0; i < entries.length; i += CATALOG_CONCURRENCY) {
|
|
134
|
+
summaries.push(...await Promise.all(entries.slice(i, i + CATALOG_CONCURRENCY).map(summarize)));
|
|
135
|
+
}
|
|
136
|
+
return summaries.sort((a, b) => a.path.localeCompare(b.path));
|
|
137
|
+
};
|
|
138
|
+
/** Packages found by their topic that are not registered yet: what a "register a package" dialog offers. */
|
|
139
|
+
export const suggestPackages = async ({ catalog, ...rest }) => {
|
|
140
|
+
const registered = new Set((await catalog.list({ kind: rest.kind })).map((entry) => entry.location));
|
|
141
|
+
return (await listPackages(rest)).filter((summary) => !registered.has(summary.location));
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/registry/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,sBAAsB,EAA+D,MAAM,oBAAoB,CAAA;AAEpL,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAuB,MAAM,eAAe,CAAA;AAGjE;;;;GAIG;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAA;AAC9C,MAAM,mBAAmB,GAAG,CAAC,CAAA;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WAAW,EAAE,IAAI,EAAE,CAAA;QACvC,CAAC;IACH,CAAC,CAAA;IACD,kIAAkI;IAClI,MAAM,SAAS,GAAqB,EAAE,CAAA;IACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,mBAAmB,EAAE,CAAC;QAC7D,SAAS,CAAC,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IAChG,CAAC;IACD,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;AAC/D,CAAC,CAAA;AAED,4GAA4G;AAC5G,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,EAAE,OAAO,EAAE,GAAG,IAAI,EAAoE,EAA6B,EAAE;IACzJ,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAA;IACpG,OAAO,CAAC,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;AAC1F,CAAC,CAAA","sourcesContent":["import semver from 'semver'\nimport { REGISTRY_INDEX_PATH, createFileCatalog, emptyRegistryIndex, serializeRegistryIndex, type PackageCatalog, type PackageSource, type RegistryEntry } from '@lbdudc/linea-core'\nimport type { GitHostKind, GitProvider, Id } from '../provider.js'\nimport { locationOf } from '../packages/index.js'\nimport { listPackages, type PackageSummary } from './packages.js'\nimport type { PackageKind } from './kinds.js'\n\n/**\n * The catalog of a LINEA installation, kept in ONE git repository: `registry.json` on its `main` branch (a location such as\n * `gitlab:linea/registry`). Whoever may push there may register; the history of the file is the history of the registry.\n * It lists what is registered; it does not decide what an SPL may use (that is what the source and `trustedNamespaces` do).\n */\n\nexport const REGISTRY_TOPIC = 'linea-registry'\nconst CATALOG_CONCURRENCY = 5\nconst PENDING_DELETION = /-deletion_scheduled-\\d+/\n\ninterface Host {\n provider: GitProvider\n token: string\n}\n\n/** The host a location is on: `local:`, `github:`, else GitLab (`gitlab:` and the locations that were written before there were schemes). */\nexport const hostOfLocation = (location: string): GitHostKind => (location.startsWith('local:') ? 'local' : location.startsWith('github:') ? 'github' : 'gitlab')\n\n/** `gitlab:linea/registry` -> `linea/registry`, for the host that is being used. */\nexport const registryPathOf = ({ location, host }: { location: string, host: GitHostKind }): string => {\n const prefix = `${host}:`\n if (!location.startsWith(prefix) || location.length === prefix.length) {\n throw new Error(`The registry \"${location}\" is not on ${host}: write it as ${prefix}<path>.`)\n }\n return location.slice(prefix.length)\n}\n\n/** The text of `registry.json`, or `undefined` when the repository or the file is not there. */\nconst readIndex = async ({ provider, token, path }: Host & { path: string }): Promise<string | undefined> => {\n const repository = await provider.findRepository({ token, path })\n if (repository === null) return undefined\n try {\n return (await provider.readFile({ token, id: repository.id, path: REGISTRY_INDEX_PATH, ref: 'main' }))?.toString('utf8')\n } catch (error) {\n if ((error as { status?: number }).status === 404) return undefined // an empty repository has no `main` yet\n throw error\n }\n}\n\n/** The repository of the registry, created with an empty `registry.json` when there is none. */\nexport const ensureRegistryRepository = async ({ provider, token, location }: Host & { location: string }): Promise<{ id: Id, path: string, created: boolean }> => {\n const path = registryPathOf({ location, host: provider.kind })\n const found = await provider.findRepository({ token, path })\n if (found !== null) return { id: found.id, path: found.path, created: false }\n const parts = path.split('/')\n const name = parts.pop() as string\n const group = parts.join('/')\n const namespace = await provider.findNamespace({ token, fullPath: group })\n if (namespace === null) throw new Error(`${group} does not exist on ${provider.kind}: the group (or owner) of the registry has to be there already.`)\n const repository = await provider.createRepository({ token, name, namespaceId: namespace.id, topics: [REGISTRY_TOPIC], defaultBranch: 'main' })\n await provider.commit({\n token,\n id: repository.id,\n branch: 'main',\n message: 'Start the registry',\n track: false,\n actions: [{ action: 'create', path: REGISTRY_INDEX_PATH, content: serializeRegistryIndex({ index: emptyRegistryIndex() }) }]\n })\n return { id: repository.id, path: repository.path, created: true }\n}\n\n/** Changes to one registry run one after another in this process; two processes writing at once can still lose one change. */\nconst queues = new Map<string, Promise<unknown>>()\nconst inTurn = <T>(key: string, task: () => Promise<T>): Promise<T> => {\n const run = (queues.get(key) ?? Promise.resolve()).then(task, task)\n queues.set(key, run.catch(() => {}))\n return run\n}\n\nexport const createGitCatalog = ({ provider, token, location }: Host & { location: string }): PackageCatalog => {\n const path = registryPathOf({ location, host: provider.kind })\n const catalog = createFileCatalog({\n read: () => readIndex({ provider, token, path }),\n write: async ({ content, message }) => {\n const { id } = await ensureRegistryRepository({ provider, token, location })\n const exists = (await provider.readFile({ token, id, path: REGISTRY_INDEX_PATH, ref: 'main' })) !== null\n await provider.commit({\n token,\n id,\n branch: 'main',\n message,\n track: false,\n actions: [{ action: exists ? 'update' : 'create', path: REGISTRY_INDEX_PATH, content }]\n })\n }\n })\n return {\n list: (args) => catalog.list(args),\n get: (args) => catalog.get(args),\n add: (args) => inTurn(path, () => catalog.add(args)),\n remove: (args) => inTurn(path, () => catalog.remove(args))\n }\n}\n\n/** The entry of a package that was just made or published by the caller, so there is no need to read it back. */\nexport const entryFor = ({ kind, provider, path, name, description, now = () => new Date() }: { kind: PackageKind, provider: GitProvider, path: string, name: string, description?: string | undefined, now?: () => Date }): RegistryEntry => ({\n kind,\n location: locationOf({ kind: provider.kind, path }),\n name,\n ...(description ? { description } : {}),\n addedAt: now().toISOString()\n})\n\n/**\n * The registered packages of one kind, with their versions. An entry that cannot be reached (deleted, private, or its host is down)\n * is still listed, marked `unavailable`, so that one broken entry does not hide the rest.\n */\nexport const listRegisteredPackages = async ({ provider, token, kind, catalog, source }: Host & { kind: PackageKind, catalog: PackageCatalog, source: PackageSource }): Promise<PackageSummary[]> => {\n // GitLab renames the group of a project scheduled for deletion to `<name>-deletion_scheduled-<id>` at once, and the project goes on\n // answering until the group is purged: an entry there is registered but gone, so it is not offered (the same rule the lines use)\n const entries = (await catalog.list({ kind })).filter((entry) => !PENDING_DELETION.test(entry.location))\n const summarize = async (entry: (typeof entries)[number]): Promise<PackageSummary> => {\n const host = hostOfLocation(entry.location)\n const path = entry.location.slice(host.length + 1)\n const base: PackageSummary = { id: null, host, kind, location: entry.location, name: entry.name, path, description: entry.description ?? '', webUrl: '', versions: [], latest: null }\n try {\n const sameHost = host === provider.kind\n const [versions, repository] = await Promise.all([\n source.listVersions({ location: entry.location }),\n sameHost ? provider.findRepository({ token, path }) : Promise.resolve(null)\n ])\n if (sameHost && repository === null) return { ...base, unavailable: true }\n const sorted = semver.rsort([...versions])\n return {\n ...base,\n ...(repository === null ? { readOnly: true } : { id: repository.id, name: repository.name, description: repository.description || base.description, webUrl: repository.webUrl }),\n versions: sorted,\n latest: sorted[0] ?? null\n }\n } catch {\n return { ...base, unavailable: true }\n }\n }\n // a few at a time: every entry costs a tags request and a repository lookup, and on a slow host all of them at once only queue up\n const summaries: PackageSummary[] = []\n for (let i = 0; i < entries.length; i += CATALOG_CONCURRENCY) {\n summaries.push(...await Promise.all(entries.slice(i, i + CATALOG_CONCURRENCY).map(summarize)))\n }\n return summaries.sort((a, b) => a.path.localeCompare(b.path))\n}\n\n/** Packages found by their topic that are not registered yet: what a \"register a package\" dialog offers. */\nexport const suggestPackages = async ({ catalog, ...rest }: Parameters<typeof listPackages>[0] & { catalog: PackageCatalog }): Promise<PackageSummary[]> => {\n const registered = new Set((await catalog.list({ kind: rest.kind })).map((entry) => entry.location))\n return (await listPackages(rest)).filter((summary) => !registered.has(summary.location))\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type PackageKind = 'module' | 'metamodel';
|
|
2
|
+
/** What a module or a metamodel is in the registry: how it is found (its topic), described (its manifest) and started (its scaffold). */
|
|
3
|
+
export interface KindDefinition {
|
|
4
|
+
kind: PackageKind;
|
|
5
|
+
/** The folder of a workspace that holds the packages of this kind. */
|
|
6
|
+
dir: string;
|
|
7
|
+
topic: string;
|
|
8
|
+
manifest: string;
|
|
9
|
+
parse: (args: {
|
|
10
|
+
content: string;
|
|
11
|
+
}) => unknown;
|
|
12
|
+
scaffold: (args: {
|
|
13
|
+
name: string;
|
|
14
|
+
description?: string | undefined;
|
|
15
|
+
}) => Record<string, string>;
|
|
16
|
+
}
|
|
17
|
+
/** `user-management` -> `UserManagement`: the name of a root feature or of a grammar rule. */
|
|
18
|
+
export declare const pascal: (name: string) => string;
|
|
19
|
+
/** The two registries of packages. They are separate: each has its own definition, and nothing in one refers to the other. */
|
|
20
|
+
export declare const KIND_DEFINITIONS: Record<PackageKind, KindDefinition>;
|
|
21
|
+
export declare const KINDS: PackageKind[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { parseMetamodelManifest, parseModuleManifest } from '@lbdudc/linea-core';
|
|
2
|
+
/** `user-management` -> `UserManagement`: the name of a root feature or of a grammar rule. */
|
|
3
|
+
export const pascal = (name) => name.replace(/(^|[-_.\s]+)(.)/g, (_match, _sep, char) => char.toUpperCase()).replace(/[^A-Za-z0-9_]/g, '') || 'Root';
|
|
4
|
+
const moduleKind = {
|
|
5
|
+
kind: 'module',
|
|
6
|
+
dir: 'modules',
|
|
7
|
+
topic: 'linea-module',
|
|
8
|
+
manifest: '.linea/module.json',
|
|
9
|
+
parse: parseModuleManifest,
|
|
10
|
+
scaffold: ({ name, description }) => ({
|
|
11
|
+
'.linea/module.json': `${JSON.stringify({ name, version: '0.1.0', ...(description ? { description } : {}), requires: { modules: {}, metamodels: {} }, offers: {} }, null, 2)}\n`,
|
|
12
|
+
'.linea/model.uvl': `features\n\t${pascal(name)}\n`
|
|
13
|
+
})
|
|
14
|
+
};
|
|
15
|
+
const metamodelKind = {
|
|
16
|
+
kind: 'metamodel',
|
|
17
|
+
dir: 'metamodels',
|
|
18
|
+
topic: 'linea-metamodel',
|
|
19
|
+
manifest: 'metamodel.json',
|
|
20
|
+
parse: parseMetamodelManifest,
|
|
21
|
+
scaffold: ({ name, description }) => {
|
|
22
|
+
const rule = pascal(name);
|
|
23
|
+
return {
|
|
24
|
+
'metamodel.json': `${JSON.stringify({ name, version: '0.1.0', ...(description ? { description } : {}), requires: {} }, null, 2)}\n`,
|
|
25
|
+
[`grammars/${name}.langium`]: [
|
|
26
|
+
`grammar ${rule}`,
|
|
27
|
+
'',
|
|
28
|
+
`// ${description || `${rule}: describe what this metamodel models`}`,
|
|
29
|
+
`entry ${rule}Model: '${name.toLowerCase()}' name=ID? (items+=Item)*;`,
|
|
30
|
+
'',
|
|
31
|
+
"Item: 'item' name=ID;",
|
|
32
|
+
'',
|
|
33
|
+
'terminal ID: /[_a-zA-Z][\\w_-]*/;',
|
|
34
|
+
'hidden terminal WS: /\\s+/;',
|
|
35
|
+
''
|
|
36
|
+
].join('\n')
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
/** The two registries of packages. They are separate: each has its own definition, and nothing in one refers to the other. */
|
|
41
|
+
export const KIND_DEFINITIONS = { module: moduleKind, metamodel: metamodelKind };
|
|
42
|
+
export const KINDS = ['module', 'metamodel'];
|
|
43
|
+
//# sourceMappingURL=kinds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kinds.js","sourceRoot":"","sources":["../../src/registry/kinds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAehF,8FAA8F;AAC9F,MAAM,CAAC,MAAM,MAAM,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GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI;YACnI,CAAC,YAAY,IAAI,UAAU,CAAC,EAAE;gBAC5B,WAAW,IAAI,EAAE;gBACjB,EAAE;gBACF,MAAM,WAAW,IAAI,GAAG,IAAI,uCAAuC,EAAE;gBACrE,SAAS,IAAI,WAAW,IAAI,CAAC,WAAW,EAAE,4BAA4B;gBACtE,EAAE;gBACF,uBAAuB;gBACvB,EAAE;gBACF,mCAAmC;gBACnC,6BAA6B;gBAC7B,EAAE;aACH,CAAC,IAAI,CAAC,IAAI,CAAC;SACb,CAAA;IACH,CAAC;CACF,CAAA;AAED,8HAA8H;AAC9H,MAAM,CAAC,MAAM,gBAAgB,GAAwC,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,CAAA;AACrH,MAAM,CAAC,MAAM,KAAK,GAAkB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAA","sourcesContent":["import { parseMetamodelManifest, parseModuleManifest } from '@lbdudc/linea-core'\n\nexport type PackageKind = 'module' | 'metamodel'\n\n/** What a module or a metamodel is in the registry: how it is found (its topic), described (its manifest) and started (its scaffold). */\nexport interface KindDefinition {\n kind: PackageKind\n /** The folder of a workspace that holds the packages of this kind. */\n dir: string\n topic: string\n manifest: string\n parse: (args: { content: string }) => unknown\n scaffold: (args: { name: string, description?: string | undefined }) => Record<string, string>\n}\n\n/** `user-management` -> `UserManagement`: the name of a root feature or of a grammar rule. */\nexport const pascal = (name: string): string =>\n name.replace(/(^|[-_.\\s]+)(.)/g, (_match, _sep, char: string) => char.toUpperCase()).replace(/[^A-Za-z0-9_]/g, '') || 'Root'\n\nconst moduleKind: KindDefinition = {\n kind: 'module',\n dir: 'modules',\n topic: 'linea-module',\n manifest: '.linea/module.json',\n parse: parseModuleManifest,\n scaffold: ({ name, description }) => ({\n '.linea/module.json': `${JSON.stringify({ name, version: '0.1.0', ...(description ? { description } : {}), requires: { modules: {}, metamodels: {} }, offers: {} }, null, 2)}\\n`,\n '.linea/model.uvl': `features\\n\\t${pascal(name)}\\n`\n })\n}\n\nconst metamodelKind: KindDefinition = {\n kind: 'metamodel',\n dir: 'metamodels',\n topic: 'linea-metamodel',\n manifest: 'metamodel.json',\n parse: parseMetamodelManifest,\n scaffold: ({ name, description }) => {\n const rule = pascal(name)\n return {\n 'metamodel.json': `${JSON.stringify({ name, version: '0.1.0', ...(description ? { description } : {}), requires: {} }, null, 2)}\\n`,\n [`grammars/${name}.langium`]: [\n `grammar ${rule}`,\n '',\n `// ${description || `${rule}: describe what this metamodel models`}`,\n `entry ${rule}Model: '${name.toLowerCase()}' name=ID? (items+=Item)*;`,\n '',\n \"Item: 'item' name=ID;\",\n '',\n 'terminal ID: /[_a-zA-Z][\\\\w_-]*/;',\n 'hidden terminal WS: /\\\\s+/;',\n ''\n ].join('\\n')\n }\n }\n}\n\n/** The two registries of packages. They are separate: each has its own definition, and nothing in one refers to the other. */\nexport const KIND_DEFINITIONS: Record<PackageKind, KindDefinition> = { module: moduleKind, metamodel: metamodelKind }\nexport const KINDS: PackageKind[] = ['module', 'metamodel']\n"]}
|