@jini-ai/registry 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/dist/database-backend.d.ts +46 -0
- package/dist/database-backend.d.ts.map +1 -0
- package/dist/database-backend.js +149 -0
- package/dist/database-backend.js.map +1 -0
- package/dist/github-backend.d.ts +68 -0
- package/dist/github-backend.d.ts.map +1 -0
- package/dist/github-backend.js +157 -0
- package/dist/github-backend.js.map +1 -0
- package/dist/github-client.d.ts +116 -0
- package/dist/github-client.d.ts.map +1 -0
- package/dist/github-client.js +272 -0
- package/dist/github-client.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/static-backend.d.ts +68 -0
- package/dist/static-backend.d.ts.map +1 -0
- package/dist/static-backend.js +281 -0
- package/dist/static-backend.js.map +1 -0
- package/dist/trust.d.ts +94 -0
- package/dist/trust.d.ts.map +1 -0
- package/dist/trust.js +295 -0
- package/dist/trust.js.map +1 -0
- package/dist/versioning.d.ts +47 -0
- package/dist/versioning.d.ts.map +1 -0
- package/dist/versioning.js +205 -0
- package/dist/versioning.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Open Design contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module database-backend
|
|
3
|
+
*
|
|
4
|
+
* A `RegistryBackend` backed by a `better-sqlite3` table: one row per entry
|
|
5
|
+
* name, keyed by `(backendId, name)`, with the full {@link RegistryEntry}
|
|
6
|
+
* stored as JSON. `list`/`search`/`resolve`/`doctor` reuse `StaticRegistryBackend`
|
|
7
|
+
* by re-reading the whole table into an in-memory manifest snapshot on every
|
|
8
|
+
* call (`getManifest()` override) — simple and correct for the entry counts a
|
|
9
|
+
* registry realistically holds; `publish`/`yank` write straight to the table.
|
|
10
|
+
*/
|
|
11
|
+
import type Database from 'better-sqlite3';
|
|
12
|
+
import { type RegistryEntry, type RegistryManifest, type RegistryPublishOutcome, type RegistryPublishRequest, type RegistryTrust, type RegistryYankOutcome } from '@jini-ai/protocol';
|
|
13
|
+
import { StaticRegistryBackend } from './static-backend.js';
|
|
14
|
+
import type { RegistryTrustRoot } from './trust.js';
|
|
15
|
+
type SqliteDb = Database.Database;
|
|
16
|
+
export interface DatabaseRegistryBackendOptions {
|
|
17
|
+
id: string;
|
|
18
|
+
trust?: RegistryTrust;
|
|
19
|
+
db: SqliteDb;
|
|
20
|
+
/** Optional `github-oidc` signature trust root — see `StaticRegistryBackendOptions.trustRoot`'s doc comment for what configuring (or omitting) this does. */
|
|
21
|
+
trustRoot?: RegistryTrustRoot | undefined;
|
|
22
|
+
}
|
|
23
|
+
export declare class DatabaseRegistryBackend extends StaticRegistryBackend {
|
|
24
|
+
readonly db: SqliteDb;
|
|
25
|
+
constructor(options: DatabaseRegistryBackendOptions);
|
|
26
|
+
publish(request: RegistryPublishRequest): Promise<RegistryPublishOutcome>;
|
|
27
|
+
yank(name: string, version: string, reason: string): Promise<RegistryYankOutcome>;
|
|
28
|
+
protected getManifest(): RegistryManifest;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create the `registry_entries` table if it does not already exist.
|
|
32
|
+
*
|
|
33
|
+
* @param db - The sqlite connection to migrate.
|
|
34
|
+
*/
|
|
35
|
+
export declare function ensureRegistryTables(db: SqliteDb): void;
|
|
36
|
+
/**
|
|
37
|
+
* Insert or update one registry entry's row for a given backend.
|
|
38
|
+
*
|
|
39
|
+
* @param db - The sqlite connection to write to.
|
|
40
|
+
* @param backendId - The owning backend's id (part of the row's primary key).
|
|
41
|
+
* @param entry - The entry to store (serialized as JSON).
|
|
42
|
+
* @param now - Timestamp to record as `updated_at` (defaults to `Date.now()`).
|
|
43
|
+
*/
|
|
44
|
+
export declare function upsertRegistryEntry(db: SqliteDb, backendId: string, entry: RegistryEntry, now?: number): void;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=database-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-backend.d.ts","sourceRoot":"","sources":["../src/database-backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAA6B,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,KAAK,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;AAElC,MAAM,WAAW,8BAA8B;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,EAAE,EAAE,QAAQ,CAAC;IACb,6JAA6J;IAC7J,SAAS,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;CAC3C;AAED,qBAAa,uBAAwB,SAAQ,qBAAqB;IAChE,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;gBAEV,OAAO,EAAE,8BAA8B;IAY7C,OAAO,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAsBzE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;cAwCpE,WAAW,IAAI,gBAAgB;CAGnD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAWvD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,SAAa,GAAG,IAAI,CASjH"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { RegistryEntrySchema, } from '@jini-ai/protocol';
|
|
2
|
+
import { assertValidPublishRequest, StaticRegistryBackend } from './static-backend.js';
|
|
3
|
+
export class DatabaseRegistryBackend extends StaticRegistryBackend {
|
|
4
|
+
db;
|
|
5
|
+
constructor(options) {
|
|
6
|
+
ensureRegistryTables(options.db);
|
|
7
|
+
super({
|
|
8
|
+
id: options.id,
|
|
9
|
+
kind: 'db',
|
|
10
|
+
trust: options.trust ?? 'restricted',
|
|
11
|
+
manifest: manifestFromDb(options.db, options.id),
|
|
12
|
+
trustRoot: options.trustRoot,
|
|
13
|
+
});
|
|
14
|
+
this.db = options.db;
|
|
15
|
+
}
|
|
16
|
+
async publish(request) {
|
|
17
|
+
// Validate the whole request against the wire schema before writing
|
|
18
|
+
// anything: `manifestFromDb()`/`parseStoredEntry()` throw on read for
|
|
19
|
+
// any row that fails `RegistryEntrySchema`, so an unvalidated publish
|
|
20
|
+
// could write a row that permanently breaks every future
|
|
21
|
+
// `list`/`search`/`resolve`/`doctor` call for this backend (see CR-009 /
|
|
22
|
+
// `assertValidPublishRequest`'s docs in `static-backend.ts`).
|
|
23
|
+
const parsed = assertValidPublishRequest(request);
|
|
24
|
+
const [vendor, name] = parsed.entry.name.split('/');
|
|
25
|
+
const changedFiles = [
|
|
26
|
+
`db://${this.id}/entries/${vendor}/${name}`,
|
|
27
|
+
`db://${this.id}/entries/${vendor}/${name}/versions/${parsed.entry.version}`,
|
|
28
|
+
];
|
|
29
|
+
// A dry-run publish must not mutate the database — only report what
|
|
30
|
+
// *would* change — and must say so honestly in the outcome.
|
|
31
|
+
if (parsed.dryRun) {
|
|
32
|
+
return { ok: true, dryRun: true, changedFiles, warnings: [] };
|
|
33
|
+
}
|
|
34
|
+
upsertRegistryEntry(this.db, this.id, parsed.entry);
|
|
35
|
+
return { ok: true, dryRun: false, changedFiles, warnings: [] };
|
|
36
|
+
}
|
|
37
|
+
async yank(name, version, reason) {
|
|
38
|
+
// Read-then-write: run as a single `IMMEDIATE` transaction rather than
|
|
39
|
+
// two separate auto-committing statements. Two bare statements leave a
|
|
40
|
+
// window — between the SELECT and the later UPSERT — where a concurrent
|
|
41
|
+
// writer (a second connection/process sharing this database file, e.g.
|
|
42
|
+
// another daemon instance) can commit a change to the same row; this
|
|
43
|
+
// yank would then compute `nextVersions` from stale data and silently
|
|
44
|
+
// clobber that concurrent change when it writes (a lost update).
|
|
45
|
+
// `.immediate` acquires the write lock at the *start* of the
|
|
46
|
+
// transaction, before the SELECT even runs, so a concurrent writer is
|
|
47
|
+
// rejected for the whole operation instead of being able to interleave.
|
|
48
|
+
const runYank = this.db.transaction(() => {
|
|
49
|
+
const row = this.db
|
|
50
|
+
.prepare(`SELECT entry_json FROM registry_entries WHERE backend_id = ? AND name = ?`)
|
|
51
|
+
.get(this.id, name);
|
|
52
|
+
if (!row) {
|
|
53
|
+
return { ok: false, name, version, reason, warnings: [`${name} not found`] };
|
|
54
|
+
}
|
|
55
|
+
const entry = parseStoredEntry(row.entry_json, `${this.id}/${name}`);
|
|
56
|
+
const versions = entry.versions ?? [{ version: entry.version, source: entry.source }];
|
|
57
|
+
// Reject a yank of a version that never existed instead of reporting a
|
|
58
|
+
// false success — mutating nothing while still returning `ok: true`
|
|
59
|
+
// would let a caller believe a nonexistent version was suppressed.
|
|
60
|
+
const exists = versions.some((item) => item.version === version);
|
|
61
|
+
if (!exists) {
|
|
62
|
+
return { ok: false, name, version, reason, warnings: [`${name}@${version} not found`] };
|
|
63
|
+
}
|
|
64
|
+
const nextVersions = versions.map((item) => item.version === version ? { ...item, yanked: true, yankedAt: new Date().toISOString(), yankReason: reason } : item);
|
|
65
|
+
upsertRegistryEntry(this.db, this.id, {
|
|
66
|
+
...entry,
|
|
67
|
+
versions: nextVersions,
|
|
68
|
+
...(entry.version === version ? { yanked: true, yankedAt: new Date().toISOString(), yankReason: reason } : {}),
|
|
69
|
+
});
|
|
70
|
+
return { ok: true, name, version, reason, warnings: [] };
|
|
71
|
+
});
|
|
72
|
+
return runYank.immediate();
|
|
73
|
+
}
|
|
74
|
+
getManifest() {
|
|
75
|
+
return manifestFromDb(this.db, this.id);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create the `registry_entries` table if it does not already exist.
|
|
80
|
+
*
|
|
81
|
+
* @param db - The sqlite connection to migrate.
|
|
82
|
+
*/
|
|
83
|
+
export function ensureRegistryTables(db) {
|
|
84
|
+
db.exec(`
|
|
85
|
+
CREATE TABLE IF NOT EXISTS registry_entries (
|
|
86
|
+
backend_id TEXT NOT NULL,
|
|
87
|
+
name TEXT NOT NULL,
|
|
88
|
+
version TEXT NOT NULL,
|
|
89
|
+
entry_json TEXT NOT NULL,
|
|
90
|
+
updated_at INTEGER NOT NULL,
|
|
91
|
+
PRIMARY KEY (backend_id, name)
|
|
92
|
+
)
|
|
93
|
+
`);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Insert or update one registry entry's row for a given backend.
|
|
97
|
+
*
|
|
98
|
+
* @param db - The sqlite connection to write to.
|
|
99
|
+
* @param backendId - The owning backend's id (part of the row's primary key).
|
|
100
|
+
* @param entry - The entry to store (serialized as JSON).
|
|
101
|
+
* @param now - Timestamp to record as `updated_at` (defaults to `Date.now()`).
|
|
102
|
+
*/
|
|
103
|
+
export function upsertRegistryEntry(db, backendId, entry, now = Date.now()) {
|
|
104
|
+
db.prepare(`
|
|
105
|
+
INSERT INTO registry_entries (backend_id, name, version, entry_json, updated_at)
|
|
106
|
+
VALUES (?, ?, ?, ?, ?)
|
|
107
|
+
ON CONFLICT(backend_id, name) DO UPDATE SET
|
|
108
|
+
version = excluded.version,
|
|
109
|
+
entry_json = excluded.entry_json,
|
|
110
|
+
updated_at = excluded.updated_at
|
|
111
|
+
`).run(backendId, entry.name, entry.version, JSON.stringify(entry), now);
|
|
112
|
+
}
|
|
113
|
+
function manifestFromDb(db, backendId) {
|
|
114
|
+
const rows = db
|
|
115
|
+
.prepare(`SELECT entry_json FROM registry_entries WHERE backend_id = ? ORDER BY name ASC`)
|
|
116
|
+
.all(backendId);
|
|
117
|
+
return {
|
|
118
|
+
specVersion: '1.0.0',
|
|
119
|
+
name: backendId,
|
|
120
|
+
version: '0.0.0',
|
|
121
|
+
entries: rows.map((row) => parseStoredEntry(row.entry_json, `${backendId}/${row.name}`)),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Parse and schema-validate a stored `entry_json` row. A row can only get
|
|
126
|
+
* into this shape through `upsertRegistryEntry`'s own `JSON.stringify`, but
|
|
127
|
+
* the table is a plain TEXT column any process/migration/manual edit can
|
|
128
|
+
* corrupt — parsing it unchecked would crash every operation that reads the
|
|
129
|
+
* table (`list`/`search`/`resolve`/`doctor`/`yank`) on the first bad row.
|
|
130
|
+
* Fail with one clear, attributable error instead.
|
|
131
|
+
*
|
|
132
|
+
* @param raw - The raw `entry_json` column value.
|
|
133
|
+
* @param context - `backendId/name` (or similar) included in the error for diagnosis.
|
|
134
|
+
*/
|
|
135
|
+
function parseStoredEntry(raw, context) {
|
|
136
|
+
let candidate;
|
|
137
|
+
try {
|
|
138
|
+
candidate = JSON.parse(raw);
|
|
139
|
+
}
|
|
140
|
+
catch (cause) {
|
|
141
|
+
throw new Error(`Corrupt registry_entries row (${context}): entry_json is not valid JSON.`, { cause });
|
|
142
|
+
}
|
|
143
|
+
const parsed = RegistryEntrySchema.safeParse(candidate);
|
|
144
|
+
if (!parsed.success) {
|
|
145
|
+
throw new Error(`Corrupt registry_entries row (${context}): stored entry does not match RegistryEntrySchema: ${parsed.error.message}`);
|
|
146
|
+
}
|
|
147
|
+
return parsed.data;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=database-backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-backend.js","sourceRoot":"","sources":["../src/database-backend.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,mBAAmB,GAOpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAavF,MAAM,OAAO,uBAAwB,SAAQ,qBAAqB;IACvD,EAAE,CAAW;IAEtB,YAAY,OAAuC;QACjD,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACjC,KAAK,CAAC;YACJ,EAAE,EAAE,OAAO,CAAC,EAAE;YACd,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,YAAY;YACpC,QAAQ,EAAE,cAAc,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,CAAC;YAChD,SAAS,EAAE,OAAO,CAAC,SAAS;SAC7B,CAAC,CAAC;QACH,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAA+B;QAC3C,oEAAoE;QACpE,sEAAsE;QACtE,sEAAsE;QACtE,yDAAyD;QACzD,yEAAyE;QACzE,8DAA8D;QAC9D,MAAM,MAAM,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAC;QAClD,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACpD,MAAM,YAAY,GAAG;YACnB,QAAQ,IAAI,CAAC,EAAE,YAAY,MAA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CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,iCAAiC,OAAO,kCAAkC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IACzG,CAAC;IACD,MAAM,MAAM,GAAG,mBAAmB,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACxD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,iCAAiC,OAAO,uDAAuD,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACzI,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module github-backend
|
|
3
|
+
*
|
|
4
|
+
* A `RegistryBackend` whose manifest lives in a GitHub repository. Reads the
|
|
5
|
+
* whole manifest once (via an injected {@link GithubRegistryClient}) and
|
|
6
|
+
* serves `list`/`search`/`resolve`/`doctor` from that in-memory snapshot
|
|
7
|
+
* exactly like `StaticRegistryBackend`; `publish`/`yank` open a pull request
|
|
8
|
+
* against the same repo (or return a dry-run payload when the client has no
|
|
9
|
+
* mutation capability configured).
|
|
10
|
+
*/
|
|
11
|
+
import type { RegistryManifest, RegistryPublishOutcome, RegistryPublishRequest, RegistryTrust, RegistryYankOutcome } from '@jini-ai/protocol';
|
|
12
|
+
import { StaticRegistryBackend } from './static-backend.js';
|
|
13
|
+
import type { RegistryTrustRoot } from './trust.js';
|
|
14
|
+
/** Read/write access to a GitHub-hosted registry manifest, injected by the host. */
|
|
15
|
+
export interface GithubRegistryClient {
|
|
16
|
+
readManifest(owner: string, repo: string, ref: string, path: string): Promise<RegistryManifest>;
|
|
17
|
+
createPublishPullRequest?(request: GithubPublishMutation): Promise<{
|
|
18
|
+
url: string;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
export interface GithubPublishMutation {
|
|
22
|
+
owner: string;
|
|
23
|
+
repo: string;
|
|
24
|
+
baseRef: string;
|
|
25
|
+
branchName: string;
|
|
26
|
+
title: string;
|
|
27
|
+
body: string;
|
|
28
|
+
files: Array<{
|
|
29
|
+
path: string;
|
|
30
|
+
content: string;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
export interface GithubRegistryBackendOptions {
|
|
34
|
+
id: string;
|
|
35
|
+
owner: string;
|
|
36
|
+
repo: string;
|
|
37
|
+
ref?: string;
|
|
38
|
+
manifestPath?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Trust level to publish this backend under. There is no signature/allowlist
|
|
41
|
+
* proof tying a GitHub `owner/repo/ref` to any trust class, so this MUST be
|
|
42
|
+
* an explicit decision by the host wiring the backend up — it is never
|
|
43
|
+
* inferred from the fact that the source happens to be GitHub. Defaults to
|
|
44
|
+
* the least-privileged `'restricted'` when omitted.
|
|
45
|
+
*/
|
|
46
|
+
trust?: RegistryTrust;
|
|
47
|
+
client: GithubRegistryClient;
|
|
48
|
+
/** Optional `github-oidc` signature trust root — see `StaticRegistryBackendOptions.trustRoot`'s doc comment for what configuring (or omitting) this does. */
|
|
49
|
+
trustRoot?: RegistryTrustRoot | undefined;
|
|
50
|
+
}
|
|
51
|
+
export declare class GithubRegistryBackend extends StaticRegistryBackend {
|
|
52
|
+
readonly owner: string;
|
|
53
|
+
readonly repo: string;
|
|
54
|
+
readonly ref: string;
|
|
55
|
+
readonly manifestPath: string;
|
|
56
|
+
readonly client: GithubRegistryClient;
|
|
57
|
+
private constructor();
|
|
58
|
+
/**
|
|
59
|
+
* Read the manifest from the configured GitHub path and construct the backend.
|
|
60
|
+
*
|
|
61
|
+
* @param options - Repo coordinates, optional ref/path, and the client to read/write through.
|
|
62
|
+
* @returns The constructed backend, already holding its first manifest snapshot.
|
|
63
|
+
*/
|
|
64
|
+
static create(options: GithubRegistryBackendOptions): Promise<GithubRegistryBackend>;
|
|
65
|
+
publish(request: RegistryPublishRequest): Promise<RegistryPublishOutcome>;
|
|
66
|
+
yank(name: string, version: string, reason: string): Promise<RegistryYankOutcome>;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=github-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-backend.d.ts","sourceRoot":"","sources":["../src/github-backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EACV,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAA6B,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AA6CpD,oFAAoF;AACpF,MAAM,WAAW,oBAAoB;IACnC,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAChG,wBAAwB,CAAC,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACrF;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,4BAA4B;IAC3C,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,6JAA6J;IAC7J,SAAS,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;CAC3C;AAID,qBAAa,qBAAsB,SAAQ,qBAAqB;IAC9D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAKtC,OAAO;IAaP;;;;;OAKG;WACU,MAAM,CAAC,OAAO,EAAE,4BAA4B,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAOpF,OAAO,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAyCzE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAkCxF"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { assertValidPublishRequest, StaticRegistryBackend } from './static-backend.js';
|
|
2
|
+
/** `vendor/name` — deliberately the same shape `RegistryEntrySchema.name` requires. */
|
|
3
|
+
const SAFE_ENTRY_NAME = /^([a-z0-9][a-z0-9._-]*)\/([a-z0-9][a-z0-9._-]*)$/;
|
|
4
|
+
/** A single safe path/branch segment: alnum-bounded, no separators, no traversal. */
|
|
5
|
+
const SAFE_VERSION = /^[A-Za-z0-9](?:[A-Za-z0-9._+-]*[A-Za-z0-9])?$/;
|
|
6
|
+
// eslint-disable-next-line no-control-regex -- deliberately matching C0/DEL control bytes.
|
|
7
|
+
const CONTROL_CHARS = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/;
|
|
8
|
+
/**
|
|
9
|
+
* Split and validate a registry entry name into safe `vendor`/`name` path
|
|
10
|
+
* segments. `publish`/`yank` are public methods that take plain strings from
|
|
11
|
+
* an untyped JS caller — TypeScript's compile-time `RegistryEntry`/`string`
|
|
12
|
+
* types give no runtime guarantee, so this boundary must reject path
|
|
13
|
+
* traversal (`..`, `/`) and anything else that isn't the expected shape
|
|
14
|
+
* before the value is used to build a file path or PR branch name.
|
|
15
|
+
*/
|
|
16
|
+
function assertSafeEntryName(name) {
|
|
17
|
+
const match = SAFE_ENTRY_NAME.exec(name);
|
|
18
|
+
if (!match) {
|
|
19
|
+
throw new Error(`Invalid registry entry name ${JSON.stringify(name)}: expected "vendor/name" (lowercase letters, digits, ".", "_", "-").`);
|
|
20
|
+
}
|
|
21
|
+
return [match[1], match[2]];
|
|
22
|
+
}
|
|
23
|
+
/** Validate a version string used to build a file path/branch name segment. */
|
|
24
|
+
function assertSafeVersion(version) {
|
|
25
|
+
if (!SAFE_VERSION.test(version)) {
|
|
26
|
+
throw new Error(`Invalid version ${JSON.stringify(version)}: expected a safe identifier (letters, digits, ".", "_", "+", "-").`);
|
|
27
|
+
}
|
|
28
|
+
return version;
|
|
29
|
+
}
|
|
30
|
+
/** Reject control characters (including NUL) in free-text fields embedded in a PR title/body. */
|
|
31
|
+
function assertNoControlChars(value, label) {
|
|
32
|
+
if (CONTROL_CHARS.test(value)) {
|
|
33
|
+
throw new Error(`Invalid ${label}: control characters are not allowed.`);
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
const DEFAULT_MANIFEST_PATH = 'registry/index.json';
|
|
38
|
+
export class GithubRegistryBackend extends StaticRegistryBackend {
|
|
39
|
+
owner;
|
|
40
|
+
repo;
|
|
41
|
+
ref;
|
|
42
|
+
manifestPath;
|
|
43
|
+
client;
|
|
44
|
+
// `ref`/`manifestPath` are required (not `?:`) here — the only call site,
|
|
45
|
+
// `create()`, always resolves them to concrete strings before constructing,
|
|
46
|
+
// so a `??` default in this constructor would be unreachable dead code.
|
|
47
|
+
constructor(options) {
|
|
48
|
+
super({ id: options.id, kind: 'github', trust: options.trust ?? 'restricted', manifest: options.manifest, trustRoot: options.trustRoot });
|
|
49
|
+
this.owner = options.owner;
|
|
50
|
+
this.repo = options.repo;
|
|
51
|
+
this.ref = options.ref;
|
|
52
|
+
this.manifestPath = options.manifestPath;
|
|
53
|
+
this.client = options.client;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Read the manifest from the configured GitHub path and construct the backend.
|
|
57
|
+
*
|
|
58
|
+
* @param options - Repo coordinates, optional ref/path, and the client to read/write through.
|
|
59
|
+
* @returns The constructed backend, already holding its first manifest snapshot.
|
|
60
|
+
*/
|
|
61
|
+
static async create(options) {
|
|
62
|
+
const ref = options.ref ?? 'main';
|
|
63
|
+
const manifestPath = options.manifestPath ?? DEFAULT_MANIFEST_PATH;
|
|
64
|
+
const manifest = await options.client.readManifest(options.owner, options.repo, ref, manifestPath);
|
|
65
|
+
return new GithubRegistryBackend({ ...options, ref, manifestPath, manifest });
|
|
66
|
+
}
|
|
67
|
+
async publish(request) {
|
|
68
|
+
// `publish` is a public method on a plain-string/JS-object boundary — an
|
|
69
|
+
// untyped caller's `name`/`version` are used to build a file path and PR
|
|
70
|
+
// branch name below, so both must be validated before that happens.
|
|
71
|
+
const [vendor, name] = assertSafeEntryName(request.entry.name);
|
|
72
|
+
const version = assertSafeVersion(request.entry.version);
|
|
73
|
+
// Beyond the path-safety checks above, validate the *whole* request
|
|
74
|
+
// against the wire schema before any of its fields get written into the
|
|
75
|
+
// published manifest content below (see CR-009/`assertValidPublishRequest`).
|
|
76
|
+
const parsed = assertValidPublishRequest(request);
|
|
77
|
+
const root = `entries/${vendor}/${name}`;
|
|
78
|
+
const files = [
|
|
79
|
+
{ path: `${root}/entry.json`, content: `${JSON.stringify(parsed.entry, null, 2)}\n` },
|
|
80
|
+
{
|
|
81
|
+
path: `${root}/versions/${version}.json`,
|
|
82
|
+
content: `${JSON.stringify({ ...parsed.entry, publishedAt: new Date().toISOString(), tag: parsed.tag ?? 'latest' }, null, 2)}\n`,
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
if (parsed.dryRun || !this.client.createPublishPullRequest) {
|
|
86
|
+
return {
|
|
87
|
+
ok: true,
|
|
88
|
+
dryRun: true,
|
|
89
|
+
changedFiles: files.map((file) => file.path),
|
|
90
|
+
warnings: this.client.createPublishPullRequest ? [] : ['github mutation client unavailable; emitted dry-run payload only'],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const mutation = {
|
|
94
|
+
owner: this.owner,
|
|
95
|
+
repo: this.repo,
|
|
96
|
+
baseRef: this.ref,
|
|
97
|
+
branchName: `publish/${vendor}-${name}-${version}`,
|
|
98
|
+
title: `Add ${parsed.entry.name}@${version}`,
|
|
99
|
+
body: renderPublishBody(parsed),
|
|
100
|
+
files,
|
|
101
|
+
};
|
|
102
|
+
const pr = await this.client.createPublishPullRequest(mutation);
|
|
103
|
+
return { ok: true, dryRun: false, pullRequestUrl: pr.url, changedFiles: files.map((file) => file.path), warnings: [] };
|
|
104
|
+
}
|
|
105
|
+
async yank(name, version, reason) {
|
|
106
|
+
const [vendor, entryName] = assertSafeEntryName(name);
|
|
107
|
+
const safeVersion = assertSafeVersion(version);
|
|
108
|
+
assertNoControlChars(reason, 'yank reason');
|
|
109
|
+
const path = `entries/${vendor}/${entryName}/versions/${safeVersion}.json`;
|
|
110
|
+
if (!this.client.createPublishPullRequest) {
|
|
111
|
+
// Same honest-outcome treatment as `publish`: no mutation capability
|
|
112
|
+
// means this is implicitly a dry run, not a real yank — say so.
|
|
113
|
+
return {
|
|
114
|
+
ok: true,
|
|
115
|
+
dryRun: true,
|
|
116
|
+
name,
|
|
117
|
+
version,
|
|
118
|
+
reason,
|
|
119
|
+
warnings: ['github mutation client unavailable; emitted dry-run yank only'],
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const mutation = {
|
|
123
|
+
owner: this.owner,
|
|
124
|
+
repo: this.repo,
|
|
125
|
+
baseRef: this.ref,
|
|
126
|
+
branchName: `yank/${vendor}-${entryName}-${safeVersion}`,
|
|
127
|
+
title: `Yank ${name}@${version}`,
|
|
128
|
+
body: `Yank ${name}@${version}\n\nReason: ${reason}\n`,
|
|
129
|
+
files: [
|
|
130
|
+
{
|
|
131
|
+
path,
|
|
132
|
+
content: `${JSON.stringify({ name, version, yanked: true, yankedAt: new Date().toISOString(), yankReason: reason }, null, 2)}\n`,
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
};
|
|
136
|
+
const pr = await this.client.createPublishPullRequest(mutation);
|
|
137
|
+
return { ok: true, dryRun: false, name, version, reason, pullRequestUrl: pr.url, warnings: [] };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function renderPublishBody(request) {
|
|
141
|
+
return [
|
|
142
|
+
`Publish ${request.entry.name}@${request.entry.version}`,
|
|
143
|
+
'',
|
|
144
|
+
request.entry.description ?? '',
|
|
145
|
+
'',
|
|
146
|
+
'## Registry metadata',
|
|
147
|
+
'',
|
|
148
|
+
`- source: ${request.entry.source}`,
|
|
149
|
+
`- integrity: ${request.entry.integrity ?? request.entry.dist?.integrity ?? '(pending)'}`,
|
|
150
|
+
`- manifestDigest: ${request.entry.manifestDigest ?? request.entry.dist?.manifestDigest ?? '(pending)'}`,
|
|
151
|
+
`- capabilities: ${(request.entry.capabilitiesSummary ?? []).join(', ') || '(none declared)'}`,
|
|
152
|
+
request.changelog ? `\n## Changelog\n\n${request.changelog}` : '',
|
|
153
|
+
]
|
|
154
|
+
.filter(Boolean)
|
|
155
|
+
.join('\n');
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=github-backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-backend.js","sourceRoot":"","sources":["../src/github-backend.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,yBAAyB,EAAE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