@preventive/triage 1.0.0-alpha.80 → 1.0.0-alpha.82
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/common/code-language.js +14 -0
- package/common/managed/routes.js +1 -1
- package/out/activity.js +2 -2
- package/out/chunk-6WMQVUT2.js +3 -0
- package/out/{chunk-5EAVJAD2.js → chunk-CE2FMDK3.js} +1 -1
- package/out/{chunk-5QWPKTCE.js → chunk-EIEUTJM4.js} +2 -2
- package/out/chunk-FNFWBAJO.js +3 -0
- package/out/chunk-KP2XM324.js +6 -0
- package/out/{chunk-OWSEQOL5.js → chunk-NH2HDQ5E.js} +1 -1
- package/out/{chunk-PTFYDJUP.js → chunk-RAM3GDAD.js} +1 -1
- package/out/{chunk-5CJKUV53.js → chunk-SUFRZ5U7.js} +1 -1
- package/out/chunk-UP3ADVQN.js +54 -0
- package/out/{chunk-JXBRWLMA.js → chunk-W2H4DBZW.js} +1 -1
- package/out/chunk-WOCJFOXN.js +1 -0
- package/out/{chunk-ITUKKCCK.js → chunk-WOLGZ2PE.js} +1 -1
- package/out/{chunk-7YO4QV5P.js → chunk-XHYX3Q34.js} +1 -1
- package/out/chunk-Z7KOFS2V.js +266 -0
- package/out/{chunk-LBD3M3J6.js → chunk-ZQQALNFP.js} +1 -1
- package/out/client-managed-import.js +1 -1
- package/out/client-managed.js +30 -30
- package/out/compare.js +10 -10
- package/out/dialogs.js +5 -5
- package/out/graph.js +1 -1
- package/out/index.html +10 -10
- package/out/prism.js +1 -1
- package/out/scan.js +1 -1
- package/out/view.css +1 -1
- package/out/view.js +8 -8
- package/package.json +3 -2
- package/risk/files/characters.js +13 -0
- package/risk/files/runs-code.js +13 -8
- package/risk/files/script.js +15 -7
- package/risk/npm/assess.js +1 -1
- package/server-managed/activity.ts +24 -2
- package/server-managed/avatar-store.ts +8 -0
- package/server-managed/db-methods.ts +42 -11
- package/server-managed/db-neon.ts +5 -2
- package/server-managed/db-schema.ts +10 -2
- package/server-managed/db.ts +2 -1
- package/server-managed/dependency-review-comments.ts +19 -4
- package/server-managed/http.ts +105 -19
- package/server-managed/pretty-format.js +1 -1
- package/server-managed/repository-browser.ts +2 -2
- package/server-managed/team-icons.ts +50 -0
- package/out/chunk-5M2X3QPK.js +0 -6
- package/out/chunk-DUS5ARE2.js +0 -53
- package/out/chunk-GBMAXAYK.js +0 -3
- package/out/chunk-MV66NL3G.js +0 -3
- package/out/chunk-VZPPX6MV.js +0 -1
- package/out/chunk-YKCRCNYZ.js +0 -266
package/server-managed/http.ts
CHANGED
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
// POST /api/reports/<id>/triage → write triage entries: admin, or ≥triage role + membership | 401/403/404
|
|
24
24
|
// GET /api/reports/<id>/triage/history?finding=<fid> → one visible finding's triage trail, newest first | 400/401/404
|
|
25
25
|
// GET /api/avatar/<id>[?own] → cached avatar bytes by user id, of the account chosen on their profile (`own`: the
|
|
26
|
-
// sign-in account's), or by linked account id; `app-<id>` or `user-<id>`, an agent's GitHub App's or account's (GITHUB_AGENTS)
|
|
26
|
+
// sign-in account's), or by linked account id; `app-<id>` or `user-<id>`, an agent's GitHub App's or account's (GITHUB_AGENTS);
|
|
27
|
+
// `org-<id>`, a GitHub organization's a team shows as its icon, for an admin or a member of that team (team-icons.ts) | 401/404
|
|
27
28
|
// GET /api/admin/users → admin-only user list | 401/403
|
|
28
29
|
// GET /api/admin/history → paginated activity (admin), team content activity (manage) | 401/403
|
|
29
30
|
// POST /api/admin/set-role → admin sets another user's role | 401/403/404
|
|
@@ -116,6 +117,10 @@
|
|
|
116
117
|
// POST /api/admin/teams/{set,remove}-member → admin links/unlinks a user (+perms) | 401/403/404
|
|
117
118
|
// POST /api/admin/teams/set-dependency-review → admin toggles dependency review publication for a team | 400/401/403/404
|
|
118
119
|
// POST /api/admin/teams/set-npm-scopes → admin replaces a team's npm scopes | 400/401/403/404
|
|
120
|
+
// GET /api/admin/teams/icons?teamId= → admin: the GitHub organizations owning a team's repositories, its icon's choices,
|
|
121
|
+
// and the owners GitHub could not be asked about | 400/401/403/404
|
|
122
|
+
// POST /api/admin/teams/set-icon → admin sets a team's icon to one of those organizations ({ teamId, organization: login }),
|
|
123
|
+
// or the default icon (organization null) | 400/401/403/404/502
|
|
119
124
|
// GET/POST /api/npm/reviews → read private/team reviews; save, publish, revoke or continue a set; a patched version's
|
|
120
125
|
// (patchHash) changed with where its patch is (patchRepoId, patchCommit, patchPath) | 400/401/403/404/409/422
|
|
121
126
|
// POST /api/npm/reviews/discard → author discards an unpublished review and its file rows | 400/401/403/409
|
|
@@ -176,12 +181,12 @@ import { contentAccess } from './content-access.ts'
|
|
|
176
181
|
import type { BundleStore } from './bundle-store.ts'
|
|
177
182
|
import { Buffer } from 'node:buffer'
|
|
178
183
|
import { createHash, randomUUID } from 'node:crypto'
|
|
179
|
-
import type
|
|
184
|
+
import { type AvatarStore, type CachedAvatar, type GithubAvatar, githubAvatarKey, githubAvatarUrl } from './avatar-store.ts'
|
|
180
185
|
import type { BlobStore, OpenedBlob } from './blob-store.ts'
|
|
181
186
|
import { bundleFilePrefix, bundleIntegrity, bundleKind, bundleRepo, reportBundleHashes } from './bundle.ts'
|
|
182
187
|
import { ourRepositoryNames, resolveRepositoryImportLocation } from './repository-aliases.ts'
|
|
183
188
|
import type { ManagedConfig } from './config.ts'
|
|
184
|
-
import type { BundleBuildConditions, BundleProvenance, BundleReuse, ManagedBundle, ManagedDb, ManagedSession, ReportRecord, SelectedRepo, StoredUser, TriageEventRow } from './db.ts'
|
|
189
|
+
import type { AdminTeam, BundleBuildConditions, BundleProvenance, BundleReuse, ManagedBundle, ManagedDb, ManagedSession, ReportRecord, SelectedRepo, StoredUser, TriageEventRow } from './db.ts'
|
|
185
190
|
import type { OriginGate } from '../server-common/origin.ts'
|
|
186
191
|
import { isRole, roleAtLeast } from '../common/managed/roles.ts'
|
|
187
192
|
import { VISIBILITY_PERMISSIONS, parseTeamUserPermissions } from '../common/managed/permissions.ts'
|
|
@@ -201,6 +206,7 @@ import { bundleCommitHash } from '../common/bundle-commit.js'
|
|
|
201
206
|
import { collectRepos, fetchPublicRepository, installUrl, publicRepositoryName, repositoryInstallation } from './github-app.ts'
|
|
202
207
|
import { type TaggedRead, keepTaggedReadsIn } from './github-requests.ts'
|
|
203
208
|
import { SHA, timeOf } from './github-values.ts'
|
|
209
|
+
import { ORGANIZATION_AVATAR, isOrganizationLogin, teamOrganizations } from './team-icons.ts'
|
|
204
210
|
import { GithubApiError, upstreamGithub } from './github-errors.ts'
|
|
205
211
|
import { STASIS_CONFIG } from './stasis-config.ts'
|
|
206
212
|
import { createClient } from '@preventive/upstream/github.js'
|
|
@@ -344,6 +350,8 @@ const TEAM_REMOVE_REPO_PATH = '/api/admin/teams/remove-repo'
|
|
|
344
350
|
const TEAM_SET_MEMBER_PATH = '/api/admin/teams/set-member'
|
|
345
351
|
const TEAM_REMOVE_MEMBER_PATH = '/api/admin/teams/remove-member'
|
|
346
352
|
const TEAM_SET_NPM_SCOPES_PATH = '/api/admin/teams/set-npm-scopes'
|
|
353
|
+
const TEAM_ICONS_PATH = '/api/admin/teams/icons'
|
|
354
|
+
const TEAM_SET_ICON_PATH = '/api/admin/teams/set-icon'
|
|
347
355
|
const NPM_PACKAGE_PATH = '/api/npm/package'
|
|
348
356
|
const NPM_VERSIONS_PATH = '/api/npm/versions'
|
|
349
357
|
const NPM_DOWNLOAD_PATH = '/api/npm/download'
|
|
@@ -457,7 +465,7 @@ async function handleHistory(res: ServerResponse, deps: ManagedHttpDeps, cookie:
|
|
|
457
465
|
const repo = query.get('repo') ?? ''
|
|
458
466
|
const actor = query.get('actor') ?? ''
|
|
459
467
|
if (!Number.isSafeInteger(page) || page < 1 || !Number.isSafeInteger(limit) || limit < 1 || limit > 100
|
|
460
|
-
|| !['all', 'triage', 'upload', 'visibility', 'access', 'repository', 'delete'].includes(kind) || search.length > 500
|
|
468
|
+
|| !['all', 'triage', 'review', 'upload', 'visibility', 'access', 'repository', 'delete'].includes(kind) || search.length > 500
|
|
461
469
|
|| repo.length > 500 || actor.length > 500) {
|
|
462
470
|
sendJson(res, 400, { error: 'bad-request' }); return
|
|
463
471
|
}
|
|
@@ -561,9 +569,8 @@ function sendAvatar(req: IncomingMessage, res: ServerResponse, avatar: CachedAva
|
|
|
561
569
|
|
|
562
570
|
// The avatars `/api/avatar/app-<id>` and `/api/avatar/user-<id>` serve, these
|
|
563
571
|
// alone: those the app draws agents by (GITHUB_AGENTS), on the Agents tab and
|
|
564
|
-
// wherever their work shows. Each is fetched from GitHub once and
|
|
565
|
-
//
|
|
566
|
-
// an account's, `…-0001-<id>`.
|
|
572
|
+
// wherever their work shows. Each is fetched from GitHub once and kept
|
|
573
|
+
// (githubAvatarKey).
|
|
567
574
|
const AGENT_AVATARS: ReadonlySet<string> = new Set(Object.values(GITHUB_AGENTS).flatMap(agent => 'avatar' in agent ? [agent.avatar] : []))
|
|
568
575
|
const AGENT_AVATAR = /^(app|user)-([1-9]\d{0,11})$/u
|
|
569
576
|
// An agent's mark is a public GitHub image that never changes with anyone's
|
|
@@ -571,17 +578,24 @@ const AGENT_AVATAR = /^(app|user)-([1-9]\d{0,11})$/u
|
|
|
571
578
|
// for it alone.
|
|
572
579
|
const AGENT_AVATAR_CACHE = 'private, max-age=86400'
|
|
573
580
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
if (kept != null) { sendAvatar(req, res, kept, AGENT_AVATAR_CACHE); return }
|
|
580
|
-
await cacheAvatar(avatarStore, key, `https://avatars.githubusercontent.com/${kind === 'app' ? 'in' : 'u'}/${id}`, globalThis.fetch)
|
|
581
|
-
.catch((err) => { console.warn('managed: agent avatar caching failed:', err) })
|
|
582
|
-
await serveAvatar(req, res, avatarStore, key, key, AGENT_AVATAR_CACHE)
|
|
581
|
+
// Keep the avatar GitHub serves of account `id` now, replacing what was
|
|
582
|
+
// kept; a failure is told the operator, never thrown.
|
|
583
|
+
function keepGithubAvatar(avatarStore: AvatarStore, kind: GithubAvatar, id: number | string): Promise<void> {
|
|
584
|
+
return cacheAvatar(avatarStore, githubAvatarKey(kind, id), githubAvatarUrl(kind, id), globalThis.fetch)
|
|
585
|
+
.catch((err) => { console.warn(`managed: ${kind} ${id} avatar caching failed:`, err) })
|
|
583
586
|
}
|
|
584
587
|
|
|
588
|
+
// Account `id`'s avatar, as kept, else fetched from GitHub and kept then.
|
|
589
|
+
async function serveGithubAvatar(req: IncomingMessage, res: ServerResponse, avatarStore: AvatarStore, kind: GithubAvatar, id: number | string, cacheControl: string): Promise<void> {
|
|
590
|
+
const key = githubAvatarKey(kind, id)
|
|
591
|
+
sendAvatar(req, res, await avatarStore.get(key) ?? await keepGithubAvatar(avatarStore, kind, id).then(() => avatarStore.get(key)), cacheControl)
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// What the generic path serves: a user's id, or a linked account's, each a v4
|
|
595
|
+
// UUID (randomUUID); never a GitHub account's kept avatar, served by its own
|
|
596
|
+
// path alone, an organization's to those whose team shows it.
|
|
597
|
+
const USER_AVATAR = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u
|
|
598
|
+
|
|
585
599
|
const MAX_JSON_BODY_BYTES = 4096
|
|
586
600
|
|
|
587
601
|
// Buffer the request body, aborting (and throwing 'too-large') once it exceeds
|
|
@@ -2763,10 +2777,13 @@ async function pullDependencyAnswer(deps: ManagedHttpDeps, fullName: string, tok
|
|
|
2763
2777
|
wantedIn })
|
|
2764
2778
|
askBuilds(deps, wanted, wantedIn, wants)
|
|
2765
2779
|
// The comment the host formats of the reader's reviews of its versions, for
|
|
2766
|
-
// its copy button, but those its comments make of theirs already
|
|
2780
|
+
// its copy button, but those its comments make of theirs already; with the
|
|
2781
|
+
// versions it is of, whence a team's Dependencies hides it where it copies
|
|
2782
|
+
// only those another pull request lists.
|
|
2767
2783
|
const formatted = await formattedPull(reviewed, deps.db, user.id, told, state, { repository: fullName, number }, commented, bases)
|
|
2768
2784
|
const intoOther = review && defaultBranch !== null && typeof answered.value.baseRef === 'string' && answered.value.baseRef !== defaultBranch
|
|
2769
|
-
return { value: { number: told.number, ...dependencies, ...formatted ? { formatted } : {}, ...intoOther ? { intoOther } : {} },
|
|
2785
|
+
return { value: { number: told.number, ...dependencies, ...formatted ? { formatted: formatted.text, formattedVersions: formatted.versions } : {}, ...intoOther ? { intoOther } : {} },
|
|
2786
|
+
kept: answered.kept && held !== null && !asked.github }
|
|
2770
2787
|
}
|
|
2771
2788
|
|
|
2772
2789
|
// What the stasis.config.json files repository `repoId`'s review holds to
|
|
@@ -5168,6 +5185,58 @@ async function handleSetTeamNpmScopes(req: IncomingMessage, res: ServerResponse,
|
|
|
5168
5185
|
sendJson(res, 200, { ok: true, scopes: (await deps.db.listTeamNpmScopes())[teamId] ?? [] })
|
|
5169
5186
|
}
|
|
5170
5187
|
|
|
5188
|
+
// Team `team`'s repositories, each once, as GitHub is asked of them for its icon.
|
|
5189
|
+
async function teamIconRepos(deps: ManagedHttpDeps, team: AdminTeam): Promise<SelectedRepo[]> {
|
|
5190
|
+
const linked = new Set(team.repos.map(link => link.repoId))
|
|
5191
|
+
return (await deps.db.listAllRepos()).filter(repo => linked.has(repo.repoId))
|
|
5192
|
+
}
|
|
5193
|
+
|
|
5194
|
+
// GET /api/admin/teams/icons?teamId= — what team `teamId` may show as its
|
|
5195
|
+
// icon: the GitHub organizations owning its repositories, as GitHub tells them
|
|
5196
|
+
// now (`organizations`, each { id, login }), and the owners GitHub could not
|
|
5197
|
+
// be asked about (`unchecked`). Admin, read-only.
|
|
5198
|
+
async function handleTeamIcons(res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, teamId: string | null): Promise<void> {
|
|
5199
|
+
const s = await readAdminSession(res, deps, cookie, { handed: true })
|
|
5200
|
+
if (s == null) return
|
|
5201
|
+
if (!teamId || teamId.length > 100) { sendJson(res, 400, { error: 'bad-request' }); return }
|
|
5202
|
+
const team = (await deps.db.listTeams()).find(row => row.id === teamId)
|
|
5203
|
+
if (team == null) { sendJson(res, 404, { error: 'no-team' }); return }
|
|
5204
|
+
sendJson(res, 200, await teamOrganizations(deps.config, await teamIconRepos(deps, team), globalThis.fetch))
|
|
5205
|
+
}
|
|
5206
|
+
|
|
5207
|
+
// POST /api/admin/teams/set-icon — a team's icon. Body { teamId, organization }:
|
|
5208
|
+
// the login of a GitHub organization owning one of its repositories, as GitHub
|
|
5209
|
+
// tells it now, its avatar fetched again; or null for the default icon.
|
|
5210
|
+
// 400 not-team-organization where none of its repositories is that
|
|
5211
|
+
// organization's; 502 github-unavailable where GitHub could not tell of one.
|
|
5212
|
+
async function handleSetTeamIcon(req: IncomingMessage, res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined): Promise<void> {
|
|
5213
|
+
const s = await adminMutation(req, res, deps, cookie, { handed: true })
|
|
5214
|
+
if (s == null) return
|
|
5215
|
+
const body = await readBodyFields(req, res)
|
|
5216
|
+
if (!body) return
|
|
5217
|
+
const { teamId, organization } = body
|
|
5218
|
+
if (typeof teamId !== 'string' || (organization !== null && !isOrganizationLogin(organization))) { sendJson(res, 400, { error: 'bad-request' }); return }
|
|
5219
|
+
const team = (await deps.db.listTeams()).find(row => row.id === teamId)
|
|
5220
|
+
if (team == null) { sendJson(res, 404, { error: 'no-team' }); return }
|
|
5221
|
+
let icon = null
|
|
5222
|
+
if (organization !== null) {
|
|
5223
|
+
const choices = await teamOrganizations(deps.config, await teamIconRepos(deps, team), globalThis.fetch)
|
|
5224
|
+
icon = choices.organizations.find(choice => choice.login.toLowerCase() === organization.toLowerCase()) ?? null
|
|
5225
|
+
if (icon == null) {
|
|
5226
|
+
if (choices.unchecked.length > 0) sendJson(res, 502, { error: 'github-unavailable' })
|
|
5227
|
+
else sendJson(res, 400, { error: 'not-team-organization' })
|
|
5228
|
+
return
|
|
5229
|
+
}
|
|
5230
|
+
await keepGithubAvatar(deps.avatarStore, 'user', icon.id)
|
|
5231
|
+
}
|
|
5232
|
+
if (await readAdminSession(res, deps, cookie) == null) return
|
|
5233
|
+
if (!(await deps.db.setTeamIcon(teamId, icon, Date.now()))) { sendJson(res, 404, { error: 'no-team' }); return }
|
|
5234
|
+
if (team.icon?.id !== icon?.id) {
|
|
5235
|
+
await activity(deps, s.user, 'access', icon ? `set team ${team.name}'s icon to ${icon.login}` : `reset team ${team.name}'s icon`)
|
|
5236
|
+
}
|
|
5237
|
+
sendJson(res, 200, { ok: true, icon })
|
|
5238
|
+
}
|
|
5239
|
+
|
|
5171
5240
|
// Who reads npm packages now: a session with workspace access, its role and,
|
|
5172
5241
|
// where they count for any of `names` it is asked about (npmScopesCount), the
|
|
5173
5242
|
// npm scopes of its visible teams, else none: none are read for an unscoped
|
|
@@ -5980,7 +6049,16 @@ export function createManagedRequestHandler(deps: ManagedHttpDeps): Handler {
|
|
|
5980
6049
|
if (path.startsWith(AVATAR_PREFIX)) {
|
|
5981
6050
|
if (method !== 'GET') { send405(res, 'GET'); return }
|
|
5982
6051
|
const id = path.slice(AVATAR_PREFIX.length)
|
|
5983
|
-
|
|
6052
|
+
const agent = AGENT_AVATARS.has(id) ? AGENT_AVATAR.exec(id) : null
|
|
6053
|
+
if (agent) { await serveGithubAvatar(req, res, avatarStore, agent[1] as GithubAvatar, agent[2]!, AGENT_AVATAR_CACHE); return }
|
|
6054
|
+
// A team's icon (team-icons.ts): any organization's for an admin, who
|
|
6055
|
+
// chooses them; one a team of theirs shows for anyone else.
|
|
6056
|
+
const organization = Number(ORGANIZATION_AVATAR.exec(id)?.[1])
|
|
6057
|
+
const user = workspaceSession!.user
|
|
6058
|
+
if (organization && (user.role === 'admin' || await db.userCanReadTeamIcon(user.id, organization))) {
|
|
6059
|
+
await serveGithubAvatar(req, res, avatarStore, 'user', organization, USER_AVATAR_CACHE); return
|
|
6060
|
+
}
|
|
6061
|
+
if (!USER_AVATAR.test(id)) { sendJson(res, 404, { error: 'no-avatar' }); return }
|
|
5984
6062
|
await serveAvatar(req, res, avatarStore, id, url.searchParams.has('own') ? id : await db.getAvatarKey(id))
|
|
5985
6063
|
return
|
|
5986
6064
|
}
|
|
@@ -6236,6 +6314,14 @@ export function createManagedRequestHandler(deps: ManagedHttpDeps): Handler {
|
|
|
6236
6314
|
if (method !== 'POST') { send405(res, 'POST'); return }
|
|
6237
6315
|
await handleSetTeamNpmScopes(req, res, deps, cookie); return
|
|
6238
6316
|
}
|
|
6317
|
+
if (path === TEAM_ICONS_PATH) {
|
|
6318
|
+
if (method !== 'GET') { send405(res, 'GET'); return }
|
|
6319
|
+
await handleTeamIcons(res, deps, cookie, url.searchParams.get('teamId')); return
|
|
6320
|
+
}
|
|
6321
|
+
if (path === TEAM_SET_ICON_PATH) {
|
|
6322
|
+
if (method !== 'POST') { send405(res, 'POST'); return }
|
|
6323
|
+
await handleSetTeamIcon(req, res, deps, cookie); return
|
|
6324
|
+
}
|
|
6239
6325
|
if (path === '/api/npm/reviews/latest') {
|
|
6240
6326
|
if (method !== 'GET') { send405(res, 'GET'); return }
|
|
6241
6327
|
const s = workspaceSession!
|
|
@@ -5,7 +5,7 @@ import { format, layoutBlankLines } from '@preventive/compare/pretty.js'
|
|
|
5
5
|
// Part of every kept copy's name; bumped when what the formatter writes for
|
|
6
6
|
// the same file changes, or what its check lets through, so copies written
|
|
7
7
|
// before are no longer read.
|
|
8
|
-
export const PRETTY_VERSION =
|
|
8
|
+
export const PRETTY_VERSION = 7
|
|
9
9
|
|
|
10
10
|
export async function prettyFormat(text, extension) {
|
|
11
11
|
const result = await format(text, extension)
|
|
@@ -65,7 +65,7 @@ function credentialFailure(err: unknown): err is GithubApiError {
|
|
|
65
65
|
// that token (`userToken`, hashed), whichever credential reads it: a private
|
|
66
66
|
// repository's was granted on who that token told GitHub they are. The next
|
|
67
67
|
// check asks GitHub, falling back to the installation's or none as it does.
|
|
68
|
-
type RepoMetadata = { id?: unknown; full_name?: unknown; private?: unknown; visibility?: unknown; default_branch?: unknown; archived?: unknown }
|
|
68
|
+
type RepoMetadata = { id?: unknown; full_name?: unknown; private?: unknown; visibility?: unknown; default_branch?: unknown; archived?: unknown; owner?: unknown }
|
|
69
69
|
type AccessVerdict = { until: number; data: RepoMetadata; credential: 'user' | 'app' | 'none'; level: string | null; userToken: string | null }
|
|
70
70
|
type VerdictCache = { get(): AccessVerdict | undefined; set(verdict: Omit<AccessVerdict, 'until' | 'userToken'>): void }
|
|
71
71
|
const MAX_ACCESS_VERDICTS = 1000
|
|
@@ -176,7 +176,7 @@ type Access = { data: RepoMetadata; token: string | null; level: string | null }
|
|
|
176
176
|
// github-moved) or names another repository by it since, by its id,
|
|
177
177
|
// which neither changes. Where GitHub names it otherwise now, `repo` is named
|
|
178
178
|
// so, and `renamed` told. Throws where GitHub tells of no repository of its id.
|
|
179
|
-
async function currentMetadata(repo: SelectedRepo, metadata: (url: string) => Promise<unknown>, renamed: RepositoryRenamed | undefined): Promise<RepoMetadata> {
|
|
179
|
+
export async function currentMetadata(repo: SelectedRepo, metadata: (url: string) => Promise<unknown>, renamed: RepositoryRenamed | undefined): Promise<RepoMetadata> {
|
|
180
180
|
let movedTo: number | null = null, named: RepoMetadata | null = null
|
|
181
181
|
try { named = await metadata(repoApi(repo.fullName)) as RepoMetadata } catch (err) {
|
|
182
182
|
if (!isGithubMoved(err)) throw err
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// A team's icon: the avatar of a GitHub organization owning one of the
|
|
2
|
+
// team's repositories, chosen on Manage → Teams (POST /api/admin/teams/set-icon),
|
|
3
|
+
// or none, the default icon. A user's own account is never offered: only
|
|
4
|
+
// owners GitHub tells are organizations. The organization is kept by its
|
|
5
|
+
// numeric id, which survives a rename, and its login as it was when chosen.
|
|
6
|
+
// The icon stays until it is changed, though the team's repositories change.
|
|
7
|
+
// Its avatar is served as `/api/avatar/org-<id>` (http.ts).
|
|
8
|
+
import type { ManagedConfig } from './config.ts'
|
|
9
|
+
import type { SelectedRepo, TeamIcon } from './db-methods.ts'
|
|
10
|
+
import { accountOf } from './github-accounts.ts'
|
|
11
|
+
import { repoAccessToken } from './github-app.ts'
|
|
12
|
+
import { githubJson } from './github-requests.ts'
|
|
13
|
+
import { LOGIN } from './github-values.ts'
|
|
14
|
+
import { eachOf } from './queue.ts'
|
|
15
|
+
import { currentMetadata } from './repository-browser.ts'
|
|
16
|
+
|
|
17
|
+
// The organizations a team may show, by login, and the owners of its
|
|
18
|
+
// repositories GitHub could not be asked about, by their names' owner.
|
|
19
|
+
export interface TeamIconChoices { organizations: TeamIcon[]; unchecked: string[] }
|
|
20
|
+
|
|
21
|
+
// What `/api/avatar/org-<id>` names: an organization by its id.
|
|
22
|
+
export const ORGANIZATION_AVATAR = /^org-([1-9]\d{0,11})$/u
|
|
23
|
+
// A GitHub login, as a team's icon is asked for by (no App's `[bot]`).
|
|
24
|
+
export const isOrganizationLogin = (value: unknown): value is string => typeof value === 'string' && LOGIN.test(value) && !value.endsWith('[bot]')
|
|
25
|
+
|
|
26
|
+
const ownerOf = (fullName: string) => fullName.split('/', 1)[0]!.toLowerCase()
|
|
27
|
+
const GITHUB_REQUESTS_AT_ONCE = 4
|
|
28
|
+
|
|
29
|
+
// The organizations owning `repos` (a team's), each once, sorted by login, as
|
|
30
|
+
// GitHub tells each repository's owner now, one renamed or transferred since
|
|
31
|
+
// included (currentMetadata); and the owners, as the repositories are named,
|
|
32
|
+
// of those GitHub could not be asked about, past any it told of.
|
|
33
|
+
export async function teamOrganizations(config: ManagedConfig, repos: readonly SelectedRepo[], fetchImpl: typeof fetch): Promise<TeamIconChoices> {
|
|
34
|
+
const told = await eachOf([...repos], GITHUB_REQUESTS_AT_ONCE, async (repo) => {
|
|
35
|
+
try {
|
|
36
|
+
const token = await repoAccessToken(config, repo.installationId, fetchImpl)
|
|
37
|
+
const { owner } = await currentMetadata({ ...repo }, url => githubJson(url, token, fetchImpl), undefined)
|
|
38
|
+
const { id, login } = accountOf(owner as { id?: unknown; login?: unknown } | undefined)
|
|
39
|
+
return { repo, icon: id !== null && (owner as { type?: unknown }).type === 'Organization' ? { id, login: login! } : null }
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.warn(`managed: team icon owner of ${repo.fullName} unread:`, err instanceof Error ? err.message : err)
|
|
42
|
+
return { repo, icon: undefined }
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
const read = new Set(told.flatMap(({ repo, icon }) => icon === undefined ? [] : [ownerOf(repo.fullName)]))
|
|
46
|
+
return {
|
|
47
|
+
organizations: [...new Map(told.flatMap(({ icon }) => icon ? [[icon.id, icon] as const] : [])).values()].toSorted((a, b) => a.login.localeCompare(b.login)),
|
|
48
|
+
unchecked: [...new Set(told.flatMap(({ repo, icon }) => icon === undefined && !read.has(ownerOf(repo.fullName)) ? [ownerOf(repo.fullName)] : []))].toSorted(),
|
|
49
|
+
}
|
|
50
|
+
}
|
package/out/chunk-5M2X3QPK.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{b as e}from"./chunk-DUASGS2O.js";import{a as t}from"./chunk-IYPY47MC.js";import{a as n}from"./chunk-QRKFPLA4.js";import{b as r}from"./chunk-TUII34K2.js";var i=/^webpack(?:-internal)?:\/\/[^/]*\//u,a=/^[a-z][\d+.a-z-]*:/iu,o=/^file:/iu,s=/^(?:file|ftp|https?|wss?):/iu,c=/^(?:[a-z][\d+.a-z-]*:\/\/[^/]*\/?|\/\/[^/]+\/|[a-z]:\/|\/)?/iu,l=e=>c.exec(e)[0],u=e=>l(e).includes(`://`),d=e=>e.replace(u(e)?/[#?].*$/su:/\?.*$/su,``),f=e=>e.slice(e.lastIndexOf(`/`)+1),p=(e,t)=>URL.parse(e,t)?.href??null;function m(e){let t=l(e),n=t.includes(`://`)&&p(e);if(n)return n;let r=[];for(let n of e.slice(t.length).split(`/`))n===``||n===`.`||(n===`..`?r.length>0&&r.at(-1)!==`..`?r.pop():t||r.push(`..`):r.push(n));let i=/^[a-z]:\/$/iu.test(t)?t.toUpperCase():t.startsWith(`//`)?t.toLowerCase():t;return i?i.replace(/\/?$/u,`/`)+r.join(`/`):r.join(`/`)||`.`}function h(e,t){let n=l(t);return u(e)&&!n.includes(`:`)?p(t,e)??m(`${e}/../${t}`):m(n===`/`?l(e).replace(/\/?$/u,``)+t:n?t:`${e}/../${t}`)}function ee(e){try{return decodeURIComponent(e)}catch{return e}}function g(e,t){let n=e.replaceAll(`\\`,`/`);if(i.test(n))return m(n.replace(i,``));let r=s.test(n)?p(n)??n:n,c=/^file:\/\/([^/#]*)([^#]*)/isu.exec(r);if(c){let[,e,t]=c;return m(ee(e&&e.toLowerCase()!==`localhost`?`//${e}${t}`:t).replace(/^\/(?=[a-z]:\/)/iu,``))}if(a.test(r)&&!l(r).includes(`:`))return r;if(t===void 0)return m(r);if(o.test(t)&&!l(r))return g(p(r,t)??r);let d=g(t);return l(r)&&!u(d)?m(r):h(d,r)}var te=/^(?:@[\dA-Za-z~-][\w.~-]*\/)?[\dA-Za-z~-][\w.~-]*$/u;function _(e){let t=e.split(`/`).slice(0,e.startsWith(`@`)?2:1).join(`/`);return te.test(t)?t:null}var ne=new Set([`.pnpm`,`.bun`,`.deno`]),re=/^\d+\.\d+\.\d+(?:-[\d.a-z-]+)?(?:\+[\d.a-z-]+)?$/iu;function ie(e,t){let n=`${t.replace(`/`,`+`)}@`,r=e.startsWith(n)?e.slice(n.length).split(/[(_]/u)[0]:null;return re.test(r)?r:null}function ae(e){let t=d(e).split(`/`),n=t.lastIndexOf(`node_modules`),r=n<0?null:_(t.slice(n+1).join(`/`));if(r===null)return null;let i=n+1+r.split(`/`).length;if(i>=t.length||t.slice(i).includes(``))return null;let a=t.slice(0,i).join(`/`);return{name:r,version:ne.has(t[n-2])?ie(t[n-1],r):null,root:a,path:e.slice(a.length+1)}}var oe=new Map([[`js`,`jsx`],[`mjs`,`jsx`],[`cjs`,`jsx`],[`jsx`,`jsx`],[`es`,`jsx`],[`es6`,`jsx`],[`ts`,`ts`],[`mts`,`ts`],[`cts`,`ts`],[`tsx`,`tsx`],[`json`,`json`]]);function se(e){let t=f(d(e));return/^[\w-]+$/u.test(t)?`jsx`:oe.get(/\.([\da-z]+)$/iu.exec(t)?.[1].toLowerCase())??null}var ce=[`.js`,`.mjs`,`.cjs`,`.jsx`,`.ts`,`.tsx`,`.mts`,`.cts`,`.json`],le=[`.ios`,`.android`,`.web`];function ue(e){let t=e.map(e=>/\.[a-z]+(?=\.\w+$)/u.exec(f(d(e.path??``)))?.[0]),[[n,r],[,i]]=le.map(e=>[e,t.filter(t=>t===e).length]).toSorted((e,t)=>t[1]-e[1]);return[...r===i?[]:[n],`.native`,``,`.browser`,`.node`]}var de=new Map([[`.js`,[`.ts`,`.tsx`]],[`.jsx`,[`.tsx`]],[`.mjs`,[`.mts`]],[`.cjs`,[`.cts`]]]),fe=[`index`,`main`,`browser`,`node`],pe=[``,`src/`,`lib/`,`dist/`,`build/`],me=new Set([`lib`,`dist`,`build`,`out`,`esm`,`cjs`]);function*he(e,t){yield e;let n=/\.[^./]+$/u.exec(e)?.[0];for(let t of de.get(n)??[])yield e.slice(0,-n.length)+t;for(let n of e.endsWith(`/`)?[`${e}index`]:[e,`${e}/index`])for(let e of ce)for(let r of t)yield n+r+e;if(n)for(let r of t.filter(Boolean))yield e.slice(0,-n.length)+r+n}function*ge(e){let t=e;for(;;){t.startsWith(`src/`)||(yield`src/${t}`),t!==e&&(yield t);let n=t.indexOf(`/`);if(n<0||!me.has(t.slice(0,n)))return;t=t.slice(n+1)}}function _e(e){let t=new Map,n=new Map,r=new Map;for(let i of e)i.path!==null&&t.set(i.path,i),i.package&&(n.set(i.package.name,(n.get(i.package.name)??new Set).add(i.package.root)),(r.get(i.package.root)??r.set(i.package.root,[]).get(i.package.root)).push(i));return{byPath:t,roots:n,byRoot:r,platforms:ue(e),found:new Map}}function v(e,t){if(!e.found.has(t)){let n=d(t),r=he(n,e.platforms).map(e=>e+t.slice(n.length));e.found.set(t,e.byPath.get(r.find(t=>e.byPath.has(t)))??null)}return e.found.get(t)}function ve(e,t,n){let r=e.roots.get(n);if(!r)return null;let i=t.path.split(`/`);for(let e=i.length-1;e>=0;e--){let t=[...i.slice(0,e),`node_modules`,n].join(`/`);if(r.has(t))return t}return r.size===1?[...r][0]:null}var ye=new Set(`assert.async_hooks.buffer.child_process.cluster.console.constants.crypto.dgram.diagnostics_channel.dns.domain.events.fs.http.http2.https.inspector.module.net.os.path.perf_hooks.process.punycode.querystring.readline.repl.stream.string_decoder.sys.timers.tls.trace_events.tty.url.util.v8.vm.wasi.worker_threads.zlib._http_agent._http_client._http_common._http_incoming._http_outgoing._http_server._stream_duplex._stream_passthrough._stream_readable._stream_transform._stream_wrap._stream_writable._tls_common._tls_wrap.assert/strict.dns/promises.fs/promises.inspector/promises.path/posix.path/win32.readline/promises.stream/consumers.stream/promises.stream/web.timers/promises.util/types`.split(`.`));function be(e){if(e.startsWith(`node:`)||ye.has(e))return{builtin:!0};let t=_(d(e));return t===null?{}:{package:t}}function xe(){let e=[],t=new Map,n=(n,r,i)=>{let a=t.get(n)??t.set(n,new Set).get(n);a.has(r)||(a.add(r),e.push(i))};return{edges:e,add:n,link:(e,t,r)=>{e&&t&&t!==e&&n(e,t,{from:e,to:t,kind:r})}}}function Se(e,t){for(let n of fe)for(let r of pe){let i=v(e,`${t}/${r}${n}`);if(i)return i}let n=e.byRoot.get(t);return n?.length===1?n[0]:null}function Ce(e,t,n,r){return/^\/[^?]/u.test(n)?v(e,t+n)??ge(n.slice(1)).map(n=>v(e,`${t}/${n}`)).find(Boolean):v(e,t+n)??r(e,t)}function we(e,t,n,r=Se){let i=/^(?:\.{1,2}|[a-z]:)?\\/iu.test(n)?n.replaceAll(`\\`,`/`):n,o=s.test(i);if(o||/^(?:\.{1,2}(?:\/|$)|\/|[a-z]:\/)/iu.test(i)||u(i)){let n=o?g(i):h(t.path,i),r=v(e,n);return r?{to:r}:{to:null,path:n}}if(a.test(i)&&e.byPath.has(i))return{to:e.byPath.get(i)};let c=_(d(n)),l=c===null?null:ve(e,t,c);if(l===null)return{to:null,...be(n)};let f=Ce(e,l,n.slice(c.length),r);return f?{to:f}:{to:null,package:c}}var y=class extends Error{name=`SourceMapError`},Te=new Uint8Array(128).fill(255);for(let[e,t]of[...`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/,;`].entries())Te[t.codePointAt(0)]=e;function b(e){let t=new Int32Array(e.length*2);return t.set(e),t}function Ee(e){let{starts:t,columns:n,sources:r,names:i}=e;for(let e=0;e+1<t.length;e++){let[a,o]=[t[e],t[e+1]],s=a+1;for(;s<o&&n[s-1]<=n[s];)s++;if(s>=o)continue;let c=Array.from(n.subarray(a,o),(e,t)=>[e,r[a+t],i[a+t]]).sort((e,t)=>e[0]-t[0]);for(let[e,[t,o,s]]of c.entries())[n[a+e],r[a+e],i[a+e]]=[t,o,s]}return e}function De(e){let t=[0],n=new Int32Array(1024),r=new Int32Array(1024),i=new Int32Array(1024),a=0;for(let{mappings:o,files:s,line:c,column:l,names:u,nameCount:d}of e){if(typeof o!=`string`)throw new y(`mappings is not a string`);for(;t.length<=c;)t.push(a);let e=[0,0,0,0,0],f=0,p=0,m=1,h=l;for(let c=0;c<=o.length;c++){let l=c<o.length?Te[o.codePointAt(c)]??255:64;if(l<32){if(p+=l*m,f===5)throw new y(`mappings: a segment of more than 5 fields at ${c}`);e[f++]+=p%2?(1-p)/2:p/2,p=0,m=1}else if(l<64){if(p+=(l-32)*m,m*=32,m>2**30)throw new y(`mappings: a value at ${c} runs past 32 bits`)}else{if(l===255)throw new y(`mappings: ${JSON.stringify(o[c])} at ${c} is not a base64 digit`);if(m!==1)throw new y(`mappings: the value before ${c} is cut off`);if(f>0){if(f===2||f===3)throw new y(`mappings: a segment of ${f} fields before ${c}`);let t=f===1?-1:s[e[1]];if(t===void 0)throw new y(`mappings: source ${e[1]} before ${c} is not in sources`);if(e[0]<0)throw new y(`mappings: a negative generated column before ${c}`);a===n.length&&([n,r,i]=[b(n),b(r),b(i)]),n[a]=e[0]+h,r[a]=t,i[a++]=f===5&&e[4]>=0&&e[4]<d?u+e[4]:-1,f=0}l===65&&(t.push(a),e[0]=0,h=0)}}}return t.push(a),Ee({starts:Int32Array.from(t),columns:n.slice(0,a),sources:r.slice(0,a),names:i.slice(0,a)})}var x=new WeakMap,S=e=>x.get(e),C=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function w(e,t){if(!e)throw new y(t)}function T(e,t){if(e===void 0)return[];w(Array.isArray(e),`${t} is not an array`);for(let n of e)w(typeof n==`string`||n===null,`${t} holds ${JSON.stringify(n)}`);return e}function Oe(e,t,n,r){let i=e.bySource.get(t);if(i!==void 0)return e.files[i].content??=n,e.files[i].ignored||=r,i;let a=t===null?null:g(t,e.mapPath);return e.files.push({source:t,path:a,package:a===null?null:ae(a),content:n,ignored:r}),t!==null&&e.bySource.set(t,e.files.length-1),e.files.length-1}function E(e,t,n,r){w(e.version===3,`version ${JSON.stringify(e.version)} is not 3`),w(e.sourceRoot===void 0||typeof e.sourceRoot==`string`,`sourceRoot is not a string`);let i=T(e.sources,`sources`),a=T(e.sourcesContent,`sourcesContent`),o=e.ignoreList??e.x_google_ignoreList??[];w(Array.isArray(o)&&o.every(e=>Number.isInteger(e)&&e>=0&&e<i.length),`ignoreList is not a list of indices into sources`);let s=new Set(o),c=e.sourceRoot?e.sourceRoot.replace(/\/?$/u,`/`):``,l=i.map((e,n)=>Oe(t,e===null?null:c+e,a[n]??null,s.has(n))),u=Array.isArray(e.names)?e.names:[];t.parts.push({mappings:e.mappings,files:l,line:n,column:r,names:t.names.length,nameCount:u.length}),t.names.push(...u)}function ke(e,t){w(e.version===3,`version ${JSON.stringify(e.version)} is not 3`),w(Array.isArray(e.sections),`sections is not an array`);for(let[n,r]of e.sections.entries()){let{offset:i,map:a}=C(r)?r:{};w(C(i)&&[i.line,i.column].every(e=>Number.isInteger(e)&&e>=0),`sections[${n}].offset is not a line and a column`),w(C(a)&&a.sections===void 0,`sections[${n}].map is not a plain source map`);let o=e.sections[n-1]?.offset;w(!o||o.line<i.line||o.line===i.line&&o.column<=i.column,`sections[${n}] starts before sections[${n-1}]`),E(a,t,i.line,i.column)}}function Ae(e,t={}){if(!C(t))throw TypeError(`readSourceMap: options is not an object`);if(t.path!==void 0&&typeof t.path!=`string`)throw TypeError(`readSourceMap: options.path is not a string`);let n=e;if(typeof e==`string`||e instanceof Uint8Array)try{let t=typeof e==`string`?e:new TextDecoder(`utf-8`,{fatal:!0}).decode(e);n=JSON.parse(t.replace(/^\)\]\}'[^\n]*\n/u,``))}catch(e){throw new y(`not JSON: ${e.message}`,{cause:e})}w(C(n),`not a JSON object`);let r={files:[],bySource:new Map,mapPath:t.path,parts:[],names:[]};n.sections===void 0?E(n,r,0,0):ke(n,r);let i={files:r.files};return x.set(i,{...De(r.parts),nameList:r.names}),i}var je=/\r\n?|[\n\u2028\u2029]/gu;function Me(e){let t=[0];for(let n of e.matchAll(je))t.push(n.index+n[0].length);return t}function D(e,t,n,r){let[i,a]=[t,n];for(;i<a;){let t=i+a>>1;e[t]<=r?i=t+1:a=t}return i-1}function O(e,t){let n=D(e,0,e.length,t);return[n,t-e[n]]}function Ne(e,[t,n]){if(t>=e.starts.length-1)return-1;let r=e.starts[t],i=D(e.columns,r,e.starts[t+1],n);return i<r?-1:i}function Pe(e,t,n,r){let i=S(e),a=O(t,n),[o,s]=O(t,r),c=new Map,l=Ne(i,a);for(let e=a[0];e<=o&&e<i.starts.length-1;e++){let t=e===a[0]&&l>=0?l:i.starts[e];for(let n=t;n<i.starts[e+1];n++){let t=i.sources[n];if(e===o&&i.columns[n]>=s)break;t>=0&&c.set(t,(c.get(t)??0)+1)}}let[u]=[...c].reduce((e,t)=>t[1]>e[1]?t:e,[-1,0]);return u<0?null:e.files[u]}var k=/\s+/uy,A=`
|
|
2
|
-
\r\u2028\u2029`,j=/[\n\r\u2028\u2029]/gu,Fe=/[\n\r\u2028\u2029]/u,M=/[\w$\u0080-]+/uy,Ie=new Set([`return`,`typeof`,`instanceof`,`in`,`of`,`new`,`delete`,`void`,`throw`,`case`,`default`,`extends`,`do`,`else`,`yield`,`await`]),Le=new Set([`if`,`while`,`for`,`with`]),Re=new Set([`break`,`continue`,`debugger`]),ze=new Set([`(`,`[`,"${",`,`,`=`,`:`,`?`,`!`,`~`,`+`,`-`,`*`,`/`,`%`,`&`,`|`,`^`,`<`,`>`]);function Be(e,t){return e?.type===`word`?t&&[`return`,`yield`].includes(e.value)?!1:Ie.has(e.value)&&![`do`,`else`].includes(e.value):ze.has(e?.value)}function Ve(e){let t=e.at(-1);return t?.type===`word`&&(Le.has(t.value)||t.value===`await`&&e.at(-2)?.value===`for`)}function He(e){return e?e.type===`word`?Ie.has(e.value)||Re.has(e.value)||e.label===!0:e.value===`)`?e.control:e.value===`}`?!e.object:e.type===`punctuator`&&![`++`,`--`,`]`].includes(e.value):!0}var Ue=(e,t)=>e.startsWith(`\r
|
|
3
|
-
`,t+1)?3:2,We=/\\(?:u\{([\da-f]+)\}|u([\da-f]{4})|x([\da-f]{2})|([0-3][0-7]{0,2}|[4-7][0-7]?)|(\r\n|[\n\r\u2028\u2029])|(.))/giu,Ge={b:`\b`,f:`\f`,n:`
|
|
4
|
-
`,r:`\r`,t:` `,v:`\v`};function Ke(e){return e.includes(`\\`)?e.replace(We,(e,t,n,r,i,a,o)=>{if(a!==void 0)return``;if(i!==void 0)return String.fromCodePoint(Number.parseInt(i,8));let s=Number.parseInt(t??n??r,16);return Number.isNaN(s)?Ge[o]??o:String.fromCodePoint(Math.min(s,1114111))}):e}function qe(e,t){let n=e[t],r=t+1;for(;r<e.length&&e[r]!==n&&!A.includes(e[r]);)r+=e[r]===`\\`?Ue(e,r):1;return[e[r]===n?Ke(e.slice(t+1,r)):null,r+1]}function Je(e,t){let n=t+1,r=!1;for(;n<e.length&&!A.includes(e[n])&&(r||e[n]!==`/`);)e[n]===`\\`?n++:e[n]===`[`?r=!0:e[n]===`]`&&(r=!1),n++;return M.lastIndex=n+1,M.test(e)?M.lastIndex:n+1}function Ye(e,t,n){for(let r=t;r<e.length;r++)if(e[r]===`\\`)r++;else{if(e[r]==="`")return r+1;if(e[r]===`$`&&e[r+1]===`{`)return n.push(`template`),r+2}return e.length}function Xe(e){let t=[],n=[],r=[],i=0,a=0;for(;i<e.length;){let o=t.length;if(k.lastIndex=i,k.test(e)&&(i=k.lastIndex),i>=e.length)break;let s=e[i],c=e[i+1];if(M.lastIndex=i,s===`/`&&c===`/`)j.lastIndex=i+2,i=j.test(e)?j.lastIndex-1:e.length;else if(s===`/`&&c===`*`){let t=e.indexOf(`*/`,i+2);i=t<0?e.length:t+2}else if(s===`"`||s===`'`){let[n,r]=qe(e,i);t.push({type:`string`,value:n}),i=r}else if(s==="`"||s===`}`&&n.at(-1)===`template`){s===`}`&&n.pop();let r=n.length,a=Ye(e,i+1,n),o=s==="`"&&n.length===r&&e[a-1]==="`";t.push({type:`string`,value:o?Ke(e.slice(i+1,a-1)):null}),n.length>r&&t.push({type:`punctuator`,value:"${"}),i=a}else if(s===`/`&&He(t.at(-1)))i=Je(e,i),t.push({type:`regex`});else if(M.test(e)){let n=Re.has(t.at(-1)?.value)&&!Fe.test(e.slice(a,i));t.push({type:`word`,value:e.slice(i,M.lastIndex),...n&&{label:n}}),i=M.lastIndex}else{s===`{`&&n.push(Be(t.at(-1),Fe.test(e.slice(a,i)))?`object`:`block`);let o=s===`}`?n.pop():void 0;s===`(`&&r.push(Ve(t));let l=(s===`+`||s===`-`)&&c===s||s===`=`&&c===`>`?s+c:s;t.push({type:`punctuator`,value:l,...s===`)`&&{control:r.pop()===!0},...s===`}`&&{object:o===`object`}}),i+=l.length}t.length>o&&(a=i)}return t}var N=e=>e?.type===`string`&&e.value!==null,Ze=new Set([`type`,`typeof`]),Qe=(e,t)=>e[t+1]?.type===`word`&&(e[t+1].value!==`as`||e[t+2]?.type!==`word`||e[t+2].value===`as`);function $e(e,t){let n=!1;for(let r=t+1;r<e.length&&e[r].value!==`}`;r++)if(!(r>t+1&&e[r-1].value!==`,`)){if(!Ze.has(e[r].value)||!Qe(e,r))return!1;n=!0}return n}function et(e,t){for(let n=t;n<e.length;n++){let{value:r}=e[n];if(r===`;`||n>t&&(r===`import`||r===`export`))return null;if(r===`from`&&N(e[n+1]))return e[n+1].value}return null}function tt(e,t){let[n,r,i]=[e[t].value,e[t+1],e[t+2]],a=n===`import`?`import`:`export-from`;if(n===`import`&&N(r))return{kind:a,specifier:r.value};if(Ze.has(r?.value)&&![`,`,`from`].includes(i?.value)||r?.value===`{`&&$e(e,t+1)||n===`export`&&![`{`,`*`].includes(r?.value)||n===`import`&&r?.type!==`word`&&![`{`,`*`].includes(r?.value))return null;let o=et(e,t+1);return o===null?null:{kind:a,specifier:o}}function nt(e,t){let[n,r]=[e[t+2],e[t+3]];if(n?.value!==`)`)return N(n)&&[`)`,`,`].includes(r?.value)?n.value:null}function rt(e,t=new Set){let n=Xe(e),r=[];for(let[e,i]of n.entries()){if(i.type!==`word`||[`.`,`#`,`function`].includes(n[e-1]?.value)||n[e-1]?.value===`=`&&n[e-3]?.value===`type`&&n[e-4]?.value===`import`)continue;let a=n[e+1]?.value===`(`,o=a?nt(n,e):void 0;if((i.value===`require`||t.has(i.value))&&o!==void 0)r.push({kind:`require`,specifier:o,...i.value!==`require`&&{callee:i.value}});else if(i.value===`import`&&a)o!==void 0&&r.push({kind:`dynamic-import`,specifier:o});else if(i.value===`import`||i.value===`export`){let t=tt(n,e);t&&r.push(t)}}return r}var it=/^[\w$]*__d\(/gmu,at=([e,t,n,...r])=>(typeof e==`number`||typeof e==`string`)&&(t===void 0||typeof t==`object`)&&(n===void 0||typeof n==`string`)&&r.length===0;function ot(e){let t=/\);?\s*$/u.exec(e)?.index,n=null,r=t===void 0?-1:e.lastIndexOf(`},`,t);for(;r>=0&&/[\d"]/u.test(e[r+2]);){let i;try{i=JSON.parse(`[${e.slice(r+2,t)}]`)}catch{break}if(!at(i))break;n=i,r=r>0?e.lastIndexOf(`},`,r-1):-1}return n}function st(e){let t=/^[^(]*\(\s*(?:function\s*[\w$]*\s*)?\(([^)]*)\)/u.exec(e)?.[1].split(`,`).slice(1,4).map(e=>e.trim().replaceAll(`$`,`\\$`));if(!t?.length)return[];let n=e.matchAll(RegExp(`(?<=[^\\w$.#]|\\.\\.\\.)(?:${t.join(`|`)})\\((\\d+|"(?:[^"\\\\]|\\\\.)*")[,)]`,`gu`));return[...new Set([...n].map(e=>JSON.parse(e[1])))]}function ct(e,t){if(Array.isArray(e))return e;let n=Object.entries(e??{}).filter(([e])=>/^\d+$/u.test(e)).map(([,e])=>e);return n.length>0?n:st(t)}function lt(e,t){let n=new Map(t.files.map((e,t)=>[e,t])),r=e.flatMap((e,t)=>e.file?[{k:t,at:n.get(e.file)}]:[]);for(let n=0;n<(r[0]?.k??0);n++)e[n].file=t.files[r[0].at-r[0].k+n]??null;for(let[n,{k:i,at:a}]of r.entries()){let o=r[n+1];if(!(o&&o.at-a!==o.k-i))for(let n=i+1;n<(o?.k??e.length);n++)e[n].file=t.files[a+n-i]??null}}function ut(e,t){let n=[...e.matchAll(it)].map(e=>e.index);if(n.length===0)return null;let r=Me(e),i=t=>e.slice(r[t],r[t+1]),a=[];for(let[o,s]of n.entries()){let[c]=O(r,s),[l]=O(r,(n[o+1]??e.length)-1),u=ot(i(l));for(;!u&&l>c;)u=ot(i(--l));if(!u)throw Error(`bundleEdges: the Metro module at line ${c+1} ends in no define params`);let d=r[l+1]??e.length;a.push({id:u[0],file:Pe(t,r,s,d),dependencies:ct(u[1],e.slice(s,d))})}lt(a,t);let o=new Map(a.map(e=>[e.id,e])),{edges:s,link:c}=xe();for(let{file:e,dependencies:t}of a)for(let n of t)c(e,o.get(n)?.file,`dependency`);return s}var dt=e=>e.path!==null&&![`json`,null].includes(se(e.path)),ft=e=>e.path!==null&&se(e.path)===null;function pt(e){let t=/^_([A-Za-z]+)\d+$/u.exec(e)?.[1];if(t)return[t,`interopRequireDefault`];let n=/^_(interopRequire(?:Default|Wildcard)|jsx(?:Dev)?Runtime|callSuper)$/u.exec(e)?.[1];return n===`callSuper`?[`getPrototypeOf`,`possibleConstructorReturn`,`interopRequireDefault`]:n?[n]:[]}var mt={jsxRuntime:`react/jsx-runtime`,jsxDevRuntime:`react/jsx-dev-runtime`};function ht(e){let{sources:t,names:n,nameList:r}=S(e),i=new Map,a=new Map,o=e.files.map(()=>new Set);for(let e=0;e<n.length;e++)n[e]<0||t[e]<0||(a.has(n[e])||a.set(n[e],pt(r[n[e]]).length>0),a.get(n[e])&&o[t[e]].add(r[n[e]]));for(let[t,n]of o.entries()){if(n.size===0)continue;let r=e.files[t],a=new Set(Array.from((r.content??``).matchAll(/(?:function|var|let|const)\s+(_[A-Za-z]+\d*)\b/gu),e=>e[1])),o=[...n].filter(e=>!a.has(e)&&!a.has(e.replace(/\d+$/u,``))).flatMap(pt);o.length>0&&i.set(r,o.map(e=>mt[e]??`@babel/runtime/helpers/${e}`))}return i}function gt(e,t){let n=new Map;for(let[r,i]of e){let e=n.get(r)??n.set(r,new Map).get(r);for(let n of i)e.set(n,we(t,r,n,()=>null))}let r=new Set([...n.values()].flatMap(e=>[...e.values()].map(e=>e.to))),i=(e,n)=>t.byRoot.get(n).find(e=>!r.has(e))??t.byRoot.get(n)[0];return(e,r)=>{let a=n.get(e)?.get(r);return a?.to?a:we(t,e,r,i)}}var _t=e=>/(?:^|\/)__prelude__$/u.test(e.source??``),vt=e=>e?.package?.name===`metro-runtime`&&e.package.path===`src/polyfills/require.js`;function yt(e){if(!e.files.some(_t)&&!vt(e.files[0]))return null;if(!e.files.some(e=>e.content!==null&&!_t(e)&&!vt(e)))throw Error("bundleEdges: the Metro map carries no sourcesContent, which its edges are read from; pass the bundle as `code`");let t=_e(e.files),n=e.files[e.files.findIndex(ft)+1],r=e.files.find(e=>e.package?.name===`metro-runtime`&&e.package.path===`src/modules/asyncRequire.js`),i=new Map(e.files.filter(e=>e.content!==null&&dt(e)).map(e=>[e,rt(e.content)])),a=ht(e),o=gt([...[...i].map(([e,t])=>[e,t.flatMap(({specifier:e})=>e===null?[]:[e])]),...a],t),{edges:s,add:c,link:l}=xe();for(let t of e.files){ft(t)&&l(t,n,`dependency`);for(let{kind:e,specifier:n}of i.get(t)??[]){let i=n===null?{to:null}:o(t,n);i.to!==t&&c(t,`${e}\0${JSON.stringify(n)}`,{from:t,kind:e,specifier:n,...i}),e===`dynamic-import`&&l(t,r,`dependency`)}for(let e of a.get(t)??[])l(t,o(t,e).to,`dependency`)}return s}var bt=(e,t)=>t==null?yt(e):ut(t,e);function xt(e,t){let n=bt(e,t);if(!n)throw Error(`bundleEdges: not a Metro ${t==null?`map`:`bundle`}; edges-lite.js reads only those, edges.js reads others`);return{edges:n}}function St(e){let t=JSON.parse(e.replace(/^\)\]\}'[^\n]*\n/u,``)),n=Ae(t),r=t.sections?t.sections.reduce((e,t)=>e+(t.map.names?.length??0),0):t.names?.length??null;return{json:{version:t.version,file:t.file,sourceRoot:t.sourceRoot},map:n,namesCount:r}}function P(e){if(e.map)return e.map.files.flatMap(e=>e.source===null?[]:[[e.source,e.content]]);let t=e.json?.sourcesContent??[];return(e.json?.sources??[]).map((e,n)=>[e,t[n]??null])}function Ct(e,t){let n=new Map;for(let{from:r,to:i,specifier:a}of t(e).edges){if(r.source===null||i?.source==null||i.source===r.source)continue;let e=typeof a==`string`?[r.source,i.source,a]:[r.source,i.source];n.set(e.join(`\0`),e)}return[...n.values()]}function wt(e){try{return xt(e)}catch{return{edges:[]}}}var Tt=Object.freeze([]);function F(e){return e?.edges?e.edges:e?.map?(e.edges=Ct(e.map,wt),e.edges):Tt}var I=new WeakMap,L=new WeakMap;function Et(e){let t=F(e);if(!I.has(t)){let e=new Map;for(let[n,r]of t)e.has(n)||e.set(n,new Set),e.get(n).add(r);I.set(t,e)}return I.get(t)}function Dt(e){let t=F(e);if(!L.has(t)){let e=new Map;for(let[n,r,i]of t)i!==void 0&&(e.has(n)||e.set(n,new Map),e.get(n).set(i,r));L.set(t,e)}return L.get(t)}var R=new WeakMap,z=new WeakMap,B=new WeakMap,V=new WeakMap,H=new WeakMap,U=new WeakMap;function W(t){if(t?.metadataOnly)return new Map;let n=t?.bundle??t?.json;if(n&&R.has(n))return R.get(n);let r=new Map;if(!t)return r;if(t.kind===`stasis`){if(!t.bundle)return r;let n=t.bundle.formats;for(let[i,a]of t.bundle.sources)typeof a==`string`&&(e.isResourceFormat(n?.get(i))||r.set(i,a))}else if(t.kind===`sourcemap`)for(let[e,n]of P(t))typeof n==`string`&&r.set(e,n);return n&&R.set(n,r),r}function Ot(e){let t=1;for(let n=e.indexOf(`
|
|
5
|
-
`);n!==-1;n=e.indexOf(`
|
|
6
|
-
`,n+1))t++;return t}var kt=new WeakMap;function At(e){let t=kt.get(e);if(!t){let n=[...e.keys()].toSorted();t={paths:n,numbers:new Map(n.map((e,t)=>[e,t+1]))},kt.set(e,t)}return t}function jt(e,t,n){let r=Array.isArray(t)?t:[];return{integrity:e.integrity,kind:`sourcemap`,size:e.size,...Array.isArray(n)?{npmExecutable:new Set(n.filter(e=>typeof e==`string`))}:{},json:{version:3,sources:r.map(([e])=>e),sourcesContent:r.map(([,,e])=>typeof e==`string`?e:null)},fileSizes:new Map(r.map(([e,t])=>[e,t])),npmBinaries:new Map(r.filter(([,,e,t])=>typeof e!=`string`&&typeof t==`string`).map(([e,t,,n,r])=>[e,{size:t,digest:n,...typeof r==`string`?{link:r}:{}}]))}}var Mt=(e,t)=>e?.npmBinaries?.get(t)?.link;function Nt(e,t){if(t.startsWith(`/`))return null;let n=e.split(`/`).slice(0,-1);for(let e of t.split(`/`))if(e!==``&&e!==`.`){if(e!==`..`)n.push(e);else if(n.pop()===void 0)return null}return n.join(`/`)}function G(e){let t=e?.bundle??e?.json;if(t&&z.has(t))return z.get(t);let n=new Map(W(e));for(let[t,r]of e?.npmBinaries??[])n.set(t,{format:`digest`,...r});if(e?.kind===`stasis`&&e.bundle){let t=e.bundle.formats;for(let[r,i]of e.bundle.sources){if(typeof i!=`string`)continue;let e=t?.get(r);e===`resource`?n.set(r,i):e===`resource:base64`&&n.set(r,{format:`base64`,data:i})}}return t&&z.set(t,n),n}var Pt=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`;function Ft(e){let t=e.endsWith(`=`);if(t?e.length%4!=0||e.at(-3)===`=`:e.length%4==1)return null;let n=t?e.slice(0,e.endsWith(`==`)?-2:-1):e;if(/[^A-Za-z0-9+/]/u.test(n))return null;let r=n.length%4;return r>1&&Pt.indexOf(n.at(-1))&(r===2?15:3)?null:Math.floor(n.length*3/4)}function It(e){return typeof e==`string`?r(e):e?.format===`digest`?e.size:e?.format===`base64`?Ft(e.data):null}function K(e){if(e?.fileSizes)return e.fileSizes;let t=e?.bundle??e?.json;if(t&&B.has(t))return B.get(t);let n=new Map,r=G(e),i=e?.kind===`stasis`?e.bundle?.sources.keys():e&&P(e).map(([e])=>e);for(let e of i??[])n.set(e,It(r.get(e)));return t&&B.set(t,n),n}function Lt(e){if(e?.metadataOnly)return e.unsizedFiles??new Set;let t=K(e);if(U.has(t))return U.get(t);let n=new Set;for(let r of G(e).keys())t.get(r)===null&&n.add(r);return U.set(t,n),n}function Rt(t){let n=K(t);if(H.has(n))return H.get(n);let r=Lt(t),i=t?.kind===`stasis`?t.bundle?.formats:null,a=new Map;for(let[o,s]of n)s===null&&!r.has(o)||a.set(o,e.isResourceFormat(i?.get(o))||t?.npmBinaries?.has(o)?`resource`:`source`);return H.set(n,a),a}function zt(t){let n=K(t),r=t?.kind===`stasis`?t.bundle?.formats:null;if(!r||r.size===0)return n;if(V.has(n))return V.get(n);let i=new Map;for(let[t,a]of n)e.isResourceFormat(r.get(t))||i.set(t,a);return V.set(n,i),i}var q=new WeakMap;function Bt(e){if(e?.kind!==`stasis`||!e.bundle?.modules)return null;if(q.has(e.bundle))return q.get(e.bundle);let t=new Map;for(let[n,r]of e.bundle.modules)for(let e of Object.keys(r.files))t.set(n===`.`?e:`${n}/${e}`,n);return q.set(e.bundle,t),t}function Vt(e,n=null){let r=new Map;if(e?.kind!==`stasis`||!e.bundle?.modules)return r;for(let[i,a]of e.bundle.modules){if(i===`.`||n&&!n.has(i))continue;let e=a?.repo?.github,o=t(a?.repo?.commit);if(typeof e!=`string`||e===``||!o)continue;let s=typeof a.repo.directory==`string`?a.repo.directory:``;r.set(i,{github:e,...s?{directory:s}:{},commit:o})}return r}function Ht(e,t=null,n=(e,t)=>t.name){let r=new Map;if(e?.kind!==`stasis`||!e.bundle?.modules)return r;let i=t===null?null:Bt(e),a=t===null?null:new Set([...t].map(e=>i?.get(e)));for(let[t,i]of e.bundle.modules){if(a&&!a.has(t)||!t.includes(`node_modules`)||!i?.name||typeof i.version!=`string`||!i.version)continue;let e=n(t,i),o=r.get(e);o||(o=new Set,r.set(e,o)),o.add(i.version)}return r}var Ut={__proto__:null,js:`javascript`,mjs:`javascript`,cjs:`javascript`,jsx:`jsx`,ts:`typescript`,mts:`typescript`,cts:`typescript`,tsx:`tsx`,json:`json`,css:`css`,html:`markup`,htm:`markup`,xml:`markup`,svg:`markup`,yml:`yaml`,yaml:`yaml`,sh:`bash`,bash:`bash`,md:`markdown`,markdown:`markdown`,sol:`solidity`,php:`php`,phtml:`php`,rs:`rust`,rb:`ruby`,podspec:`ruby`,py:`python`,pyw:`python`,pyi:`python`,java:`java`,swift:`swift`,cpp:`cpp`,cc:`cpp`,cxx:`cpp`,"c++":`cpp`,hpp:`cpp`,hh:`cpp`,hxx:`cpp`,"h++":`cpp`,h:`cpp`,c:`c`,m:`objectivec`,mm:`objectivec`},Wt={__proto__:null,module:`javascript`,commonjs:`javascript`,"module-typescript":`typescript`,"commonjs-typescript":`typescript`,json:`json`,solidity:`solidity`,php:`php`,shell:`bash`,rust:`rust`,java:`java`,swift:`swift`,objc:`objectivec`,objcpp:`objectivec`,c:`c`,"c-header":`c`,cpp:`cpp`,"cpp-header":`cpp`,ruby:`ruby`,podspec:`ruby`,podfile:`ruby`,fastlane:`ruby`,"podfile-lock":`yaml`,xml:`markup`};function Gt(e){if(typeof e!=`string`)return!1;let t=e.length-1,n=0;for(;n<t&&/\s/u.test(e[n]);)n++;for(;t>n&&/\s/u.test(e[t]);)t--;return n<t&&e[n]===`{`&&e[t]===`}`}function J(e,t,n){if(typeof t==`string`&&Wt[t])return Wt[t];if(typeof e!=`string`)return null;let r=e.slice(e.lastIndexOf(`/`)+1),i=r.lastIndexOf(`.`);if(i<=0)return null;let a=r.slice(i+1).toLowerCase();return a===`map`?Gt(n)?`json`:null:Ut[a]??null}var Kt=Object.freeze({javascript:`JavaScript`,jsx:`JSX`,typescript:`TypeScript`,tsx:`TSX`,json:`JSON`,css:`CSS`,markup:`HTML`,yaml:`YAML`,bash:`Shell`,markdown:`Markdown`,solidity:`Solidity`,php:`PHP`,rust:`Rust`,ruby:`Ruby`,java:`Java`,cpp:`C++`,c:`C`,objectivec:`Objective-C`,python:`Python`,go:`Go`,kotlin:`Kotlin`,swift:`Swift`,dart:`Dart`,sql:`SQL`,lua:`Lua`,csharp:`C#`,scala:`Scala`,vue:`Vue`,svelte:`Svelte`}),qt=Object.freeze({py:`python`,pyw:`python`,go:`go`,kt:`kotlin`,kts:`kotlin`,swift:`swift`,dart:`dart`,sql:`sql`,lua:`lua`,cs:`csharp`,scala:`scala`,sc:`scala`,vue:`vue`,svelte:`svelte`});function Jt(e){let t=typeof e==`string`?e.slice(e.lastIndexOf(`/`)+1):``,n=t.lastIndexOf(`.`),r=n>0?t.slice(n+1).trim().toLowerCase():``,i=J(e)??qt[r];return i?{key:i,label:Kt[i]??i}:r?{key:`extension:${r}`,label:`.${r}`}:{key:`other`,label:`Other`}}function Y(e,t){let n=new Map,r=0,i=0;for(let[a,o]of e){let e=Jt(a),s=n.get(e.key)??{...e,files:0,lines:0,bytes:0};s.files++,s.lines+=o,s.bytes+=t.get(a)??0,n.set(e.key,s),i+=o,r+=t.get(a)??0}return{files:e.size,lines:i,bytes:r,languages:[...n.values()].toSorted((e,t)=>t.lines-e.lines||e.label.localeCompare(t.label))}}var X=6,Z=new WeakMap,Yt=new Set([`terminal`,`code`,`search`,`compare`]);function Xt(e,t=null){return!!t||Yt.has(e)}var Zt=/^sha512-[A-Za-z0-9+/]{86}==$/u;function Qt(e){if(e.fileHashes)return Promise.resolve(e.fileHashes);if(Z.has(e))return Z.get(e);let t=(async()=>{let t=[...W(e)],r=new Map;for(let e=0;e<t.length;e+=32){let i=await Promise.all(t.slice(e,e+32).map(async([e,t])=>[e,await n(t)]));for(let[e,t]of i)r.set(e,t)}return e.fileHashes=r,r})();return Z.set(e,t),t.catch(()=>Z.delete(e)),t}function $t(e){if(typeof e!=`string`)return 0;let t=/\S/gu,n=/[\r\n]/gu,r=0;for(;t.test(e)&&(r++,n.lastIndex=t.lastIndex,n.test(e));)t.lastIndex=n.lastIndex;return r}function Q(e){return e.lineCounts??=new Map([...W(e)].map(([e,t])=>[e,$t(t)]))}function $(e){return e instanceof Map?Object.fromEntries([...e].map(([e,t])=>[e,$(t)])):e}async function en(e){let t=await Qt(e),n=K(e),i=Q(e),a={version:X,integrity:e.integrity,kind:e.kind,size:e.size,codeStats:Y(i,n),files:[...n].map(([e,n])=>[e,n,t.get(e)??null,i.get(e)??null])},o=Lt(e);if(o.size>0&&(a.unsized=[...o]),e.kind===`sourcemap`){let{version:t,file:n,sourceRoot:i,names:o}=e.json,s=P(e);a.json={version:t,file:n,sourceRoot:i,sources:s.map(([e])=>e)},a.sourceSizes=s.map(([,e])=>typeof e==`string`?r(e):null),a.namesCount=e.namesCount??o?.length??null;let c=new Map(a.files.map(([e],t)=>[e,t]));a.edges=F(e).map(([e,t,...n])=>[c.get(e),c.get(t),...n])}else{let t=e.bundle,r={version:t.version,config:t.config,repo:t.repo,package:t.package,formats:$(t.formats),imports:$(t.imports),reason:t.reason,executable:[...t.executable]};if(t.version===0)r.sources=Object.fromEntries([...n.keys()].map(e=>[e,null]));else{let e={},n={};for(let[r,i]of t.modules){let t=r.split(`/`).includes(`node_modules`)?e:n;Object.defineProperty(t,r,{enumerable:!0,value:{name:i.name,version:i.version,ecosystem:i.ecosystem,repo:i.repo,files:Object.fromEntries(Object.keys(i.files).map(e=>[e,null]))}})}r.modules=e,t.config.scope===`full`&&(r.sources=n,r.entries=[...t.entries])}a.bundle=r}return a}function tn(t,n){if(![1,2,3,4,5,X].includes(t?.version)||t.integrity!==n||![`stasis`,`sourcemap`].includes(t.kind)||!Number.isSafeInteger(t.size)||t.size<0||!Array.isArray(t.files))throw Error(`Invalid bundle metadata`);let r=t.version!==X,i=t.version===1,a=new Map,o=new Map,s=new Map;for(let e of t.files){if(!Array.isArray(e)||e.length!==4&&!(i&&e.length===3))throw Error(`Invalid bundle metadata file`);let[t,n,r,c]=e;if(typeof t!=`string`||o.has(t)||n!==null&&(!Number.isSafeInteger(n)||n<0)||r!==null&&(typeof r!=`string`||!Zt.test(r))||n===null&&r!==null||i&&n!==null&&r===null||c!=null&&(!Number.isSafeInteger(c)||c<0))throw Error(`Invalid bundle metadata file`);o.set(t,n),r!==null&&a.set(t,r),c!=null&&s.set(t,c)}let c=new Set(t.unsized??[]);if(t.unsized!==void 0&&(i||!Array.isArray(t.unsized)||c.size!==t.unsized.length)||[...c].some(e=>typeof e!=`string`||!o.has(e)||o.get(e)!==null))throw Error(`Invalid bundle metadata`);let l={integrity:n,kind:t.kind,size:t.size,metadataOnly:!0,fileSizes:o,fileHashes:a,lineCounts:s,unsizedFiles:c,stale:r};if(t.kind===`stasis`){l.bundle=e.fromJSON(t.bundle);let n=l.bundle.sources;if(n.size!==o.size||[...n.keys()].some(e=>!o.has(e)))throw Error(`Invalid bundle metadata inventory`);let r=l.bundle.formats;if(!i&&[...o].some(([t,n])=>a.has(t)!==(n!==null&&!e.isResourceFormat(r.get(t))))||[...c].some(e=>r.get(e)!==`resource:base64`))throw Error(`Invalid bundle metadata inventory`)}else{if(!t.json||typeof t.json!=`object`||![null,void 0].includes(t.namesCount)&&(!Number.isSafeInteger(t.namesCount)||t.namesCount<0))throw Error(`Invalid sourcemap metadata`);if(!Array.isArray(t.json.sources)||t.json.sources.some(e=>!o.has(e))||!Array.isArray(t.sourceSizes)||t.sourceSizes.length!==t.json.sources.length||t.sourceSizes.some(e=>e!==null&&(!Number.isSafeInteger(e)||e<0))||[...o].some(([e,t])=>a.has(e)!==(t!==null))||c.size>0)throw Error(`Invalid sourcemap inventory`);l.json=t.json,l.sourceSizes=t.sourceSizes,l.namesCount=t.namesCount,t.edges!==void 0&&(l.edges=nn(t.edges,t.files))}if(t.codeStats===void 0)l.codeStats=Y(s,o);else{let e=t.codeStats,n=e=>Number.isSafeInteger(e)&&e>=0;if(!e||![e.files,e.lines,e.bytes].every(n)||!Array.isArray(e.languages)||e.languages.some(e=>!e||typeof e.key!=`string`||typeof e.label!=`string`||![e.files,e.lines,e.bytes].every(n)))throw Error(`Invalid bundle code stats`);l.codeStats=e}return l}function nn(e,t){if(!Array.isArray(e))throw TypeError(`Invalid sourcemap edges`);return e.map(e=>{if(!Array.isArray(e)||![2,3].includes(e.length)||e[0]===e[1]||e.length===3&&typeof e[2]!=`string`||e.slice(0,2).some(e=>!Number.isSafeInteger(e)||e<0||e>=t.length))throw Error(`Invalid sourcemap edges`);return[t[e[0]][0],t[e[1]][0],...e.slice(2)]})}function rn(t,{integrity:n,kind:r,size:i}){if(r===`stasis`)return{integrity:n,kind:r,size:i,bundle:e.parse(t)};if(r!==`sourcemap`)throw Error(`Unsupported bundle format`);return{integrity:n,kind:r,size:i,...St(t)}}export{J as a,Y as b,F as c,Et as d,Dt as e,W as f,Ot as g,At as h,jt as i,Mt as j,Nt as k,G as l,It as m,K as n,Rt as o,zt as p,Bt as q,Vt as r,Ht as s,Xt as t,Qt as u,$t as v,Q as w,en as x,tn as y,rn as z};
|