@lbdudc/linea-git 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/README.md +47 -2
  2. package/dist/access.d.ts +18 -0
  3. package/dist/access.js +18 -0
  4. package/dist/access.js.map +1 -0
  5. package/dist/auth.d.ts +11 -0
  6. package/dist/auth.js +16 -0
  7. package/dist/auth.js.map +1 -0
  8. package/dist/changelog/generate.d.ts +18 -0
  9. package/dist/changelog/generate.js +166 -0
  10. package/dist/changelog/generate.js.map +1 -0
  11. package/dist/changelog/index.d.ts +5 -0
  12. package/dist/changelog/index.js +3 -0
  13. package/dist/changelog/index.js.map +1 -0
  14. package/dist/changelog/parse.d.ts +43 -0
  15. package/dist/changelog/parse.js +91 -0
  16. package/dist/changelog/parse.js.map +1 -0
  17. package/dist/changelog/types.d.ts +85 -0
  18. package/dist/changelog/types.js +2 -0
  19. package/dist/changelog/types.js.map +1 -0
  20. package/dist/checkout/credential.d.ts +14 -0
  21. package/dist/checkout/credential.js +29 -0
  22. package/dist/checkout/credential.js.map +1 -0
  23. package/dist/checkout/git.d.ts +78 -0
  24. package/dist/checkout/git.js +191 -0
  25. package/dist/checkout/git.js.map +1 -0
  26. package/dist/checkout/index.d.ts +3 -0
  27. package/dist/checkout/index.js +4 -0
  28. package/dist/checkout/index.js.map +1 -0
  29. package/dist/checkout/sync.d.ts +156 -0
  30. package/dist/checkout/sync.js +211 -0
  31. package/dist/checkout/sync.js.map +1 -0
  32. package/dist/closing.d.ts +1 -0
  33. package/dist/closing.js +14 -0
  34. package/dist/closing.js.map +1 -0
  35. package/dist/config.d.ts +53 -0
  36. package/dist/config.js +40 -0
  37. package/dist/config.js.map +1 -0
  38. package/dist/deletion.d.ts +19 -0
  39. package/dist/deletion.js +27 -0
  40. package/dist/deletion.js.map +1 -0
  41. package/dist/errors.d.ts +26 -0
  42. package/dist/errors.js +47 -0
  43. package/dist/errors.js.map +1 -0
  44. package/dist/factory.d.ts +20 -0
  45. package/dist/factory.js +46 -0
  46. package/dist/factory.js.map +1 -0
  47. package/dist/github/client.d.ts +44 -0
  48. package/dist/github/client.js +145 -0
  49. package/dist/github/client.js.map +1 -0
  50. package/dist/github/config.d.ts +24 -0
  51. package/dist/github/config.js +11 -0
  52. package/dist/github/config.js.map +1 -0
  53. package/dist/github/provider.d.ts +510 -0
  54. package/dist/github/provider.js +1009 -0
  55. package/dist/github/provider.js.map +1 -0
  56. package/dist/gitlab/client.d.ts +50 -0
  57. package/dist/gitlab/client.js +228 -0
  58. package/dist/gitlab/client.js.map +1 -0
  59. package/dist/gitlab/provider.d.ts +487 -0
  60. package/dist/gitlab/provider.js +719 -0
  61. package/dist/gitlab/provider.js.map +1 -0
  62. package/dist/host.d.ts +27 -0
  63. package/dist/host.js +45 -0
  64. package/dist/host.js.map +1 -0
  65. package/dist/index.d.ts +46 -0
  66. package/dist/index.js +31 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/local/diff.d.ts +3 -0
  69. package/dist/local/diff.js +43 -0
  70. package/dist/local/diff.js.map +1 -0
  71. package/dist/local/git.d.ts +24 -0
  72. package/dist/local/git.js +51 -0
  73. package/dist/local/git.js.map +1 -0
  74. package/dist/local/health.d.ts +36 -0
  75. package/dist/local/health.js +57 -0
  76. package/dist/local/health.js.map +1 -0
  77. package/dist/local/hooks.d.ts +2 -0
  78. package/dist/local/hooks.js +44 -0
  79. package/dist/local/hooks.js.map +1 -0
  80. package/dist/local/http.d.ts +35 -0
  81. package/dist/local/http.js +160 -0
  82. package/dist/local/http.js.map +1 -0
  83. package/dist/local/provider.d.ts +571 -0
  84. package/dist/local/provider.js +1237 -0
  85. package/dist/local/provider.js.map +1 -0
  86. package/dist/local/store.d.ts +136 -0
  87. package/dist/local/store.js +171 -0
  88. package/dist/local/store.js.map +1 -0
  89. package/dist/packages/github-source.d.ts +69 -0
  90. package/dist/packages/github-source.js +133 -0
  91. package/dist/packages/github-source.js.map +1 -0
  92. package/dist/packages/gitlab-source.d.ts +59 -0
  93. package/dist/packages/gitlab-source.js +214 -0
  94. package/dist/packages/gitlab-source.js.map +1 -0
  95. package/dist/packages/index.d.ts +30 -0
  96. package/dist/packages/index.js +45 -0
  97. package/dist/packages/index.js.map +1 -0
  98. package/dist/packages/provider-source.d.ts +34 -0
  99. package/dist/packages/provider-source.js +57 -0
  100. package/dist/packages/provider-source.js.map +1 -0
  101. package/dist/packages/repository-files.d.ts +12 -0
  102. package/dist/packages/repository-files.js +16 -0
  103. package/dist/packages/repository-files.js.map +1 -0
  104. package/dist/provider.d.ts +888 -0
  105. package/dist/provider.js +29 -0
  106. package/dist/provider.js.map +1 -0
  107. package/dist/read-cache.d.ts +5 -0
  108. package/dist/read-cache.js +101 -0
  109. package/dist/read-cache.js.map +1 -0
  110. package/dist/registry/catalog.d.ts +55 -0
  111. package/dist/registry/catalog.js +143 -0
  112. package/dist/registry/catalog.js.map +1 -0
  113. package/dist/registry/kinds.d.ts +21 -0
  114. package/dist/registry/kinds.js +43 -0
  115. package/dist/registry/kinds.js.map +1 -0
  116. package/dist/registry/packages.d.ts +165 -0
  117. package/dist/registry/packages.js +290 -0
  118. package/dist/registry/packages.js.map +1 -0
  119. package/dist/registry/publish.d.ts +35 -0
  120. package/dist/registry/publish.js +155 -0
  121. package/dist/registry/publish.js.map +1 -0
  122. package/dist/registry/release.d.ts +63 -0
  123. package/dist/registry/release.js +79 -0
  124. package/dist/registry/release.js.map +1 -0
  125. package/dist/restoration.d.ts +14 -0
  126. package/dist/restoration.js +33 -0
  127. package/dist/restoration.js.map +1 -0
  128. package/dist/templates.d.ts +8 -0
  129. package/dist/templates.js +39 -0
  130. package/dist/templates.js.map +1 -0
  131. package/dist/testing/contract.d.ts +43 -0
  132. package/dist/testing/contract.js +713 -0
  133. package/dist/testing/contract.js.map +1 -0
  134. package/dist/testing/diff.d.ts +1 -0
  135. package/dist/testing/diff.js +65 -0
  136. package/dist/testing/diff.js.map +1 -0
  137. package/dist/testing/git-http.d.ts +12 -0
  138. package/dist/testing/git-http.js +308 -0
  139. package/dist/testing/git-http.js.map +1 -0
  140. package/dist/testing/github-double.d.ts +151 -0
  141. package/dist/testing/github-double.js +1129 -0
  142. package/dist/testing/github-double.js.map +1 -0
  143. package/dist/testing/gitlab-double.d.ts +161 -0
  144. package/dist/testing/gitlab-double.js +1554 -0
  145. package/dist/testing/gitlab-double.js.map +1 -0
  146. package/dist/testing/index.d.ts +7 -0
  147. package/dist/testing/index.js +8 -0
  148. package/dist/testing/index.js.map +1 -0
  149. package/dist/version.d.ts +2 -0
  150. package/dist/version.js +12 -0
  151. package/dist/version.js.map +1 -0
  152. package/package.json +66 -4
@@ -0,0 +1,165 @@
1
+ import semver from 'semver';
2
+ import { type Diagnostic, type PackageCatalog } from '@lbdudc/linea-core';
3
+ import type { GitConfig } from '../config.js';
4
+ import type { GitHostKind, GitProvider, Id, Release, Repository } from '../provider.js';
5
+ import { type PackageKind } from './kinds.js';
6
+ import { type BumpLevel } from './release.js';
7
+ export interface PackageSummary {
8
+ id: Id | null;
9
+ host: GitHostKind;
10
+ kind: PackageKind;
11
+ /** `gitlab:group/project`, `github:owner/repo`: what an SPL names it by. */
12
+ location: string;
13
+ name: string;
14
+ path: string;
15
+ description: string;
16
+ webUrl: string;
17
+ /** Highest first. */
18
+ versions: string[];
19
+ latest: string | null;
20
+ /** Listed for use, edited and published elsewhere. */
21
+ readOnly?: boolean;
22
+ /** Registered, but its repository cannot be reached (deleted, private, host down). */
23
+ unavailable?: boolean;
24
+ }
25
+ export interface PackageDetail extends PackageSummary {
26
+ files: string[];
27
+ manifest: unknown;
28
+ manifestError: string | null;
29
+ }
30
+ export declare const versionsOfTags: (tags: {
31
+ name: string;
32
+ }[]) => string[];
33
+ export declare const isSafePath: (path: unknown) => path is string;
34
+ interface Host {
35
+ provider: GitProvider;
36
+ token: string;
37
+ }
38
+ /** The repository of a package, which must be one of that kind. */
39
+ export declare const packageRepository: ({ provider, token, kind, id }: Host & {
40
+ kind: PackageKind;
41
+ id: Id;
42
+ }) => Promise<Repository>;
43
+ /** The manifest of a package as it is on `ref` (parsed: a manifest that is not valid throws what linea-core throws). */
44
+ export declare const readManifest: ({ provider, token, kind, id, ref }: Host & {
45
+ kind: PackageKind;
46
+ id: Id;
47
+ ref?: string;
48
+ }) => Promise<any>;
49
+ /**
50
+ * Writes several files to a branch in one commit: a string creates or updates the file, `null` deletes it. A file that already has that
51
+ * content is left as it is. Returns `null` without committing when nothing has to change.
52
+ */
53
+ export declare const upsertFiles: ({ provider, token, id, branch, message, files }: Host & {
54
+ id: Id;
55
+ branch?: string;
56
+ message: string;
57
+ files: Record<string, string | null>;
58
+ }) => Promise<{
59
+ id: string;
60
+ } | null>;
61
+ /** The packages of one kind the user can see, with their versions. */
62
+ export declare const listPackages: ({ provider, token, kind, config, userId }: Host & {
63
+ kind: PackageKind;
64
+ config?: GitConfig;
65
+ userId?: string | number;
66
+ }) => Promise<PackageSummary[]>;
67
+ /** A new package: a repository with its topic and the files a package of that kind starts with. What it made is undone if it fails. */
68
+ export declare const createPackage: ({ provider, token, kind, name, description, namespaceId, catalog }: Host & {
69
+ kind: PackageKind;
70
+ name: string;
71
+ description?: string | undefined;
72
+ namespaceId?: Id | null | undefined;
73
+ catalog?: PackageCatalog | undefined;
74
+ }) => Promise<PackageSummary>;
75
+ export declare const getPackage: ({ provider, token, kind, id }: Host & {
76
+ kind: PackageKind;
77
+ id: Id;
78
+ }) => Promise<PackageDetail>;
79
+ export declare const readPackageFile: ({ provider, token, kind, id, path, ref }: Host & {
80
+ kind: PackageKind;
81
+ id: Id;
82
+ path: string;
83
+ ref?: string;
84
+ }) => Promise<{
85
+ path: string;
86
+ ref: string;
87
+ content: string;
88
+ }>;
89
+ /** Writes (or, with `content: null`, deletes) one file of a package on `main`. A manifest is checked before it is saved. */
90
+ export declare const savePackageFile: ({ provider, token, kind, id, path, content, message }: Host & {
91
+ kind: PackageKind;
92
+ id: Id;
93
+ path: string;
94
+ content: string | null;
95
+ message?: string | undefined;
96
+ }) => Promise<{
97
+ path: string;
98
+ committed: boolean;
99
+ }>;
100
+ /**
101
+ * Writes (a string) or deletes (`null`) several files of a package on `main` in ONE commit, so an editor that changed a grammar and its
102
+ * scripts leaves one version in the history instead of five. Every path is checked first, and so is the manifest if it is among them;
103
+ * nothing is written when any of them is not valid.
104
+ */
105
+ export declare const savePackageFiles: ({ provider, token, kind, id, files, message }: Host & {
106
+ kind: PackageKind;
107
+ id: Id;
108
+ files: Record<string, string | null>;
109
+ message?: string | undefined;
110
+ }) => Promise<{
111
+ paths: string[];
112
+ committed: boolean;
113
+ }>;
114
+ export interface PackageCheck {
115
+ ok: boolean;
116
+ diagnostics: readonly Diagnostic[];
117
+ [key: string]: unknown;
118
+ }
119
+ /**
120
+ * Publishes the version of `main`: checks that the version is valid semver, higher than the last one published and not already
121
+ * published, checks the package (with `check`, which is given the location and the manifest), tags it `vX.Y.Z` and creates the release of
122
+ * the tag with the changelog since the previous version. With `bump` (`patch`, `minor`, `major`) the version in the manifest is raised
123
+ * first (a commit on `main`), so a package can be released without editing the manifest by hand.
124
+ *
125
+ * `suggestedBump` is what the commits since the last version imply, and `warnings` says when the version does not match it (it never blocks).
126
+ */
127
+ export declare const publishPackage: ({ provider, token, kind, id, bump, check }: Host & {
128
+ kind: PackageKind;
129
+ id: Id;
130
+ bump?: semver.ReleaseType | undefined;
131
+ check: (args: {
132
+ location: string;
133
+ manifest: any;
134
+ }) => Promise<PackageCheck>;
135
+ }) => Promise<{
136
+ location: string;
137
+ version: string;
138
+ tag: string;
139
+ report: PackageCheck;
140
+ release: Release | null;
141
+ suggestedBump: BumpLevel | null;
142
+ warnings: string[];
143
+ }>;
144
+ export interface PackageChangelog {
145
+ version: string;
146
+ tag: string;
147
+ /** Markdown, made from commit messages that whoever can push wrote: a page that shows it has to sanitize it (HTML included). */
148
+ markdown: string;
149
+ /** The release the host holds, or the changelog worked out from the commits for a version that was tagged without one. */
150
+ source: 'release' | 'commits';
151
+ /** The page of the release on the host (empty when there is none). */
152
+ url: string;
153
+ }
154
+ /** The changelog of one version of a package (`1.2.0` or `v1.2.0`), for the catalog to show: its release, or the commits when it has none. */
155
+ export declare const getPackageChangelog: ({ provider, token, kind, id, version }: Host & {
156
+ kind: PackageKind;
157
+ id: Id;
158
+ version: string;
159
+ }) => Promise<PackageChangelog>;
160
+ /** The changelogs of every published version of a package, highest first (one call to the host for all the releases; a version without release is worked out from its commits). */
161
+ export declare const listPackageChangelogs: ({ provider, token, kind, id }: Host & {
162
+ kind: PackageKind;
163
+ id: Id;
164
+ }) => Promise<PackageChangelog[]>;
165
+ export {};
@@ -0,0 +1,290 @@
1
+ import semver from 'semver';
2
+ import { ModuleCheckError, NAME_PATTERN } from '@lbdudc/linea-core';
3
+ import { generateChangelog } from '../changelog/index.js';
4
+ import { PackageNotFoundError } from '../errors.js';
5
+ import { GitHubClient } from '../github/client.js';
6
+ import { githubApiUrl } from '../github/config.js';
7
+ import { GitHubPackageSource, discoverGitHubPackages } from '../packages/github-source.js';
8
+ import { locationOf } from '../packages/index.js';
9
+ import { forgetPackageTags } from '../packages/gitlab-source.js';
10
+ import { entryFor } from './catalog.js';
11
+ import { KIND_DEFINITIONS } from './kinds.js';
12
+ import { createPackageRelease, preflight, tagOf } from './release.js';
13
+ /**
14
+ * The registry of modules and metamodels, on the git host: repositories with the topic `linea-module` or `linea-metamodel`, whose
15
+ * versions are their `vX.Y.Z` tags. There is no database: the git host is the registry. These are the operations on it; who may do
16
+ * what is for the caller to decide before calling.
17
+ */
18
+ const VERSION_TAG = /^v?(\d+\.\d+\.\d+)$/;
19
+ const CONCURRENCY = 5;
20
+ export const versionsOfTags = (tags) => semver.rsort(tags.map((tag) => VERSION_TAG.exec(tag.name)?.[1]).filter((version) => Boolean(version)));
21
+ const summarize = ({ repository, kind, versions, host }) => ({
22
+ id: repository.id,
23
+ host,
24
+ kind,
25
+ location: locationOf({ kind: host, path: repository.path }),
26
+ name: repository.name,
27
+ path: repository.path,
28
+ description: repository.description ?? '',
29
+ webUrl: repository.webUrl,
30
+ versions,
31
+ latest: versions[0] ?? null
32
+ });
33
+ export const isSafePath = (path) => typeof path === 'string' && path !== '' && !path.startsWith('/') && !path.includes('\\') && !path.split('/').some((part) => part === '' || part === '..' || part === '.git');
34
+ const decode = (bytes) => (bytes === null ? null : bytes.toString('utf8'));
35
+ /** The repository of a package, which must be one of that kind. */
36
+ export const packageRepository = async ({ provider, token, kind, id }) => {
37
+ let repository;
38
+ try {
39
+ repository = await provider.getRepository({ token, id });
40
+ }
41
+ catch (error) {
42
+ if (error.status === 404)
43
+ throw new PackageNotFoundError();
44
+ throw error;
45
+ }
46
+ if (!repository.topics.includes(KIND_DEFINITIONS[kind].topic))
47
+ throw new PackageNotFoundError();
48
+ return repository;
49
+ };
50
+ /** The manifest of a package as it is on `ref` (parsed: a manifest that is not valid throws what linea-core throws). */
51
+ export const readManifest = async ({ provider, token, kind, id, ref = 'main' }) => {
52
+ const definition = KIND_DEFINITIONS[kind];
53
+ const content = decode(await provider.readFile({ token, id, path: definition.manifest, ref }));
54
+ if (content === null)
55
+ throw new PackageNotFoundError(`${definition.manifest} is missing`);
56
+ return definition.parse({ content });
57
+ };
58
+ /**
59
+ * Writes several files to a branch in one commit: a string creates or updates the file, `null` deletes it. A file that already has that
60
+ * content is left as it is. Returns `null` without committing when nothing has to change.
61
+ */
62
+ export const upsertFiles = async ({ provider, token, id, branch = 'main', message, files }) => {
63
+ const actions = [];
64
+ for (const [path, content] of Object.entries(files)) {
65
+ let current = null;
66
+ try {
67
+ current = Buffer.from((await provider.getFileRevision({ token, id, path, ref: branch })).content, 'base64').toString('utf8');
68
+ }
69
+ catch (error) {
70
+ if (error.status !== 404)
71
+ throw error;
72
+ }
73
+ if (content === null) {
74
+ if (current !== null)
75
+ actions.push({ action: 'delete', path });
76
+ }
77
+ else if (current !== content) {
78
+ actions.push({ action: current !== null ? 'update' : 'create', path, content });
79
+ }
80
+ }
81
+ if (actions.length === 0)
82
+ return null;
83
+ return provider.commit({ token, id, branch, message, actions, track: false });
84
+ };
85
+ /** The packages of one kind the user can see, with their versions. */
86
+ export const listPackages = async ({ provider, token, kind, config, userId = 'anonymous' }) => {
87
+ const topic = KIND_DEFINITIONS[kind].topic;
88
+ const repositories = await provider.listRepositories({ token, topic });
89
+ const summaries = [];
90
+ for (let i = 0; i < repositories.length; i += CONCURRENCY) {
91
+ summaries.push(...await Promise.all(repositories.slice(i, i + CONCURRENCY).map(async (repository) => {
92
+ let versions = [];
93
+ try {
94
+ versions = versionsOfTags(await provider.listTags({ token, id: repository.id }));
95
+ }
96
+ catch (error) {
97
+ if (error.status !== 404)
98
+ throw error;
99
+ }
100
+ return summarize({ repository, kind, versions, host: provider.kind });
101
+ })));
102
+ }
103
+ if (provider.kind !== 'github' && config)
104
+ summaries.push(...await listGitHubPackages({ kind, config, userId }));
105
+ return summaries.sort((a, b) => a.path.localeCompare(b.path));
106
+ };
107
+ /**
108
+ * On a deployment that is not on GitHub, the packages of the GitHub owners named in `config.githubOwners`, found by the same topics.
109
+ * They can be used by an SPL like any other; they are read-only here: published and edited on GitHub.
110
+ */
111
+ const listGitHubPackages = async ({ kind, config, userId }) => {
112
+ const owners = config.githubOwners ?? [];
113
+ if (owners.length === 0)
114
+ return [];
115
+ try {
116
+ const client = new GitHubClient({ apiUrl: githubApiUrl(config.github ?? {}) });
117
+ const source = new GitHubPackageSource({ config: config.github ?? {}, userId, client });
118
+ const found = await discoverGitHubPackages({ topic: KIND_DEFINITIONS[kind].topic, owners, source, client, token: config.github?.token });
119
+ return found.map(({ repo, location, versions }) => {
120
+ const sorted = semver.rsort(versions);
121
+ return {
122
+ id: null,
123
+ host: 'github',
124
+ readOnly: true,
125
+ kind,
126
+ location,
127
+ name: repo.name,
128
+ path: repo.full_name,
129
+ description: repo.description ?? '',
130
+ webUrl: repo.html_url,
131
+ versions: sorted,
132
+ latest: sorted[0] ?? null
133
+ };
134
+ });
135
+ }
136
+ catch {
137
+ return []; // GitHub being unreachable (or rate limited) must not take the registry down with it
138
+ }
139
+ };
140
+ /** A new package: a repository with its topic and the files a package of that kind starts with. What it made is undone if it fails. */
141
+ export const createPackage = async ({ provider, token, kind, name, description, namespaceId, catalog }) => {
142
+ if (!NAME_PATTERN.test(name))
143
+ throw new Error(`"${name}" is not a valid package name`);
144
+ const definition = KIND_DEFINITIONS[kind];
145
+ try {
146
+ const repository = await provider.createRepository({ token, name, namespaceId: namespaceId ?? undefined, topics: [definition.topic] });
147
+ for (const [path, content] of Object.entries(definition.scaffold({ name, description }))) {
148
+ await provider.createFile({ token, id: repository.id, path, branch: 'main', content });
149
+ }
150
+ const summary = summarize({ repository: { ...repository, description: description ?? '' }, kind, versions: [], host: provider.kind });
151
+ if (catalog)
152
+ await catalog.add({ entry: entryFor({ kind, provider, path: repository.path, name, description }) });
153
+ return summary;
154
+ }
155
+ catch (error) {
156
+ await provider.rollback().catch(() => { });
157
+ throw error;
158
+ }
159
+ };
160
+ export const getPackage = async ({ provider, token, kind, id }) => {
161
+ const repository = await packageRepository({ provider, token, kind, id });
162
+ const [files, tags] = await Promise.all([provider.listFiles({ token, id, ref: 'main' }), provider.listTags({ token, id })]);
163
+ let manifest = null;
164
+ let manifestError = null;
165
+ try {
166
+ manifest = await readManifest({ provider, token, kind, id });
167
+ }
168
+ catch (error) {
169
+ manifestError = error.message;
170
+ }
171
+ return { ...summarize({ repository, kind, versions: versionsOfTags(tags), host: provider.kind }), files, manifest, manifestError };
172
+ };
173
+ export const readPackageFile = async ({ provider, token, kind, id, path, ref = 'main' }) => {
174
+ await packageRepository({ provider, token, kind, id });
175
+ if (!isSafePath(path))
176
+ throw new PackageNotFoundError();
177
+ const content = decode(await provider.readFile({ token, id, path, ref }));
178
+ if (content === null)
179
+ throw new PackageNotFoundError();
180
+ return { path, ref, content };
181
+ };
182
+ /** Writes (or, with `content: null`, deletes) one file of a package on `main`. A manifest is checked before it is saved. */
183
+ export const savePackageFile = async ({ provider, token, kind, id, path, content, message }) => {
184
+ await packageRepository({ provider, token, kind, id });
185
+ if (!isSafePath(path))
186
+ throw new PackageNotFoundError();
187
+ const definition = KIND_DEFINITIONS[kind];
188
+ if (path === definition.manifest) {
189
+ if (content === null)
190
+ throw new Error(`${path} cannot be deleted`);
191
+ definition.parse({ content }); // throws ModuleManifestError when it is not valid
192
+ }
193
+ const commit = await upsertFiles({ provider, token, id, message: message ?? `${content === null ? 'Delete' : 'Update'} ${path}`, files: { [path]: content } });
194
+ return { path, committed: commit !== null };
195
+ };
196
+ /**
197
+ * Writes (a string) or deletes (`null`) several files of a package on `main` in ONE commit, so an editor that changed a grammar and its
198
+ * scripts leaves one version in the history instead of five. Every path is checked first, and so is the manifest if it is among them;
199
+ * nothing is written when any of them is not valid.
200
+ */
201
+ export const savePackageFiles = async ({ provider, token, kind, id, files, message }) => {
202
+ await packageRepository({ provider, token, kind, id });
203
+ const paths = Object.keys(files);
204
+ if (paths.length === 0)
205
+ return { paths, committed: false };
206
+ for (const path of paths)
207
+ if (!isSafePath(path))
208
+ throw new PackageNotFoundError();
209
+ const definition = KIND_DEFINITIONS[kind];
210
+ if (definition.manifest in files) {
211
+ const content = files[definition.manifest];
212
+ if (content === null || content === undefined)
213
+ throw new Error(`${definition.manifest} cannot be deleted`);
214
+ definition.parse({ content }); // throws ModuleManifestError when it is not valid
215
+ }
216
+ const commit = await upsertFiles({ provider, token, id, message: message ?? `Update ${paths.length === 1 ? paths[0] : `${paths.length} files`}`, files });
217
+ return { paths, committed: commit !== null };
218
+ };
219
+ /**
220
+ * Publishes the version of `main`: checks that the version is valid semver, higher than the last one published and not already
221
+ * published, checks the package (with `check`, which is given the location and the manifest), tags it `vX.Y.Z` and creates the release of
222
+ * the tag with the changelog since the previous version. With `bump` (`patch`, `minor`, `major`) the version in the manifest is raised
223
+ * first (a commit on `main`), so a package can be released without editing the manifest by hand.
224
+ *
225
+ * `suggestedBump` is what the commits since the last version imply, and `warnings` says when the version does not match it (it never blocks).
226
+ */
227
+ export const publishPackage = async ({ provider, token, kind, id, bump, check }) => {
228
+ const definition = KIND_DEFINITIONS[kind];
229
+ const repository = await packageRepository({ provider, token, kind, id });
230
+ const location = locationOf({ kind: provider.kind, path: repository.path });
231
+ let manifest = await readManifest({ provider, token, kind, id });
232
+ let checked;
233
+ if (bump) {
234
+ const next = semver.inc(manifest.version, bump);
235
+ checked = await preflight({ provider, token, id, version: next, file: definition.manifest }); // before anything is committed
236
+ const raw = JSON.parse(decode(await provider.readFile({ token, id, path: definition.manifest, ref: 'main' })));
237
+ await upsertFiles({ provider, token, id, message: `Bump version to ${next}`, files: { [definition.manifest]: `${JSON.stringify({ ...raw, version: next }, null, 2)}\n` } });
238
+ manifest = await readManifest({ provider, token, kind, id });
239
+ }
240
+ else {
241
+ checked = await preflight({ provider, token, id, version: manifest.version, file: definition.manifest });
242
+ }
243
+ const { suggestedBump, warnings } = checked;
244
+ const tag = `v${manifest.version}`;
245
+ const report = await check({ location, manifest });
246
+ if (!report.ok)
247
+ throw new ModuleCheckError(`${location}@${manifest.version} does not pass its checks`, [...report.diagnostics]);
248
+ await provider.createTag({ token, id, tag, ref: 'main', message: `Release ${manifest.version}` });
249
+ forgetPackageTags(location);
250
+ const { release, warning } = await createPackageRelease({ provider, token, id, tag, name: manifest.name ?? repository.name });
251
+ if (warning)
252
+ warnings.push(warning);
253
+ return { location, version: manifest.version, tag, report, release, suggestedBump, warnings };
254
+ };
255
+ /** The changelog of one version of a package (`1.2.0` or `v1.2.0`), for the catalog to show: its release, or the commits when it has none. */
256
+ export const getPackageChangelog = async ({ provider, token, kind, id, version }) => {
257
+ await packageRepository({ provider, token, kind, id });
258
+ const clean = version.replace(/^v/, '');
259
+ if (!semver.valid(clean))
260
+ throw new PackageNotFoundError();
261
+ const tag = `v${clean}`;
262
+ if (!await provider.getTag({ token, id, tag }))
263
+ throw new PackageNotFoundError();
264
+ const release = await provider.getRelease({ token, id, tag });
265
+ if (release)
266
+ return { version: clean, tag, markdown: release.description, source: 'release', url: release.url };
267
+ const changes = await generateChangelog({ provider, token, id, to: tag });
268
+ return { version: clean, tag, markdown: changes.markdown, source: 'commits', url: '' };
269
+ };
270
+ /** The changelogs of every published version of a package, highest first (one call to the host for all the releases; a version without release is worked out from its commits). */
271
+ export const listPackageChangelogs = async ({ provider, token, kind, id }) => {
272
+ await packageRepository({ provider, token, kind, id });
273
+ const [tags, releases] = await Promise.all([provider.listTags({ token, id }), provider.listReleases({ token, id })]);
274
+ const byTag = new Map(releases.map((release) => [release.tag, release]));
275
+ const versions = versionsOfTags(tags);
276
+ const result = [];
277
+ // a version with no release is worked out from its commits: a few at a time, each one is several calls to the host
278
+ for (let i = 0; i < versions.length; i += CONCURRENCY) {
279
+ result.push(...await Promise.all(versions.slice(i, i + CONCURRENCY).map(async (version) => {
280
+ const tag = tagOf(tags, version);
281
+ const release = byTag.get(tag);
282
+ if (release)
283
+ return { version, tag, markdown: release.description, source: 'release', url: release.url };
284
+ const changes = await generateChangelog({ provider, token, id, to: tag });
285
+ return { version, tag, markdown: changes.markdown, source: 'commits', url: '' };
286
+ })));
287
+ }
288
+ return result;
289
+ };
290
+ //# sourceMappingURL=packages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packages.js","sourceRoot":"","sources":["../../src/registry/packages.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAwC,MAAM,oBAAoB,CAAA;AAEzG,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;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AG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAA6B,EAAE;YACnH,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;YAChC,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAC9B,IAAI,OAAO;gBAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAA;YACxG,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAA;YACzE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,EAAE,CAAA;QACjF,CAAC,CAAC,CAAC,CAAC,CAAA;IACN,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA","sourcesContent":["import semver from 'semver'\nimport { ModuleCheckError, NAME_PATTERN, type Diagnostic, type PackageCatalog } from '@lbdudc/linea-core'\nimport type { GitConfig } from '../config.js'\nimport { generateChangelog } from '../changelog/index.js'\nimport { PackageNotFoundError } from '../errors.js'\nimport { GitHubClient } from '../github/client.js'\nimport { githubApiUrl } from '../github/config.js'\nimport { GitHubPackageSource, discoverGitHubPackages } from '../packages/github-source.js'\nimport { locationOf } from '../packages/index.js'\nimport { forgetPackageTags } from '../packages/gitlab-source.js'\nimport type { GitHostKind, GitProvider, Id, Release, Repository } from '../provider.js'\nimport { entryFor } from './catalog.js'\nimport { KIND_DEFINITIONS, type PackageKind } from './kinds.js'\nimport { createPackageRelease, preflight, tagOf, type BumpLevel, type Preflight } from './release.js'\n\n/**\n * The registry of modules and metamodels, on the git host: repositories with the topic `linea-module` or `linea-metamodel`, whose\n * versions are their `vX.Y.Z` tags. There is no database: the git host is the registry. These are the operations on it; who may do\n * what is for the caller to decide before calling.\n */\n\nconst VERSION_TAG = /^v?(\\d+\\.\\d+\\.\\d+)$/\nconst CONCURRENCY = 5\n\nexport interface PackageSummary {\n id: Id | null\n host: GitHostKind\n kind: PackageKind\n /** `gitlab:group/project`, `github:owner/repo`: what an SPL names it by. */\n location: string\n name: string\n path: string\n description: string\n webUrl: string\n /** Highest first. */\n versions: string[]\n latest: string | null\n /** Listed for use, edited and published elsewhere. */\n readOnly?: boolean\n /** Registered, but its repository cannot be reached (deleted, private, host down). */\n unavailable?: boolean\n}\n\nexport interface PackageDetail extends PackageSummary {\n files: string[]\n manifest: unknown\n manifestError: string | null\n}\n\nexport const versionsOfTags = (tags: { name: string }[]): string[] =>\n semver.rsort(tags.map((tag) => VERSION_TAG.exec(tag.name)?.[1]).filter((version): version is string => Boolean(version)))\n\nconst summarize = ({ repository, kind, versions, host }: { repository: Repository, kind: PackageKind, versions: string[], host: GitHostKind }): PackageSummary => ({\n id: repository.id,\n host,\n kind,\n location: locationOf({ kind: host, path: repository.path }),\n name: repository.name,\n path: repository.path,\n description: repository.description ?? '',\n webUrl: repository.webUrl,\n versions,\n latest: versions[0] ?? null\n})\n\nexport const isSafePath = (path: unknown): path is string =>\n typeof path === 'string' && path !== '' && !path.startsWith('/') && !path.includes('\\\\') && !path.split('/').some((part) => part === '' || part === '..' || part === '.git')\n\nconst decode = (bytes: Buffer | null): string | null => (bytes === null ? null : bytes.toString('utf8'))\n\ninterface Host {\n provider: GitProvider\n token: string\n}\n\n/** The repository of a package, which must be one of that kind. */\nexport const packageRepository = async ({ provider, token, kind, id }: Host & { kind: PackageKind, id: Id }): Promise<Repository> => {\n let repository: Repository\n try {\n repository = await provider.getRepository({ token, id })\n } catch (error) {\n if ((error as { status?: number }).status === 404) throw new PackageNotFoundError()\n throw error\n }\n if (!repository.topics.includes(KIND_DEFINITIONS[kind].topic)) throw new PackageNotFoundError()\n return repository\n}\n\n/** The manifest of a package as it is on `ref` (parsed: a manifest that is not valid throws what linea-core throws). */\nexport const readManifest = async ({ provider, token, kind, id, ref = 'main' }: Host & { kind: PackageKind, id: Id, ref?: string }): Promise<any> => {\n const definition = KIND_DEFINITIONS[kind]\n const content = decode(await provider.readFile({ token, id, path: definition.manifest, ref }))\n if (content === null) throw new PackageNotFoundError(`${definition.manifest} is missing`)\n return definition.parse({ content })\n}\n\n/**\n * Writes several files to a branch in one commit: a string creates or updates the file, `null` deletes it. A file that already has that\n * content is left as it is. Returns `null` without committing when nothing has to change.\n */\nexport const upsertFiles = async ({ provider, token, id, branch = 'main', message, files }: Host & { id: Id, branch?: string, message: string, files: Record<string, string | null> }): Promise<{ id: string } | null> => {\n const actions = []\n for (const [path, content] of Object.entries(files)) {\n let current: string | null = null\n try {\n current = Buffer.from((await provider.getFileRevision({ token, id, path, ref: branch })).content, 'base64').toString('utf8')\n } catch (error) {\n if ((error as { status?: number }).status !== 404) throw error\n }\n if (content === null) {\n if (current !== null) actions.push({ action: 'delete' as const, path })\n } else if (current !== content) {\n actions.push({ action: current !== null ? 'update' as const : 'create' as const, path, content })\n }\n }\n if (actions.length === 0) return null\n return provider.commit({ token, id, branch, message, actions, track: false })\n}\n\n/** The packages of one kind the user can see, with their versions. */\nexport const listPackages = async ({ provider, token, kind, config, userId = 'anonymous' }: Host & { kind: PackageKind, config?: GitConfig, userId?: string | number }): Promise<PackageSummary[]> => {\n const topic = KIND_DEFINITIONS[kind].topic\n const repositories = await provider.listRepositories({ token, topic })\n const summaries: PackageSummary[] = []\n for (let i = 0; i < repositories.length; i += CONCURRENCY) {\n summaries.push(...await Promise.all(repositories.slice(i, i + CONCURRENCY).map(async (repository) => {\n let versions: string[] = []\n try {\n versions = versionsOfTags(await provider.listTags({ token, id: repository.id }))\n } catch (error) {\n if ((error as { status?: number }).status !== 404) throw error\n }\n return summarize({ repository, kind, versions, host: provider.kind })\n })))\n }\n if (provider.kind !== 'github' && config) summaries.push(...await listGitHubPackages({ kind, config, userId }))\n return summaries.sort((a, b) => a.path.localeCompare(b.path))\n}\n\n/**\n * On a deployment that is not on GitHub, the packages of the GitHub owners named in `config.githubOwners`, found by the same topics.\n * They can be used by an SPL like any other; they are read-only here: published and edited on GitHub.\n */\nconst listGitHubPackages = async ({ kind, config, userId }: { kind: PackageKind, config: GitConfig, userId: string | number }): Promise<PackageSummary[]> => {\n const owners = config.githubOwners ?? []\n if (owners.length === 0) return []\n try {\n const client = new GitHubClient({ apiUrl: githubApiUrl(config.github ?? {}) })\n const source = new GitHubPackageSource({ config: config.github ?? {}, userId, client })\n const found = await discoverGitHubPackages({ topic: KIND_DEFINITIONS[kind].topic, owners, source, client, token: config.github?.token })\n return found.map(({ repo, location, versions }) => {\n const sorted = semver.rsort(versions)\n return {\n id: null,\n host: 'github' as const,\n readOnly: true,\n kind,\n location,\n name: repo.name,\n path: repo.full_name,\n description: repo.description ?? '',\n webUrl: repo.html_url,\n versions: sorted,\n latest: sorted[0] ?? null\n }\n })\n } catch {\n return [] // GitHub being unreachable (or rate limited) must not take the registry down with it\n }\n}\n\n/** A new package: a repository with its topic and the files a package of that kind starts with. What it made is undone if it fails. */\nexport const createPackage = async ({ provider, token, kind, name, description, namespaceId, catalog }: Host & { kind: PackageKind, name: string, description?: string | undefined, namespaceId?: Id | null | undefined, catalog?: PackageCatalog | undefined }): Promise<PackageSummary> => {\n if (!NAME_PATTERN.test(name)) throw new Error(`\"${name}\" is not a valid package name`)\n const definition = KIND_DEFINITIONS[kind]\n try {\n const repository = await provider.createRepository({ token, name, namespaceId: namespaceId ?? undefined, topics: [definition.topic] })\n for (const [path, content] of Object.entries(definition.scaffold({ name, description }))) {\n await provider.createFile({ token, id: repository.id, path, branch: 'main', content })\n }\n const summary = summarize({ repository: { ...repository, description: description ?? '' }, kind, versions: [], host: provider.kind })\n if (catalog) await catalog.add({ entry: entryFor({ kind, provider, path: repository.path, name, description }) })\n return summary\n } catch (error) {\n await provider.rollback().catch(() => {})\n throw error\n }\n}\n\nexport const getPackage = async ({ provider, token, kind, id }: Host & { kind: PackageKind, id: Id }): Promise<PackageDetail> => {\n const repository = await packageRepository({ provider, token, kind, id })\n const [files, tags] = await Promise.all([provider.listFiles({ token, id, ref: 'main' }), provider.listTags({ token, id })])\n let manifest: unknown = null\n let manifestError: string | null = null\n try {\n manifest = await readManifest({ provider, token, kind, id })\n } catch (error) {\n manifestError = (error as Error).message\n }\n return { ...summarize({ repository, kind, versions: versionsOfTags(tags), host: provider.kind }), files, manifest, manifestError }\n}\n\nexport const readPackageFile = async ({ provider, token, kind, id, path, ref = 'main' }: Host & { kind: PackageKind, id: Id, path: string, ref?: string }): Promise<{ path: string, ref: string, content: string }> => {\n await packageRepository({ provider, token, kind, id })\n if (!isSafePath(path)) throw new PackageNotFoundError()\n const content = decode(await provider.readFile({ token, id, path, ref }))\n if (content === null) throw new PackageNotFoundError()\n return { path, ref, content }\n}\n\n/** Writes (or, with `content: null`, deletes) one file of a package on `main`. A manifest is checked before it is saved. */\nexport const savePackageFile = async ({ provider, token, kind, id, path, content, message }: Host & { kind: PackageKind, id: Id, path: string, content: string | null, message?: string | undefined }): Promise<{ path: string, committed: boolean }> => {\n await packageRepository({ provider, token, kind, id })\n if (!isSafePath(path)) throw new PackageNotFoundError()\n const definition = KIND_DEFINITIONS[kind]\n if (path === definition.manifest) {\n if (content === null) throw new Error(`${path} cannot be deleted`)\n definition.parse({ content }) // throws ModuleManifestError when it is not valid\n }\n const commit = await upsertFiles({ provider, token, id, message: message ?? `${content === null ? 'Delete' : 'Update'} ${path}`, files: { [path]: content } })\n return { path, committed: commit !== null }\n}\n\n/**\n * Writes (a string) or deletes (`null`) several files of a package on `main` in ONE commit, so an editor that changed a grammar and its\n * scripts leaves one version in the history instead of five. Every path is checked first, and so is the manifest if it is among them;\n * nothing is written when any of them is not valid.\n */\nexport const savePackageFiles = async ({ provider, token, kind, id, files, message }: Host & { kind: PackageKind, id: Id, files: Record<string, string | null>, message?: string | undefined }): Promise<{ paths: string[], committed: boolean }> => {\n await packageRepository({ provider, token, kind, id })\n const paths = Object.keys(files)\n if (paths.length === 0) return { paths, committed: false }\n for (const path of paths) if (!isSafePath(path)) throw new PackageNotFoundError()\n const definition = KIND_DEFINITIONS[kind]\n if (definition.manifest in files) {\n const content = files[definition.manifest]\n if (content === null || content === undefined) throw new Error(`${definition.manifest} cannot be deleted`)\n definition.parse({ content }) // throws ModuleManifestError when it is not valid\n }\n const commit = await upsertFiles({ provider, token, id, message: message ?? `Update ${paths.length === 1 ? paths[0] : `${paths.length} files`}`, files })\n return { paths, committed: commit !== null }\n}\n\nexport interface PackageCheck {\n ok: boolean\n diagnostics: readonly Diagnostic[]\n [key: string]: unknown\n}\n\n/**\n * Publishes the version of `main`: checks that the version is valid semver, higher than the last one published and not already\n * published, checks the package (with `check`, which is given the location and the manifest), tags it `vX.Y.Z` and creates the release of\n * the tag with the changelog since the previous version. With `bump` (`patch`, `minor`, `major`) the version in the manifest is raised\n * first (a commit on `main`), so a package can be released without editing the manifest by hand.\n *\n * `suggestedBump` is what the commits since the last version imply, and `warnings` says when the version does not match it (it never blocks).\n */\nexport const publishPackage = async ({ provider, token, kind, id, bump, check }: Host & {\n kind: PackageKind\n id: Id\n bump?: semver.ReleaseType | undefined\n check: (args: { location: string, manifest: any }) => Promise<PackageCheck>\n}): Promise<{ location: string, version: string, tag: string, report: PackageCheck, release: Release | null, suggestedBump: BumpLevel | null, warnings: string[] }> => {\n const definition = KIND_DEFINITIONS[kind]\n const repository = await packageRepository({ provider, token, kind, id })\n const location = locationOf({ kind: provider.kind, path: repository.path })\n let manifest = await readManifest({ provider, token, kind, id })\n\n let checked: Preflight\n if (bump) {\n const next = semver.inc(manifest.version, bump)\n checked = await preflight({ provider, token, id, version: next, file: definition.manifest }) // before anything is committed\n const raw = JSON.parse(decode(await provider.readFile({ token, id, path: definition.manifest, ref: 'main' })) as string)\n await upsertFiles({ provider, token, id, message: `Bump version to ${next}`, files: { [definition.manifest]: `${JSON.stringify({ ...raw, version: next }, null, 2)}\\n` } })\n manifest = await readManifest({ provider, token, kind, id })\n } else {\n checked = await preflight({ provider, token, id, version: manifest.version, file: definition.manifest })\n }\n const { suggestedBump, warnings } = checked\n const tag = `v${manifest.version}`\n const report = await check({ location, manifest })\n if (!report.ok) throw new ModuleCheckError(`${location}@${manifest.version} does not pass its checks`, [...report.diagnostics])\n await provider.createTag({ token, id, tag, ref: 'main', message: `Release ${manifest.version}` })\n forgetPackageTags(location)\n const { release, warning } = await createPackageRelease({ provider, token, id, tag, name: manifest.name ?? repository.name })\n if (warning) warnings.push(warning)\n return { location, version: manifest.version, tag, report, release, suggestedBump, warnings }\n}\n\nexport interface PackageChangelog {\n version: string\n tag: string\n /** Markdown, made from commit messages that whoever can push wrote: a page that shows it has to sanitize it (HTML included). */\n markdown: string\n /** The release the host holds, or the changelog worked out from the commits for a version that was tagged without one. */\n source: 'release' | 'commits'\n /** The page of the release on the host (empty when there is none). */\n url: string\n}\n\n/** The changelog of one version of a package (`1.2.0` or `v1.2.0`), for the catalog to show: its release, or the commits when it has none. */\nexport const getPackageChangelog = async ({ provider, token, kind, id, version }: Host & { kind: PackageKind, id: Id, version: string }): Promise<PackageChangelog> => {\n await packageRepository({ provider, token, kind, id })\n const clean = version.replace(/^v/, '')\n if (!semver.valid(clean)) throw new PackageNotFoundError()\n const tag = `v${clean}`\n if (!await provider.getTag({ token, id, tag })) throw new PackageNotFoundError()\n const release = await provider.getRelease({ token, id, tag })\n if (release) return { version: clean, tag, markdown: release.description, source: 'release', url: release.url }\n const changes = await generateChangelog({ provider, token, id, to: tag })\n return { version: clean, tag, markdown: changes.markdown, source: 'commits', url: '' }\n}\n\n/** The changelogs of every published version of a package, highest first (one call to the host for all the releases; a version without release is worked out from its commits). */\nexport const listPackageChangelogs = async ({ provider, token, kind, id }: Host & { kind: PackageKind, id: Id }): Promise<PackageChangelog[]> => {\n await packageRepository({ provider, token, kind, id })\n const [tags, releases] = await Promise.all([provider.listTags({ token, id }), provider.listReleases({ token, id })])\n const byTag = new Map(releases.map((release) => [release.tag, release]))\n const versions = versionsOfTags(tags)\n const result: PackageChangelog[] = []\n // a version with no release is worked out from its commits: a few at a time, each one is several calls to the host\n for (let i = 0; i < versions.length; i += CONCURRENCY) {\n result.push(...await Promise.all(versions.slice(i, i + CONCURRENCY).map(async (version): Promise<PackageChangelog> => {\n const tag = tagOf(tags, version)\n const release = byTag.get(tag)\n if (release) return { version, tag, markdown: release.description, source: 'release', url: release.url }\n const changes = await generateChangelog({ provider, token, id, to: tag })\n return { version, tag, markdown: changes.markdown, source: 'commits', url: '' }\n })))\n }\n return result\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import type { PackageCatalog } from '@lbdudc/linea-core';
2
+ import type { GitProvider } from '../provider.js';
3
+ import { type PackageKind } from './kinds.js';
4
+ import { type BumpLevel } from './release.js';
5
+ export interface PublishedPackage {
6
+ kind: PackageKind;
7
+ name: string;
8
+ version: string;
9
+ /** Where it is, as the host shows it. */
10
+ path: string;
11
+ status: 'published' | 'already-published' | 'dry-run';
12
+ /** What the commits since the last published version imply (only when it was published and there was a version before). */
13
+ suggestedBump?: BumpLevel | null;
14
+ /** Things worth knowing that did not stop it: the version does not match the commits, the release could not be made. */
15
+ warnings?: string[];
16
+ }
17
+ export interface PublishFolderOptions {
18
+ provider: GitProvider;
19
+ token: string;
20
+ /** The folder with `metamodels/` and `modules/`. */
21
+ dir: string;
22
+ /** GitLab: the path of an existing group to publish under. GitHub: the user or organisation that owns the repositories. */
23
+ root: string;
24
+ /** Only these kinds (both by default, metamodels first). */
25
+ kinds?: PackageKind[];
26
+ /** Only the package with this name. */
27
+ only?: string;
28
+ dryRun?: boolean;
29
+ /** A version that is already published is reported (`already-published`) and left alone, instead of refused with `PackageVersionExistsError`. */
30
+ skipPublished?: boolean;
31
+ /** Every package it publishes (or finds already published) is registered here, with the description of its manifest. */
32
+ catalog?: PackageCatalog;
33
+ log?: (line: string) => void;
34
+ }
35
+ export declare const publishFolder: ({ provider, token, dir, root, kinds, only, dryRun, skipPublished, catalog, log }: PublishFolderOptions) => Promise<PublishedPackage[]>;