@preventive/triage 1.0.0-alpha.65 → 1.0.0-alpha.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/common/bundle-imports.js +20 -0
  2. package/common/bundle-metadata.js +1 -1
  3. package/common/bundle-reasons.d.ts +4 -0
  4. package/common/bundle-reasons.js +38 -1
  5. package/common/bundle-sources.d.ts +1 -0
  6. package/common/bundle-sources.js +22 -0
  7. package/common/managed/npm-packages.js +3 -3
  8. package/common/managed/routes.js +23 -11
  9. package/common/managed/stasis-config.ts +7 -0
  10. package/out/activity.js +4 -4
  11. package/out/chunk-5F5FPI75.js +3 -0
  12. package/out/chunk-6ATPGDDI.js +1 -0
  13. package/out/chunk-6YGH7BJG.js +42 -0
  14. package/out/{chunk-ISXL3KOS.js → chunk-A5A3LEMV.js} +1 -1
  15. package/out/chunk-CGRIZ5M5.js +1 -0
  16. package/out/chunk-FUHRMY7R.js +247 -0
  17. package/out/{chunk-J2FWBXFV.js → chunk-LBJVV6UB.js} +1 -1
  18. package/out/chunk-LDO42LAC.js +1 -0
  19. package/out/{chunk-24AKGEH3.js → chunk-NB4JBTKK.js} +1 -1
  20. package/out/{chunk-IZ6MYRYB.js → chunk-R3WUYD4F.js} +1 -1
  21. package/out/chunk-U5C2TNNQ.js +52 -0
  22. package/out/chunk-VG5RH6KN.js +2 -0
  23. package/out/{chunk-XCWGOW63.js → chunk-VR3NRE5V.js} +1 -1
  24. package/out/chunk-WFDXHPT2.js +12 -0
  25. package/out/client-managed-import.js +2 -2
  26. package/out/client-managed.js +19 -19
  27. package/out/compare.js +15 -15
  28. package/out/dialogs.js +38 -38
  29. package/out/graph.js +8 -8
  30. package/out/index.html +9 -9
  31. package/out/scan.js +2 -2
  32. package/out/view.css +1 -1
  33. package/out/view.js +15 -15
  34. package/package.json +11 -8
  35. package/server-managed/activity.ts +21 -12
  36. package/server-managed/bundle-build-diagnostics.d.ts +1 -1
  37. package/server-managed/bundle-build-worker.js +84 -15
  38. package/server-managed/bundle-build.ts +95 -19
  39. package/server-managed/bundle-cache.ts +28 -6
  40. package/server-managed/bundle-dependency-reviews.ts +38 -22
  41. package/server-managed/commit-lockfiles.ts +2 -1
  42. package/server-managed/db-neon.ts +1 -1
  43. package/server-managed/dependency-review-comments.ts +31 -12
  44. package/server-managed/http.ts +127 -59
  45. package/server-managed/locked-packages.ts +34 -14
  46. package/server-managed/lockfile-scope.ts +10 -1
  47. package/server-managed/npm-kept.ts +10 -0
  48. package/server-managed/npm-patch.ts +127 -50
  49. package/server-managed/public-workspace.ts +3 -2
  50. package/server-managed/pull-dependencies.ts +55 -37
  51. package/server-managed/pull-dependency-reviews.ts +15 -11
  52. package/server-managed/report-sources.ts +6 -3
  53. package/server-managed/repository-issues.ts +14 -11
  54. package/server-managed/stasis-dependencies.ts +153 -0
  55. package/out/chunk-65PLAG3I.js +0 -12
  56. package/out/chunk-D34CUNO5.js +0 -247
  57. package/out/chunk-DCBXCBLL.js +0 -52
  58. package/out/chunk-F3UI65ZI.js +0 -42
  59. package/out/chunk-FAG6E5RC.js +0 -3
  60. package/out/chunk-PTFQKLKO.js +0 -1
  61. package/out/chunk-QVKFY4FA.js +0 -1
  62. package/out/chunk-SYXT3SFP.js +0 -2
  63. package/out/chunk-WL3SPQB4.js +0 -1
  64. /package/out/{chunk-WCPJDAYA.js → chunk-D6NVKGGG.js} +0 -0
@@ -19,9 +19,11 @@
19
19
  // with, either whole, or compared with a version of its package: for a
20
20
  // version the pull request adds, one it was; for another, any. A patched
21
21
  // one's (`patch`) are of it as patched, by its patch's hash, its patch read
22
- // of the repository where its lockfile names the patch's file (npm-patch.ts):
23
- // compared with the version it patches, where that is one it was, they review
24
- // the patch alone. Locked so at that commit, its patch too, it needs none.
22
+ // of the repository at its file, which its lockfile names, or which is found
23
+ // where it names it by its hash alone (npm-patch.ts withPatchFiles):
24
+ // compared with the version it patches, where that is one it was, they
25
+ // review the patch alone. Locked so at that commit, its patch too, it needs
26
+ // none.
25
27
  // Which versions the repository's lockfiles locked at that commit never
26
28
  // changes: it is read once, every lockfile there of those read here
27
29
  // (pull-dependencies.ts), and kept by the commit (`baselines` in this
@@ -49,18 +51,20 @@ export interface ReviewBaselineStore {
49
51
  const baselines: Lru<Baseline> = lru(500_000, baseline => baseline.versions.size + baseline.unread.length + 1)
50
52
 
51
53
  // Why a version can't be reviewed: from git, of a tarball not npm's
52
- // registry's of its version, or locked with no integrity.
53
- export type Unsupported = 'git' | 'tarball' | 'integrity'
54
+ // registry's of its version, locked with no integrity, or, a Stasis build's
55
+ // (stasis-dependencies.ts), locked by no lockfile read (`unlocked`).
56
+ export type Unsupported = 'git' | 'tarball' | 'integrity' | 'unlocked'
54
57
  // How a version is reviewed: by its name, version and integrity
55
58
  // (`version`), not at all (`skip`), or why it can't be.
56
59
  function reviewedAs(pkg: LockedPackage): 'version' | 'skip' | Unsupported {
60
+ if (pkg.unlocked) return 'unlocked'
57
61
  if (pkg.source === 'file') return 'skip'
58
62
  if (pkg.source === 'git') return 'git'
59
63
  if (pkg.source !== 'registry' || pkg.version === null) return 'tarball'
60
64
  return pkg.integrity ? 'version' : 'integrity'
61
65
  }
62
66
  // The hashes an integrity names, each of which is npm's of it.
63
- const hashesOf = (pkg: LockedPackage) => (pkg.integrity ?? '').split(/\s+/u).filter(Boolean)
67
+ export const hashesOf = (pkg: LockedPackage) => (pkg.integrity ?? '').split(/\s+/u).filter(Boolean)
64
68
  // A version as a baseline holds it: its name and version with each hash,
65
69
  // and its patch.
66
70
  const baselineKeys = (pkg: LockedPackage) => hashesOf(pkg).map(hash => `${pkg.name}@${pkg.version ?? ''}\0${hash}\0${pkg.patchHash ?? ''}`)
@@ -133,18 +137,18 @@ type Reviewer = { login: string; status: PublishedReview['status']; passes?: tru
133
137
 
134
138
  // A version as the client is told it: what its reviews are held to left
135
139
  // out, but its patch, where it is patched (`patch`): its hash, which its
136
- // reviews are held to, and its file, where its lockfile names one, from the
137
- // repository's root, whence its reviews read it.
140
+ // reviews are held to, and its file, where its lockfile names one or it
141
+ // was found, from the repository's root, whence its reviews read it.
138
142
  type Patch = { hash: string; path?: string }
139
- function shown<T extends LockedPackage>(pkg: T): Omit<T, 'integrity' | 'shasum' | 'patchHash' | 'patchPath' | 'lockfile'> & { patch?: Patch } {
143
+ function shown<T extends LockedPackage>(pkg: T): Omit<T, 'integrity' | 'shasum' | 'patchHash' | 'patchPath' | 'patchDir' | 'lockfile' | 'unlocked'> & { patch?: Patch } {
140
144
  const copy = { ...pkg }
141
- for (const field of ['integrity', 'shasum', 'patchHash', 'patchPath', 'lockfile'] as const) delete copy[field]
145
+ for (const field of ['integrity', 'shasum', 'patchHash', 'patchPath', 'patchDir', 'lockfile', 'unlocked'] as const) delete copy[field]
142
146
  return { ...copy, ...pkg.patchHash ? { patch: { hash: pkg.patchHash, ...pkg.patchPath ? { path: pkg.patchPath } : {} } } : {} }
143
147
  }
144
148
 
145
149
  // A version as the registered reviewed dependencies are asked of it, by
146
150
  // what it is asked.
147
- function askedOf(pkg: LockedPackage): [string, ReviewedDependency] {
151
+ export function askedOf(pkg: LockedPackage): [string, ReviewedDependency] {
148
152
  const dependency: ReviewedDependency = { ecosystem: 'npm', lockfile: pkg.lockfile ?? 'npm', name: pkg.name, version: pkg.version ?? '', integrity: pkg.integrity ?? '',
149
153
  ...pkg.shasum ? { shasum: pkg.shasum } : {}, ...pkg.patchHash ? { patchHash: pkg.patchHash } : {} }
150
154
  return [JSON.stringify(dependency), dependency]
@@ -3,7 +3,7 @@ import { createHash } from 'node:crypto'
3
3
  import { extname } from 'node:path'
4
4
  import { promisify } from 'node:util'
5
5
  import { gzip } from 'node:zlib'
6
- import { bundlePackageDirs, bundleSourcesAsMap } from '../common/bundle-sources.js'
6
+ import { bundlePackageDirs, bundlePackageRepos, bundleSourcesAsMap } from '../common/bundle-sources.js'
7
7
  import { bundleSourceLinkImports } from '../common/bundle-source-links.js'
8
8
  import type { BundleDetails } from '../common/bundle-metadata.js'
9
9
  import { loadManagedFindings, managedFindingSourcePaths } from '../common/managed/report-content.ts'
@@ -31,7 +31,7 @@ function formatDirectory(bundleId: string, sha256: string, name: string) {
31
31
  }
32
32
  function sourceCacheFilename(report: ReportRecord, bundle: ManagedBundle, permissions: ViewerPermissions, repo: { github: string | null }, sourcePaths?: Set<string>) {
33
33
  const key = createHash('sha256').update(JSON.stringify([
34
- 'finding-access-v10', sourcePaths ? [...sourcePaths].toSorted() : null, bundle.integrity, bundle.kind, permissions.dependencies, permissions.security, repo,
34
+ 'finding-access-v11', sourcePaths ? [...sourcePaths].toSorted() : null, bundle.integrity, bundle.kind, permissions.dependencies, permissions.security, repo,
35
35
  ])).digest('hex')
36
36
  return `${formatDirectory(bundle.id, report.sha256, report.filename)}/${key}.json.gz`
37
37
  }
@@ -69,7 +69,10 @@ function encodeSources(integrity: string, details: BundleDetails, selection: Ret
69
69
  const bundle = details.kind === 'stasis' ? details.bundle as { formats: Map<string, string> } : null
70
70
  const formats = [...(bundle?.formats ?? [])].filter(([file]) => sources.has(file))
71
71
  const packageDirs = [...(bundlePackageDirs(details) ?? [])].filter(([file]) => sources.has(file))
72
- return compress(Buffer.from(JSON.stringify({ integrity, ...selection, imports, formats, packageDirs })), { level: 6 })
72
+ // The repository and commit each of those files' packages records, which
73
+ // the finding's dependency evidence links to (focus-code.js).
74
+ const packageRepos = [...bundlePackageRepos(details, new Set(packageDirs.map(([, dir]) => dir)))]
75
+ return compress(Buffer.from(JSON.stringify({ integrity, ...selection, imports, formats, packageDirs, packageRepos })), { level: 6 })
73
76
  }
74
77
 
75
78
  type SourcemapEdges = (bundle: ManagedBundle) => Promise<BundleDetails['edges']>
@@ -17,7 +17,7 @@ import { ACTOR, type GraphAccount, actorOf } from './github-accounts.ts'
17
17
  import { GithubApiError } from './github-errors.ts'
18
18
  import { type GraphqlError, githubGraphql } from './github-graphql.ts'
19
19
  import { SHA, count, nameOf, timeOf } from './github-values.ts'
20
- import { touchesLockfile } from './pull-dependencies.ts'
20
+ import { pullRefs, touchesLockfile } from './pull-dependencies.ts'
21
21
  import { ITEM_THREADS, type ReviewNode, TILE_THREADS, pullReviews, reviewFields, reviewsRefused } from './pull-reviews.ts'
22
22
  import type { Connection } from './repository-history.ts'
23
23
 
@@ -57,14 +57,14 @@ const pageQuery = (kind: IssuesKind, state: IssuesState) => `query($owner: Strin
57
57
  closed: ${connection[kind]}(states: ${states[kind].closed}) { totalCount }
58
58
  page: ${connection[kind]}(states: ${states[kind][state]}, first: ${ISSUES_PAGE}, after: $after, orderBy: { field: UPDATED_AT, direction: DESC }) {
59
59
  pageInfo { hasNextPage endCursor }
60
- nodes { ${fields[kind]}${kind === 'pulls' && state === 'open' ? ` baseRefOid headRefOid ${files} ${reviewFields(TILE_THREADS, false)}` : ''} }
60
+ nodes { ${fields[kind]}${kind === 'pulls' && state === 'open' ? ` baseRefOid headRefOid isCrossRepository ${files} ${reviewFields(TILE_THREADS, false)}` : ''} }
61
61
  }
62
62
  }
63
63
  }`
64
64
 
65
65
  type Node = ReviewNode & { number?: unknown; title?: unknown; createdAt?: unknown; updatedAt?: unknown; closedAt?: unknown; mergedAt?: unknown; author?: GraphAccount
66
66
  comments?: { totalCount?: unknown }; labels?: { totalCount?: unknown; nodes?: { name?: unknown; color?: unknown }[] }; state?: unknown; stateReason?: unknown
67
- isDraft?: unknown; reviewDecision?: unknown; additions?: unknown; deletions?: unknown; headRefName?: unknown; baseRefName?: unknown; baseRefOid?: unknown
67
+ isDraft?: unknown; reviewDecision?: unknown; additions?: unknown; deletions?: unknown; headRefName?: unknown; baseRefName?: unknown; baseRefOid?: unknown; isCrossRepository?: unknown
68
68
  commits?: { nodes?: { commit?: { statusCheckRollup?: { state?: unknown } | null } | null }[] }
69
69
  files?: { totalCount?: unknown; nodes?: ({ path?: unknown } | null)[] } | null }
70
70
  type Page = { repository?: { open?: { totalCount?: unknown }; closed?: { totalCount?: unknown }; page?: Connection<Node> } | null }
@@ -178,9 +178,12 @@ export async function repositoryItem(fullName: string, token: string, number: nu
178
178
 
179
179
  // An open pull request's base's and head's commits, by its number, as GitHub
180
180
  // has them now: those its REST API names `base.sha` and `head.sha`
181
- // (pull-dependencies.ts pullCommits). None where either isn't a commit's id.
182
- const commitsOf = (number: number, { baseRefOid: base, headRefOid: head }: Node) =>
183
- typeof base === 'string' && SHA.test(base) && typeof head === 'string' && SHA.test(head) ? [{ number, base, head }] : []
181
+ // (pull-dependencies.ts pullCommits), with the branches they are of
182
+ // (pullRefs), its head's where it is no fork's. None where either isn't a
183
+ // commit's id.
184
+ const commitsOf = (number: number, { baseRefOid: base, headRefOid: head, baseRefName, headRefName, isCrossRepository }: Node) =>
185
+ typeof base === 'string' && SHA.test(base) && typeof head === 'string' && SHA.test(head)
186
+ ? [{ number, base, head, ...pullRefs(baseRefName, isCrossRepository === false ? headRefName : undefined) }] : []
184
187
 
185
188
  // The label the pull requests changing a repository's dependencies carry,
186
189
  // as Dependabot's do: where it has one, a team's Dependencies reads its open
@@ -229,15 +232,15 @@ export async function repositoryIssues(fullName: string, token: string, kind: Is
229
232
  // what its card there and its popup's heading tell (its number, title and
230
233
  // author, when it was opened and last updated, whether it is a draft), the
231
234
  // files by which whether it changes a lockfile is told, and its base's and
232
- // head's commits, by which what its lockfiles add is read. Nothing else a
233
- // tile shows (its labels, comments, size, branches, checks, reviews, threads
234
- // and comments), which GitHub is slow enough to gather for fifty of a large
235
- // repository's to fail the page.
235
+ // head's commits, by which what its lockfiles add is read, with the branches
236
+ // they are of (commitsOf). Nothing else a tile shows (its labels, comments,
237
+ // size, checks, reviews, threads and comments), which GitHub is slow enough
238
+ // to gather for fifty of a large repository's to fail the page.
236
239
  const openPullsQuery = (labelled: boolean) => `query($owner: String!, $name: String!, $first: Int!, $after: String${labelled ? ', $labels: [String!]' : ''}) {
237
240
  repository(owner: $owner, name: $name) {
238
241
  page: pullRequests(states: [OPEN], first: $first, after: $after, ${labelled ? 'labels: $labels, ' : ''}orderBy: { field: UPDATED_AT, direction: DESC }) {
239
242
  pageInfo { hasNextPage endCursor }
240
- nodes { number title createdAt updatedAt author { ${ACTOR} } state isDraft baseRefOid headRefOid ${files} }
243
+ nodes { number title createdAt updatedAt author { ${ACTOR} } state isDraft baseRefOid headRefOid baseRefName headRefName isCrossRepository ${files} }
241
244
  }
242
245
  }
243
246
  }`
@@ -0,0 +1,153 @@
1
+ // The npm versions a repository's stasis.config.json files have Stasis reach,
2
+ // as its dependency review holds to those it names (lockfile-scope.ts
3
+ // stasisConfigs): what the build worker tells of the lockfile it builds
4
+ // (bundle-build-worker.js buildStasisLockfile), kept by the repository, the
5
+ // commit and the file's path, which never change, in this instance and in
6
+ // the database, the versions alone. A build takes minutes, so none is waited
7
+ // for: one not kept is told as pending and built behind the answer, one at a
8
+ // time; one whose slot is busy is built when asked for again, as its page
9
+ // asks. A failed one is held in this instance, then built again as asked.
10
+ import { BundleBuildError, type LockfileInput, type StasisDependency } from './bundle-build.ts'
11
+ import { directoryOf, installsBundle, lockedVersions } from './bundle-dependency-reviews.ts'
12
+ import type { CommitLockfiles } from './commit-lockfiles.ts'
13
+ import type { LockedPackage } from './locked-packages.ts'
14
+ import { isStasisConfig } from './lockfile-scope.ts'
15
+ import { type Lru, lru } from './lru.ts'
16
+ import type { KeptStore } from './npm-kept.ts'
17
+ import { plainObject } from './npm-manifest.ts'
18
+ import { type DirectoryDependencies, type PullDependencies, addedBetween, lockedAs } from './pull-dependencies.ts'
19
+
20
+ // The rules they are told by, kept with them: one told by others is built again.
21
+ export const STASIS_DEPENDENCIES_READ = 1
22
+ // How long a failed build is held: GitHub's failure of it, or an unexpected
23
+ // one (`transient`), and any other, the commit's or the build's own.
24
+ const TRANSIENT_HELD_MS = 60_000
25
+ const FAILED_HELD_MS = 60 * 60_000
26
+ const TRANSIENT = new Set(['github-rate-limited', 'github-build-failed'])
27
+ // How long no build is tried again once one found its slot busy.
28
+ const BUSY_MS = 10_000
29
+ // How often a build under way looks whether the server is stopping.
30
+ const STOPPING_EVERY_MS = 1000
31
+
32
+ export type StasisRead = { status: 'ready'; dependencies: StasisDependency[] } | { status: 'pending' } | { status: 'failed'; error: string; transient: boolean }
33
+
34
+ export interface StasisDependencyReader {
35
+ // What the stasis.config.json at `config` of `repo` reaches at `commit`, as
36
+ // known now; where nothing is, a build of it started behind the answer
37
+ // with `token`, told the `branch` the commit is of, where its asker knows.
38
+ read(repo: { repoId: number; fullName: string }, token: string, commit: string, config: string, branch?: string): Promise<StasisRead>
39
+ }
40
+ interface ReaderOptions {
41
+ store: KeptStore<unknown>
42
+ // Builds one, as the deployment's builds are admitted (http.ts stasisReader).
43
+ build(input: LockfileInput, github: string, token: string, signal: AbortSignal): Promise<StasisDependency[]>
44
+ // Work going on behind an answer, handed to its owner (http.ts trackBehind).
45
+ behind(work: Promise<unknown>): void
46
+ stopping(): boolean
47
+ }
48
+
49
+ const optional = (value: unknown) => value === undefined || typeof value === 'string'
50
+ const dependenciesOf = (value: unknown) => Array.isArray(value) && value.every(one => plainObject(one) && typeof one['name'] === 'string'
51
+ && typeof one['version'] === 'string' && optional(one['integrity']) && optional(one['patch'])) ? value as StasisDependency[] : null
52
+
53
+ export function stasisDependencyReader({ store, build, behind, stopping }: ReaderOptions): StasisDependencyReader {
54
+ const known: Lru<{ read: StasisRead; until: number }> = lru(500_000, ({ read }) => read.status === 'ready' ? read.dependencies.length + 1 : 1)
55
+ const hold = (key: string, read: StasisRead, until = Infinity) => { known.set(key, { read, until }); return read }
56
+ // Whether one is being built here, and till when none is tried after one found its slot busy.
57
+ let building = false, busyTill = 0
58
+
59
+ async function built(key: string, input: LockfileInput, github: string, token: string) {
60
+ const stop = new AbortController()
61
+ const watching = setInterval(() => { if (stopping()) stop.abort() }, STOPPING_EVERY_MS)
62
+ watching.unref()
63
+ try {
64
+ const dependencies = await build(input, github, token, stop.signal)
65
+ await store.write(key, dependencies, Date.now())
66
+ hold(key, { status: 'ready', dependencies })
67
+ } catch (err) {
68
+ if (stop.signal.aborted) return
69
+ const refused = err instanceof BundleBuildError
70
+ const code = refused ? err.code : 'build-failed'
71
+ // Its slot another's, or given up to a build asked for: built when asked for again.
72
+ if (code === 'build-busy' || code === 'build-yielded') { busyTill = Date.now() + BUSY_MS; return }
73
+ if (!refused) console.warn('managed: stasis dependencies build failed:', err)
74
+ const transient = !refused || TRANSIENT.has(code)
75
+ hold(key, { status: 'failed', error: code, transient }, Date.now() + (transient ? TRANSIENT_HELD_MS : FAILED_HELD_MS))
76
+ } finally {
77
+ clearInterval(watching)
78
+ building = false
79
+ }
80
+ }
81
+
82
+ return {
83
+ async read({ repoId, fullName }, token, commit, config, branch) {
84
+ const key = `${repoId}\0${STASIS_DEPENDENCIES_READ}\0${commit}\0${config}`
85
+ const held = known.get(key)
86
+ if (held && Date.now() < held.until) return held.read
87
+ const kept = dependenciesOf((await store.read(key))?.value)
88
+ if (kept) return hold(key, { status: 'ready', dependencies: kept })
89
+ if (!building && Date.now() >= busyTill && !stopping()) {
90
+ building = true
91
+ behind(built(key, { repoId, commit, config, ...branch !== undefined && { branch } }, fullName, token))
92
+ }
93
+ return { status: 'pending' }
94
+ },
95
+ }
96
+ }
97
+
98
+ // The stasis.config.json at `config` as a directory of a review's
99
+ // dependencies (pull-dependencies.ts DirectoryDependencies), by its own
100
+ // path: the versions its entries reach at `head` that they didn't at `base`,
101
+ // a pull request's merge base, and all they reach at `head`; for a default
102
+ // branch, of no base, those alone. Each is told as the lockfiles in its
103
+ // directory or above lock it there (`locked`; lockedVersions), a patched one
104
+ // as the build installed it; one none of them locks told so (`unlocked`),
105
+ // which can't be reviewed. Where a build is still to be made, that it is
106
+ // (`stasis-pending`); where the head's failed, or GitHub failed the base's,
107
+ // why (`stasis-failed`). A base that couldn't be built of its own, as one of
108
+ // no such file, reaches nothing, so every version at the head is new.
109
+ export async function stasisDirectory(config: string, base: string | null, head: string, read: (commit: string) => Promise<StasisRead>,
110
+ locked: (commit: string, held: (path: string) => boolean) => Promise<CommitLockfiles>): Promise<DirectoryDependencies> {
111
+ const paths = [config]
112
+ const [after, before] = await Promise.all([read(head), base === null || base === head ? null : read(base)])
113
+ if (after.status === 'failed') return { paths, error: 'stasis-failed', detail: after.error }
114
+ if (before?.status === 'failed' && before.transient) return { paths, error: 'stasis-failed', detail: before.error }
115
+ if (after.status === 'pending' || before?.status === 'pending') return { paths, error: 'stasis-pending' }
116
+ const lockedAt = async (commit: string, dependencies: StasisDependency[]): Promise<LockedPackage[]> => {
117
+ const found = lockedVersions(dependencies, await locked(commit, path => installsBundle(path, directoryOf(config))))
118
+ return [...found.locked, ...found.unlocked.map(({ name, version }): LockedPackage => ({ name, version, source: 'registry', unlocked: true }))]
119
+ }
120
+ const [now, was] = await Promise.all([lockedAt(head, after.dependencies), before?.status === 'ready' ? lockedAt(base!, before.dependencies) : []])
121
+ return addedBetween(paths, before === null ? now : was, now)
122
+ }
123
+
124
+ // `answer`, a review's dependencies, each version its package manager alone
125
+ // asks a review of marked so (`unreached`): one a lockfile locks that the
126
+ // stasis.config.json in its directory, held to with it, reaches not, nor
127
+ // does any other told; but one another lockfile, with none beside it, locks
128
+ // too. Nothing is marked by a file whose reach isn't told (still built,
129
+ // failed, or more than are told). `lockfiles`: each lockfile and what it
130
+ // locks, where `answer`'s directories don't tell them apart (a default
131
+ // branch's).
132
+ const isStasis = (dir: DirectoryDependencies) => dir.paths.length > 0 && isStasisConfig(dir.paths[0]!)
133
+ export function withReach<T extends PullDependencies>(answer: T, lockfiles?: { path: string; packages: LockedPackage[] }[]): T {
134
+ const beside = new Set<string>(), reached = new Set<string>()
135
+ for (const dir of answer.lockfiles) {
136
+ if (!isStasis(dir) || 'error' in dir || dir.moreLocked > 0) continue
137
+ beside.add(directoryOf(dir.paths[0]!))
138
+ for (const pkg of dir.locked) reached.add(lockedAs(pkg))
139
+ }
140
+ if (beside.size === 0) return answer
141
+ const locking = lockfiles ?? answer.lockfiles.flatMap(dir => isStasis(dir) || 'error' in dir || dir.paths.length === 0 ? [] : [{ path: dir.paths[0]!, packages: dir.locked }])
142
+ // Those a lockfile beside such a file locks, and those any other does.
143
+ const alone = new Set<string>(), asked = new Set<string>()
144
+ for (const { path, packages } of locking) {
145
+ const keys = beside.has(directoryOf(path)) ? alone : asked
146
+ for (const pkg of packages) keys.add(lockedAs(pkg))
147
+ }
148
+ const marked = <P extends LockedPackage>(pkg: P): P => {
149
+ const key = lockedAs(pkg)
150
+ return alone.has(key) && !asked.has(key) && !reached.has(key) ? { ...pkg, unreached: true } : pkg
151
+ }
152
+ return { ...answer, lockfiles: answer.lockfiles.map(dir => isStasis(dir) || 'error' in dir ? dir : { ...dir, added: dir.added.map(marked), locked: dir.locked.map(marked) }) }
153
+ }
@@ -1,12 +0,0 @@
1
- import{a as e}from"./chunk-QRKFPLA4.js";import{b as t}from"./chunk-TUII34K2.js";var n=new Set([`module`,`commonjs`,`json`,`module-typescript`,`commonjs-typescript`]),r=new Set([`solidity`,`php`,`shell`,`rust`,`teal`]),i=new Set([`java`,`kotlin`,`gradle`,`objc`,`objcpp`,`swift`,`c`,`cpp`,`c-header`,`cpp-header`,`ruby`,`python`,`cmake`,`podspec`,`podfile`,`podfile-lock`,`gemfile`,`gemfile-lock`,`template`,`xml`,`env`,`fastlane`,`pbxproj`]),a=new Set([`generic-javascript`,`generic-typescript`]),o=new Set([`resource`,`resource:base64`]),s=new Set([`stat:file`,`stat:directory`]),c=new Set([...n,...r,...i,...a,...o,`patch`,`directory`,...s]),l=e=>s.has(e),u=e=>e===`directory`||e===`stat:directory`?`directory`:`file`,d=new Set([`module`,`commonjs`,`module-typescript`,`commonjs-typescript`]),f=(e,t)=>a.has(e)&&d.has(t);function p(e,t,n){if(e===t)return e;if(f(e,t))return t;if(f(t,e))return e;let r=l(e);if(r!==l(t)&&u(e)===u(t))return r?t:e;throw Error(`format conflict for '${n}' ('${t}' vs '${e}')`)}var m=(e,t)=>t===``?e:e===`.`?t:`${e}/${t}`,h=/^(?=[A-Za-z0-9-]{1,39}\/)[A-Za-z0-9](?:-?[A-Za-z0-9])*\/(?!\.\.?$)[\w.-]{1,100}$/u,ee=/^(?!\.\.?(?:\/|$))[\w.~@+-]+(?:\/(?!\.\.?(?:\/|$))[\w.~@+-]+)*$/u,te=/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u,g={github:e=>typeof e==`string`&&h.test(e),directory:e=>typeof e==`string`&&e.length<=1024&&(e===``||ee.test(e)),commit:e=>typeof e==`string`&&te.test(e)},ne=(e,t)=>e?.toLowerCase()===t?.toLowerCase(),_=(e,t,n)=>{if(e===void 0)return;E(e)||C(!1,`${n} must be an object`);for(let r of Object.keys(e))Object.hasOwn(t,r)||C(!1,`unknown ${n} key '${r}'`);let r=Object.entries(t).map(([t,r])=>typeof r==`object`?[t,_(e[t],r,`${n}.${t}`)]:(e[t]!==void 0&&!r(e[t])&&C(!1,`invalid ${n}.${t}: ${JSON.stringify(e[t])}`),[t,e[t]])).filter(([,e])=>e!==void 0);return r.length===0?void 0:Object.freeze(D(r))},re=(e,t=`bundle repo`)=>_(e,g,t),v=(e,t)=>t??(M(e)?`npm`:void 0),ie=(e,t,n,r,i)=>(a,{ecosystem:o,[e]:s},c)=>{if(s===void 0)return;r(a,o)||C(!1,`${c}: '${a}' is no ${i} bucket, and carries no ${e}`);let l=_(s,t,`${c} module '${a}' ${e}`);return l?.[n]===void 0&&C(!1,`${c} module '${a}' ${e} has no ${n}`),l},ae=ie(`repo`,g,`github`,(e,t)=>v(e,t)!==void 0,`dependency's`),oe={sha1:/^sha1-[A-Za-z\d+/]{27}=$/u,sha256:/^sha256-[A-Za-z\d+/]{43}=$/u,sha512:/^sha512-[A-Za-z\d+/]{86}==$/u},se=/^(?:\.\.\/)*(?!\.\.?(?:\/|$))[^/\\\p{Cc}]+(?:\/(?!\.\.?(?:\/|$))[^/\\\p{Cc}]+)*$/u,ce={integrity:e=>typeof e==`string`&&oe.sha256.test(e),file:e=>typeof e==`string`&&e.length<=4096&&se.test(e)},le=(e,t)=>M(e)&&v(e,t)===`npm`,ue={npm:`sha512`,cargo:`sha256`,composer:`sha1`,soldeer:`sha256`},de=(e,{ecosystem:t,integrity:n},r)=>{if(n===void 0)return;let i=v(e,t);return(!Object.hasOwn(ue,i)||i===`npm`&&!M(e))&&C(!1,`${r}: '${e}' is no npm, cargo, composer or soldeer dependency's bucket, and carries no integrity`),typeof n==`string`&&oe[ue[i]].test(n)||C(!1,`invalid ${r} module '${e}' integrity: ${JSON.stringify(n)}`),n},fe=ie(`patch`,ce,`integrity`,le,`npm dependency's`),pe=e=>typeof e==`string`&&/^[\w.+@/~'!()*-]+$/u.test(e),y={name:pe,version:pe},me=e=>typeof e==`string`&&e!==``&&!e.includes(`\\`)&&e.split(`/`).every(e=>e!==``&&e!==`.`&&e!==`..`&&e!==`node_modules`),he=(e,t,n)=>typeof e==`string`&&me(n)&&e===`${t}/${n}`,ge={vendored:()=>!0,subpackages:(e,t,n)=>he(e.name,t,n)},_e=(e,t)=>{for(let n=t.lastIndexOf(`/`);n>0;n=t.lastIndexOf(`/`,n-1))if(Object.hasOwn(e,t.slice(0,n)))return t.slice(0,n)};function ve(e,t){if(e===void 0)return;let n=new Set(Object.keys(t).map(t=>_e(e,t)).filter(e=>e!==void 0));return n.size===0?void 0:Object.freeze(D(w(n).map(t=>[t,e[t]])))}var ye=(e,t,{name:n,ecosystem:r,files:i,[e]:a},o)=>{if(a===void 0)return;v(t,r)===void 0&&C(!1,`${o}: '${t}' is no dependency's bucket, and carries no ${e}`),E(a)||C(!1,`${o} module '${t}' ${e} must be an object`);let s=D(Object.entries(a).map(([r,i])=>{me(r)||C(!1,`${o} module '${t}' ${e}: invalid directory ${JSON.stringify(r)}`);let a=_(i,y,`${o} module '${t}' ${e} '${r}'`);return a?.name===void 0&&C(!1,`${o} module '${t}' ${e} '${r}' has no name`),ge[e](a,n,r)||C(!1,`${o} module '${t}' ${e} '${r}' is named '${a.name}', not '${n}/${r}'`),[r,a]})),c=ve(s,i),l=Object.keys(s).find(e=>!Object.hasOwn(c??{},e));return l!==void 0&&C(!1,`${o} module '${t}' ${e} '${l}' holds none of its files`),c},be={integrity:de,patch:fe,repo:ae},b=Object.keys(ge),x=[...Object.keys(be),...b],xe=[`ecosystem`,...x],S=e=>{let t={name:e.name,version:e.version};for(let n of xe)e[n]!==void 0&&(t[n]=e[n]);return t.files=e.files,t},Se={integrity:(e,t)=>e===t,patch:(e,t)=>e?.integrity===t?.integrity&&(e?.file===void 0||t?.file===void 0||e.file===t.file)},Ce=Object.keys(Se),we=(e,t,n)=>Se[e](t,n),Te=(e,t)=>e[t]??(t===`patch`&&e.integrity!==void 0?null:void 0),Ee=(e,t,n,r)=>{if(we(e,t[e],n[e]))return;let[i,a]=[t[e],n[e]].map(e=>JSON.stringify(e)??`none`);C(!1,`${r} ${e} mismatch (${i} vs ${a})`)},De=(e,t,n)=>{let[r,i]=[t[e],n[e]];if([r,i].every(e=>typeof e==`object`&&!!e))return Object.keys(i).some(e=>r[e]===void 0)?Object.freeze({...i,...r}):void 0};function Oe(e,t,n=`module`){let r;for(let i of Object.keys(be))if(Ce.includes(i)&&Te(e,i)!==void 0&&Te(t,i)!==void 0){Ee(i,e,t,n);let a=De(i,e,t);a&&((r??={})[i]=a)}else e[i]===void 0&&t[i]!==void 0&&((r??={})[i]=t[i]);for(let n of b)t[n]===void 0||Object.keys(t[n]).every(t=>Object.hasOwn(e[n]??{},t))||((r??={})[n]=Object.freeze(D([...Object.entries(t[n]),...Object.entries(e[n]??{})])));return r===void 0?e:S({...e,...r})}function ke(e,t,n,r,i){let a={};for(let[i,o]of Object.entries(be))a[i]=r.includes(i)?o(e,t,n):void 0;for(let o of b)a[o]=r.includes(o)?ye(o,e,{...t,[o]:i(o)},n):void 0;return a}function Ae(e,t,n,r=x){let{name:i,version:a,ecosystem:o}=e;C(o===void 0||typeof o==`string`),E(e.files)||C(!1,`${n}: module '${t}' files must be an object`);let s=D(Object.entries(e.files));return S({name:i,version:a??void 0,ecosystem:o,...ke(t,{...e,files:s},n,r,t=>e[t]),files:s})}function je(e,{scope:t=`full`}={}){let n=new Set;for(let[r,{files:i}]of e)if(t===`full`||M(r))for(let e of Object.keys(i))n.add(m(r,e));return n}function Me(e,{what:t,files:n,formats:r,scope:i}){if(e.includes(`\\`))return`holds a '\\'`;if(k(e))return`escapes the root`;if(i!==`full`&&!M(e))return`is outside node_modules, which a '${i}'-scope ${t} does not record`;if(!n.has(e))return`names no file the ${t} records`;let a=r.get(e);return a===`directory`?`is a directory capture, not a file`:l(a)?`is a payload-free '${a}' record, not a file`:null}function Ne(e,{what:t,files:n,formats:r,scope:i}){for(let a of e){let e=Me(a,{what:t,files:n,formats:r,scope:i});C(e===null,`${t}: executable entry '${a}' ${e}`)}}function Pe(e,t,n,r){C(Array.isArray(e),`${t} must be an array of file paths`);let i=new Set;for(let t of e)r(t),C(!i.has(t),`${n} '${t}' is listed twice`),i.add(t);return i}function Fe(e,{what:t,files:n,formats:r,scope:i=`full`}){if(e===void 0)return new Set;let a=`${t}: executable entry`,o=Pe(e,`${t}: executable`,a,e=>C(typeof e==`string`&&e!==``,`${a} must be a non-empty string`));return Ne(o,{what:t,files:n,formats:r,scope:i}),o}function Ie(e,{what:t,modules:n,formats:r,scope:i}){if(e.size!==0)return Ne(e,{what:t,files:je(n,{scope:i}),formats:r,scope:i}),O(e)}function C(e,t){if(!e)throw Error(t)}var Le=`stasis.lock.json`,Re=new Set([`node_modules`,`full`]),ze=(e,t)=>C(Re.has(e),`${t} scope must be node_modules or full, got ${JSON.stringify(e)}`),Be=e=>{let t=e.slice(e.lastIndexOf(`/`)+1).toLowerCase();return t===Le||t.endsWith(`.${Le}`)},Ve=/(?:^|\/)(?:\.git(?:\/|$)|(?:\.npm-extension\.[cm]?[jt]s|\.?pnpmfile\.[cm]?[jt]s|\.npmrc|\.yarnrc(?:\.yml)?|\.?bunfig\.toml|\.pnp\.(?:c?js|loader\.mjs|data\.json))$)/iu,He=/(?:^|\/)node_modules\/(?:[^/]*\/)*(?:pnpm-workspace\.yaml|\.env\.[^/]*|[^/]*\.env)$/iu,Ue=e=>Be(e)||Ve.test(e)||He.test(e);function We(e,t){let n=0;for(;n<e.length&&e[n]===t[n];)n++;let r=e.length-n,i=t.length-n;if(r===0&&i===0)return 0;if(r<2)return i<2&&(e[n]??``)>(t[n]??``)?1:-1;if(i<2)return 1;if(e[n]===`*`)return-1;if(t[n]===`*`||e[n]===`node_modules`)return 1;if(t[n]===`node_modules`)return-1;let a=e.slice(n).join(`\0`),o=t.slice(n).join(`\0`);if(a<o)return-1;if(a>o)return 1;throw Error(`Unreachable`)}var w=(e,t=e=>e)=>Array.from(e,e=>({item:e,segments:t(e).split(`/`)})).toSorted((e,t)=>We(e.segments,t.segments)).map(({item:e})=>e),T=([e])=>e;function E(e){if(!e)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}var D=e=>Object.setPrototypeOf(Object.fromEntries(e),null),O=e=>w(e),Ge=(e,{sorted:t=!0}={})=>D((t?w(e,T):[...e]).map(([e,n])=>[e,n instanceof Map?Ge(n,{sorted:t}):n]));function Ke(e,t,n){let r=e.get(t);return r===void 0&&e.set(t,r=n()),r}var qe=(e,t)=>Ke(e,t,()=>new Map),Je=e=>new Map(Object.entries(e).map(([e,t])=>[e,E(t)?Je(t):t]));function k(e){if(e.startsWith(`/`))return!0;if(!e.includes(`..`))return!1;let t=0;for(let n of e.split(`/`))if(n!==`.`&&n!==``){if(n!==`..`)t++;else if(--t<0)return!0}return!1}var Ye=e=>e.includes(`\\`)||k(e),A=(e,t)=>C(!Ye(e),`${t}: path '${e}' escapes the root or holds a '\\'`),Xe=e=>typeof e==`string`&&e!==``&&!Ye(e),Ze=(e,t)=>C(Xe(e),`${t}: invalid entry ${JSON.stringify(e)}`),Qe=(e,t)=>Pe(e,`${t}: entries`,`${t}: entry`,e=>Ze(e,t));function $e(e,t){for(let n of e)Ze(n,t);return O(e)}function et(e,t){A(e,`formats`),C(c.has(t),`unknown format '${t}' for ${e}`)}function tt(e){C(E(e));let t=new Map;for(let[n,r]of Object.entries(e)){et(n,r);let e=n===``?`.`:n;C(!t.has(e),`duplicate format key '${e}'`),t.set(e,r)}return t}function nt(e,t,n){for(let[r,i]of e)l(i)&&t.has(r)&&C(!1,`${n}: '${r}' is a payload-free '${i}' record, yet carries content`)}function rt(e){for(let[t,n]of e)et(t,n);return Ge(e)}function it(e){for(let[,t]of e){C(t instanceof Map);for(let[e,n]of t){A(e,`imports`),C(n instanceof Map);for(let[,e]of n)if(typeof e==`string`)A(e,`imports`);else{C(e instanceof Map&&e.size>0,`import target must be a file or a non-empty {platform: file} map`);for(let[t,n]of e)C(typeof t==`string`&&t.length>0&&!t.includes(`/`),`invalid platform key '${t}'`),C(typeof n==`string`),A(n,`imports`)}}}}function at(e){C(E(e));let t=Je(e);return it(t),t}function ot(e){return it(e),Ge(e)}function st(e,{skipEmpty:t=!1,metadata:n=!0,what:r}={}){let i=n===!0?x:n===!1?[]:n,a={modules:[],sources:[]};for(let[n,o]of e){if(t&&Object.keys(o.files).length===0)continue;let e=M(n);e&&C(o.name&&o.version&&o.files);let s=D(w(Object.entries(o.files),T));a[e?`modules`:`sources`].push([n,S({...o,...ke(n,{...o,files:s},r,i,e=>ve(o[e],s)),files:s})])}return{modules:D(w(a.modules,T)),sources:D(w(a.sources,T))}}function ct(e,t,n){let r=new Map;for(let i of e.config.scope===`full`?[`modules`,`sources`]:[`modules`]){if(i===`modules`&&e.modules===void 0)continue;C(E(e[i]),`${t}: ${i} must be an object`);let a=i===`modules`;for(let[o,s]of Object.entries(e[i]))C(M(o)===a),A(o,t),C(s?.name&&(s.version||!a)&&s.files),r.set(o,Ae(s,o,t,n))}return r}function lt({config:{scope:e},entries:t,modules:n,formats:r,imports:i,executable:a},o,s){let c=e===`full`,l=st(n,{...s,what:o});return{entries:c?$e(t,o):void 0,sources:c?l.sources:void 0,modules:l.modules,formats:r===null?void 0:rt(r),imports:i===null?void 0:ot(i),executable:Ie(a,{what:o,modules:n,formats:r??new Map,scope:e})}}function ut(e,t){return!(e instanceof Map)||!(t instanceof Map)?e===t:e.size===t.size&&e.entries().every(([e,n])=>t.get(e)===n)}var dt=e=>e instanceof Map?`{${[...e].map(([e,t])=>`${e}: ${t}`).join(`, `)}}`:e;function ft(e,t,n){let r=new Map;for(let i of[e,t])for(let[e,t]of i){let i=qe(r,e);for(let[e,r]of t){let t=qe(i,e);for(let[i,a]of r)t.has(i)?C(ut(t.get(i),a),`${n}: import '${i}' from '${e}' resolves differently ('${dt(t.get(i))}' vs '${dt(a)}')`):t.set(i,a instanceof Map?new Map(a):a)}}return r}function pt(e,t,n){let r=e.get(t);e.set(t,r===void 0?n:p(n,r,t))}function mt(e,t,n){let r=new Map;try{for(let n of[e,t])for(let[e,t]of n)pt(r,e,t)}catch(e){throw Error(`${n}: ${e.message}`,{cause:e})}return r}var ht=(e,t,n,r)=>e.size===0?new Set(t):new Set(t).union(e.difference(je(n,{scope:r}))),gt=/(?:^|\/)\.{0,2}(?:\/|$)/u;function j(e,t,n){let r=m(e,t);return(r!==`.`||t!==``)&&gt.test(r)&&C(!1,`${n}: non-canonical file key ${JSON.stringify(r)}`),r.includes(`\\`)&&C(!1,`${n}: file key '${r}' holds a '\\', which no path may`),r}function _t(e,t,n){let r=new Map;for(let[i,{files:a}]of e){typeof i!=`string`&&C(!1,`${t}: bucket dir ${String(i)} is not a string`),A(i,t);for(let e of Object.keys(a)){let a=j(i,e,t),o=r.get(a);o!==void 0&&n(a,o,i),r.set(a,i)}}return r}var vt=(e,t)=>n=>C(!1,`duplicate file key '${n}' across ${e} buckets -- module bucketing changed between writes (a workspace package without a version now owns its own bucket); regenerate the ${t}`);function yt(e,t,n,{held:r=!1}={}){let i=new Map;for(let a of[e,t])for(let[e,t]of a){let a=i.get(e);if(a===void 0)i.set(e,S({...t,files:Object.assign(Object.create(null),t.files)}));else{C(a.name===t.name,`${n}: module '${e}' name mismatch ('${a.name}' vs '${t.name}')`),C(a.version===t.version,`${n}: module '${e}' version mismatch ('${a.version}' vs '${t.version}')`+(a.version==null==(t.version==null)?``:` -- an artifact from an older stasis may record a placeholder version for a workspace package without one; regenerate it (bundle=replace / lock=replace)`)),C(a.ecosystem===t.ecosystem,`${n}: module '${e}' ecosystem mismatch ('${a.ecosystem??`(none)`}' vs '${t.ecosystem??`(none)`}')`),i.set(e,Oe(a,t,`${n}: module '${e}'`));for(let i of Ce){if(a[i]===void 0==(t[i]===void 0)||r&&a[i]===void 0)continue;let[o,s]=a[i]===void 0?[t,a]:[a,t],c=Object.keys(s.files).find(e=>!Object.hasOwn(o.files,e));c!==void 0&&C(!1,`${n}: module '${e}' ${i} is recorded of one side's files, not of '${m(e,c)}' the other adds`)}for(let[r,i]of Object.entries(t.files))Object.hasOwn(a.files,r)?C(a.files[r]===i,`${n}: content mismatch for '${m(e,r)}'`):a.files[r]=i}}return _t(i,n,(e,t,r)=>C(!1,`${n}: file '${e}' is bucketed under both '${t}' and '${r}' -- module bucketing changed between the artifacts (a workspace package without a version now owns its own bucket); regenerate the artifact (bundle=replace / lock=replace)`)),i}var M=e=>e===`node_modules`||e.startsWith(`node_modules/`)||e.endsWith(`/node_modules`)||e.includes(`/node_modules/`),bt=`node_modules/`;function xt(e){let t=e.length;for(;(t=e.lastIndexOf(bt,t-1))!==-1;)if(t===0||e[t-1]===`/`)return t;return-1}function St(e){let t=xt(e);if(t===-1)return null;let n=t+bt.length,r=e.slice(n).split(`/`),i=r[0].startsWith(`@`)?2:1,a=r.slice(0,i);if(r.length<=i||a.includes(``))return null;let o=a.join(`/`);return{dir:e.slice(0,n)+o,rel:r.slice(i).join(`/`),name:o}}var N=1,Ct=0,wt=vt(`bundle`,`artifact (bundle=replace)`),Tt=(e,t)=>{let n=_t(e,`bundle`,wt);for(let e of n.keys())C(!Ue(e),`bundle: ${e} is a file no bundle may carry`);return nt(t,n,`bundle`),n},Et=e=>St(e)??{dir:`.`,rel:e===`.`?``:e,name:null};function Dt(e){C(E(e),`bundle: sources must be an object`);let t=new Map;for(let[n,r]of Object.entries(e)){A(n,`bundle`);let{dir:e,rel:i,name:a}=Et(n);C(!k(e)&&!k(i));let{files:o}=Ke(t,e,()=>({name:a,version:null,files:Object.create(null)}));C(!Object.hasOwn(o,i),`bundle: duplicate file key '.' (v0 '' and '.')`),o[i]=r}return t}function Ot(){throw Error(`bundle: file contents are not retained by this contents-free Bundle`)}var kt=(e,{files:t,...n})=>{let r=Object.create(null);for(let[n,i]of Object.entries(t))typeof i!=`symbol`&&C(!1,`bundle: file '${m(e,n)}' is not a placeholder`),Object.defineProperty(r,n,{get:Ot,enumerable:!0});return{...n,files:Object.freeze(r)}},P=(e,t)=>{if(e===void 0&&t===void 0)return;let n=new Map;for(let r of[e,t])for(let[e,t]of Object.entries(r??{}))Array.isArray(t)&&n.set(e,new Set([...n.get(e)??[],...t]));return D([...n.keys()].toSorted().map(e=>[e,O(n.get(e))]))},At=(e,t)=>Object.hasOwn(g,e)&&g[e](t),jt=(e,t)=>e?.github===void 0||!ne(e.github,t?.github)?void 0:D(Object.keys(g).filter(n=>e[n]!==void 0&&(n===`github`||e[n]===t[n])).map(t=>[t,e[t]])),Mt=e=>{if(!E(e)||e.root!==!0||Object.hasOwn(e,`directory`))return e;let{root:t,...n}=e;return n},Nt={npm:y,composer:y,cargo:y},Pt=(e,t)=>D(Object.keys(Nt).map(n=>{let[r,i]=[e?.[n],t?.[n]];return[n,r?.name!==void 0&&r.name===i?.name?D(Object.entries(r).filter(([e,t])=>t===i[e])):void 0]})),F=class e{static VERSION=N;#e;get repo(){return this.#e}set repo(e){this.#e=re(e)}#t;get package(){return this.#t}set package(e){this.#t=_(e,Nt,`bundle package`)}constructor({config:e={scope:`full`},entries:t,modules:n,formats:r,imports:i,executable:a,reason:o,repo:s,package:c,version:l=N}={}){C([Ct,N].includes(l)),ze(e.scope,`bundle`),this.version=l,this.config=e,this.entries=t??new Set,this.modules=n??new Map,this.formats=r??new Map,this.imports=i??new Map,this.executable=a??new Set,this.reason=o,this.repo=s,this.package=c}get sources(){let e=new Map;for(let[t,{files:n}]of this.modules)for(let[r,i]of Object.entries(n))e.set(m(t,r),i);return e}static isResourceFormat(e){return o.has(e)||e===`directory`}get hasCode(){return this.modules.entries().some(([t,{files:n}])=>Object.keys(n).some(n=>!e.isResourceFormat(this.formats.get(m(t,n)))))}static parse(t){return e.fromJSON(JSON.parse(t))}static fileKeyAt(e){let[t,n,r,i]=e;if(typeof n==`string`){if(e.length===2&&t===`sources`){let e=Et(n);return j(e.dir,e.rel,`bundle`)}if(e.length===4&&(t===`sources`||t===`modules`)&&r===`files`&&typeof i==`string`)return j(n,i,`bundle`)}}static fromJSON(t,{contents:n=!0}={}){C(t.version===N||t.version===Ct),ze(t.config?.scope,`bundle`);let r=tt(t.formats),i=t.version===N;i&&t.config.scope!==`full`&&C(t.entries===void 0&&t.sources===void 0);let a=i?ct(t,`bundle`):Dt(t.sources),o=Tt(a,r),s=at(t.imports);if(!n)for(let[e,t]of a)a.set(e,kt(e,t));return new e({version:t.version,config:t.config,entries:i&&t.entries!==void 0?Qe(t.entries,`bundle`):new Set,modules:a,formats:r,imports:s,executable:i?Fe(t.executable,{what:`bundle`,files:o,formats:r,scope:t.config.scope}):new Set,reason:E(t.reason)?t.reason:void 0,repo:Mt(t.repo),package:t.package})}serialize(){return JSON.stringify(this.#n(),void 0,2)}serializedBytes(){let e=this.#n(),t=Object.keys(e.modules);if(t.length===0)return Buffer.from(JSON.stringify(e,void 0,2));let{modules:n,...r}=e,i=JSON.stringify(r,void 0,2);C(i.endsWith(`
2
- }`));let a=[],o=e=>a.push(Buffer.from(e));o(i.slice(0,-2)),o(`,
3
- "modules": {
4
- `);for(let[e,r]of t.entries())e>0&&o(`,
5
- `),o(JSON.stringify({indent:{[r]:n[r]}},void 0,2).slice(16,-6));return o(`
6
- }
7
- }`),Buffer.concat(a)}#n(){Tt(this.modules,this.formats);let{entries:e,sources:t,modules:n,formats:r,imports:i,executable:a}=lt(this,`bundle`,{skipEmpty:!0});return{version:N,config:this.config,repo:this.repo,package:this.package,entries:e,formats:r,imports:i,executable:a,reason:P(this.reason,void 0),sources:t,modules:n}}withReason(t,n=[...this.sources.keys()]){let{version:r,config:i,entries:a,modules:o,formats:s,imports:c,executable:l,repo:u,package:d}=this,f=P(this.reason,{[t]:n});return new e({version:r,config:i,entries:a,modules:o,formats:s,imports:c,executable:l,reason:f,repo:u,package:d})}merge(t){return C(this.config.scope===t.config.scope,`bundle merge: scope mismatch ('${this.config.scope}' vs '${t.config.scope}')`),new e({config:{scope:this.config.scope},entries:new Set([...this.entries,...t.entries]),modules:yt(this.modules,t.modules,`bundle merge`),formats:mt(this.formats,t.formats,`bundle merge`),imports:ft(this.imports,t.imports,`bundle merge`),executable:ht(this.executable,t.executable,t.modules,this.config.scope),reason:P(this.reason,t.reason),repo:jt(this.repo,t.repo),package:Pt(this.package,t.package)})}},Ft={__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`,py:`python`,pyw:`python`,pyi:`python`,java:`java`,cpp:`cpp`,cc:`cpp`,cxx:`cpp`,"c++":`cpp`,hpp:`cpp`,hh:`cpp`,hxx:`cpp`,"h++":`cpp`,h:`cpp`,c:`c`,m:`objectivec`,mm:`objectivec`},It={__proto__:null,module:`javascript`,commonjs:`javascript`,"module-typescript":`typescript`,"commonjs-typescript":`typescript`,json:`json`,solidity:`solidity`,php:`php`,shell:`bash`,rust:`rust`,java:`java`,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 Lt(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 Rt(e,t,n){if(typeof t==`string`&&It[t])return It[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`?Lt(n)?`json`:null:Ft[a]??null}var zt=/^webpack(?:-internal)?:\/\/[^/]*\//u,Bt=/^[a-z][\d+.a-z-]*:/iu,Vt=/^file:/iu,Ht=/^(?:file|ftp|https?|wss?):/iu,Ut=/^(?:[a-z][\d+.a-z-]*:\/\/[^/]*\/?|\/\/[^/]+\/|[a-z]:\/|\/)?/iu,I=e=>Ut.exec(e)[0],L=e=>I(e).includes(`://`),R=e=>e.replace(L(e)?/[#?].*$/su:/\?.*$/su,``),Wt=e=>e.slice(e.lastIndexOf(`/`)+1),z=(e,t)=>URL.parse(e,t)?.href??null;function B(e){let t=I(e),n=t.includes(`://`)&&z(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 Gt(e,t){let n=I(t);return L(e)&&!n.includes(`:`)?z(t,e)??B(`${e}/../${t}`):B(n===`/`?I(e).replace(/\/?$/u,``)+t:n?t:`${e}/../${t}`)}function Kt(e){try{return decodeURIComponent(e)}catch{return e}}function V(e,t){let n=e.replaceAll(`\\`,`/`);if(zt.test(n))return B(n.replace(zt,``));let r=Ht.test(n)?z(n)??n:n,i=/^file:\/\/([^/#]*)([^#]*)/isu.exec(r);if(i){let[,e,t]=i;return B(Kt(e&&e.toLowerCase()!==`localhost`?`//${e}${t}`:t).replace(/^\/(?=[a-z]:\/)/iu,``))}if(Bt.test(r)&&!I(r).includes(`:`))return r;if(t===void 0)return B(r);if(Vt.test(t)&&!I(r))return V(z(r,t)??r);let a=V(t);return I(r)&&!L(a)?B(r):Gt(a,r)}var qt=/^(?:@[\dA-Za-z~-][\w.~-]*\/)?[\dA-Za-z~-][\w.~-]*$/u;function Jt(e){let t=e.split(`/`).slice(0,e.startsWith(`@`)?2:1).join(`/`);return qt.test(t)?t:null}var Yt=new Set([`.pnpm`,`.bun`,`.deno`]),Xt=/^\d+\.\d+\.\d+(?:-[\d.a-z-]+)?(?:\+[\d.a-z-]+)?$/iu;function Zt(e,t){let n=`${t.replace(`/`,`+`)}@`,r=e.startsWith(n)?e.slice(n.length).split(/[(_]/u)[0]:null;return Xt.test(r)?r:null}function Qt(e){let t=R(e).split(`/`),n=t.lastIndexOf(`node_modules`),r=n<0?null:Jt(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:Yt.has(t[n-2])?Zt(t[n-1],r):null,root:a,path:e.slice(a.length+1)}}var $t=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 en(e){let t=Wt(R(e));return/^[\w-]+$/u.test(t)?`jsx`:$t.get(/\.([\da-z]+)$/iu.exec(t)?.[1].toLowerCase())??null}var tn=[`.js`,`.mjs`,`.cjs`,`.jsx`,`.ts`,`.tsx`,`.mts`,`.cts`,`.json`],nn=[`.ios`,`.android`,`.web`];function rn(e){let t=e.map(e=>/\.[a-z]+(?=\.\w+$)/u.exec(Wt(R(e.path??``)))?.[0]),[[n,r],[,i]]=nn.map(e=>[e,t.filter(t=>t===e).length]).toSorted((e,t)=>t[1]-e[1]);return[...r===i?[]:[n],`.native`,``,`.browser`,`.node`]}var an=new Map([[`.js`,[`.ts`,`.tsx`]],[`.jsx`,[`.tsx`]],[`.mjs`,[`.mts`]],[`.cjs`,[`.cts`]]]),on=[`index`,`main`,`browser`,`node`],sn=[``,`src/`,`lib/`,`dist/`,`build/`],cn=new Set([`lib`,`dist`,`build`,`out`,`esm`,`cjs`]);function*ln(e,t){yield e;let n=/\.[^./]+$/u.exec(e)?.[0];for(let t of an.get(n)??[])yield e.slice(0,-n.length)+t;for(let n of e.endsWith(`/`)?[`${e}index`]:[e,`${e}/index`])for(let e of tn)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*un(e){let t=e;for(;;){t.startsWith(`src/`)||(yield`src/${t}`),t!==e&&(yield t);let n=t.indexOf(`/`);if(n<0||!cn.has(t.slice(0,n)))return;t=t.slice(n+1)}}function dn(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:rn(e),found:new Map}}function H(e,t){if(!e.found.has(t)){let n=R(t),r=ln(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 fn(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 pn=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 mn(e){if(e.startsWith(`node:`)||pn.has(e))return{builtin:!0};let t=Jt(R(e));return t===null?{}:{package:t}}function hn(){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 gn(e,t){for(let n of on)for(let r of sn){let i=H(e,`${t}/${r}${n}`);if(i)return i}let n=e.byRoot.get(t);return n?.length===1?n[0]:null}function _n(e,t,n,r){return/^\/[^?]/u.test(n)?H(e,t+n)??un(n.slice(1)).map(n=>H(e,`${t}/${n}`)).find(Boolean):H(e,t+n)??r(e,t)}function vn(e,t,n,r=gn){let i=/^(?:\.{1,2}|[a-z]:)?\\/iu.test(n)?n.replaceAll(`\\`,`/`):n,a=Ht.test(i);if(a||/^(?:\.{1,2}(?:\/|$)|\/|[a-z]:\/)/iu.test(i)||L(i)){let n=a?V(i):Gt(t.path,i),r=H(e,n);return r?{to:r}:{to:null,path:n}}if(Bt.test(i)&&e.byPath.has(i))return{to:e.byPath.get(i)};let o=Jt(R(n)),s=o===null?null:fn(e,t,o);if(s===null)return{to:null,...mn(n)};let c=_n(e,s,n.slice(o.length),r);return c?{to:c}:{to:null,package:o}}var U=class extends Error{name=`SourceMapError`},yn=new Uint8Array(128).fill(255);for(let[e,t]of[...`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/,;`].entries())yn[t.codePointAt(0)]=e;function bn(e){let t=new Int32Array(e.length*2);return t.set(e),t}function xn(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 Sn(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 U(`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?yn[o.codePointAt(c)]??255:64;if(l<32){if(p+=l*m,f===5)throw new U(`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 U(`mappings: a value at ${c} runs past 32 bits`)}else{if(l===255)throw new U(`mappings: ${JSON.stringify(o[c])} at ${c} is not a base64 digit`);if(m!==1)throw new U(`mappings: the value before ${c} is cut off`);if(f>0){if(f===2||f===3)throw new U(`mappings: a segment of ${f} fields before ${c}`);let t=f===1?-1:s[e[1]];if(t===void 0)throw new U(`mappings: source ${e[1]} before ${c} is not in sources`);if(e[0]<0)throw new U(`mappings: a negative generated column before ${c}`);a===n.length&&([n,r,i]=[bn(n),bn(r),bn(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),xn({starts:Int32Array.from(t),columns:n.slice(0,a),sources:r.slice(0,a),names:i.slice(0,a)})}var Cn=new WeakMap,wn=e=>Cn.get(e),W=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function G(e,t){if(!e)throw new U(t)}function Tn(e,t){if(e===void 0)return[];G(Array.isArray(e),`${t} is not an array`);for(let n of e)G(typeof n==`string`||n===null,`${t} holds ${JSON.stringify(n)}`);return e}function En(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:V(t,e.mapPath);return e.files.push({source:t,path:a,package:a===null?null:Qt(a),content:n,ignored:r}),t!==null&&e.bySource.set(t,e.files.length-1),e.files.length-1}function Dn(e,t,n,r){G(e.version===3,`version ${JSON.stringify(e.version)} is not 3`),G(e.sourceRoot===void 0||typeof e.sourceRoot==`string`,`sourceRoot is not a string`);let i=Tn(e.sources,`sources`),a=Tn(e.sourcesContent,`sourcesContent`),o=e.ignoreList??e.x_google_ignoreList??[];G(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)=>En(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 On(e,t){G(e.version===3,`version ${JSON.stringify(e.version)} is not 3`),G(Array.isArray(e.sections),`sections is not an array`);for(let[n,r]of e.sections.entries()){let{offset:i,map:a}=W(r)?r:{};G(W(i)&&[i.line,i.column].every(e=>Number.isInteger(e)&&e>=0),`sections[${n}].offset is not a line and a column`),G(W(a)&&a.sections===void 0,`sections[${n}].map is not a plain source map`);let o=e.sections[n-1]?.offset;G(!o||o.line<i.line||o.line===i.line&&o.column<=i.column,`sections[${n}] starts before sections[${n-1}]`),Dn(a,t,i.line,i.column)}}function kn(e,t={}){if(!W(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 U(`not JSON: ${e.message}`,{cause:e})}G(W(n),`not a JSON object`);let r={files:[],bySource:new Map,mapPath:t.path,parts:[],names:[]};n.sections===void 0?Dn(n,r,0,0):On(n,r);let i={files:r.files};return Cn.set(i,{...Sn(r.parts),nameList:r.names}),i}var An=/\r\n?|[\n\u2028\u2029]/gu;function jn(e){let t=[0];for(let n of e.matchAll(An))t.push(n.index+n[0].length);return t}function Mn(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 K(e,t){let n=Mn(e,0,e.length,t);return[n,t-e[n]]}function Nn(e,[t,n]){if(t>=e.starts.length-1)return-1;let r=e.starts[t],i=Mn(e.columns,r,e.starts[t+1],n);return i<r?-1:i}function Pn(e,t,n,r){let i=wn(e),a=K(t,n),[o,s]=K(t,r),c=new Map,l=Nn(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 q=/\s+/uy,Fn=`
8
- \r\u2028\u2029`,J=/[\n\r\u2028\u2029]/gu,In=/[\n\r\u2028\u2029]/u,Y=/[\w$\u0080-￿]+/uy,Ln=new Set([`return`,`typeof`,`instanceof`,`in`,`of`,`new`,`delete`,`void`,`throw`,`case`,`default`,`extends`,`do`,`else`,`yield`,`await`]),Rn=new Set([`if`,`while`,`for`,`with`]),zn=new Set([`break`,`continue`,`debugger`]),Bn=new Set([`(`,`[`,"${",`,`,`=`,`:`,`?`,`!`,`~`,`+`,`-`,`*`,`/`,`%`,`&`,`|`,`^`,`<`,`>`]);function Vn(e,t){return e?.type===`word`?t&&[`return`,`yield`].includes(e.value)?!1:Ln.has(e.value)&&![`do`,`else`].includes(e.value):Bn.has(e?.value)}function Hn(e){let t=e.at(-1);return t?.type===`word`&&(Rn.has(t.value)||t.value===`await`&&e.at(-2)?.value===`for`)}function Un(e){return e?e.type===`word`?Ln.has(e.value)||zn.has(e.value)||e.label===!0:e.value===`)`?e.control:e.value===`}`?!e.object:e.type===`punctuator`&&![`++`,`--`,`]`].includes(e.value):!0}var Wn=(e,t)=>e.startsWith(`\r
9
- `,t+1)?3:2,Gn=/\\(?: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,Kn={b:`\b`,f:`\f`,n:`
10
- `,r:`\r`,t:` `,v:`\v`};function qn(e){return e.includes(`\\`)?e.replace(Gn,(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)?Kn[o]??o:String.fromCodePoint(Math.min(s,1114111))}):e}function Jn(e,t){let n=e[t],r=t+1;for(;r<e.length&&e[r]!==n&&!Fn.includes(e[r]);)r+=e[r]===`\\`?Wn(e,r):1;return[e[r]===n?qn(e.slice(t+1,r)):null,r+1]}function Yn(e,t){let n=t+1,r=!1;for(;n<e.length&&!Fn.includes(e[n])&&(r||e[n]!==`/`);)e[n]===`\\`?n++:e[n]===`[`?r=!0:e[n]===`]`&&(r=!1),n++;return Y.lastIndex=n+1,Y.test(e)?Y.lastIndex:n+1}function Xn(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 Zn(e){let t=[],n=[],r=[],i=0,a=0;for(;i<e.length;){let o=t.length;if(q.lastIndex=i,q.test(e)&&(i=q.lastIndex),i>=e.length)break;let s=e[i],c=e[i+1];if(Y.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]=Jn(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=Xn(e,i+1,n),o=s==="`"&&n.length===r&&e[a-1]==="`";t.push({type:`string`,value:o?qn(e.slice(i+1,a-1)):null}),n.length>r&&t.push({type:`punctuator`,value:"${"}),i=a}else if(s===`/`&&Un(t.at(-1)))i=Yn(e,i),t.push({type:`regex`});else if(Y.test(e)){let n=zn.has(t.at(-1)?.value)&&!In.test(e.slice(a,i));t.push({type:`word`,value:e.slice(i,Y.lastIndex),...n&&{label:n}}),i=Y.lastIndex}else{s===`{`&&n.push(Vn(t.at(-1),In.test(e.slice(a,i)))?`object`:`block`);let o=s===`}`?n.pop():void 0;s===`(`&&r.push(Hn(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 Qn=e=>e?.type===`string`&&e.value!==null,$n=new Set([`type`,`typeof`]),er=(e,t)=>e[t+1]?.type===`word`&&(e[t+1].value!==`as`||e[t+2]?.type!==`word`||e[t+2].value===`as`);function tr(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(!$n.has(e[r].value)||!er(e,r))return!1;n=!0}return n}function nr(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`&&Qn(e[n+1]))return e[n+1].value}return null}function rr(e,t){let[n,r,i]=[e[t].value,e[t+1],e[t+2]],a=n===`import`?`import`:`export-from`;if(n===`import`&&Qn(r))return{kind:a,specifier:r.value};if($n.has(r?.value)&&![`,`,`from`].includes(i?.value)||r?.value===`{`&&tr(e,t+1)||n===`export`&&![`{`,`*`].includes(r?.value)||n===`import`&&r?.type!==`word`&&![`{`,`*`].includes(r?.value))return null;let o=nr(e,t+1);return o===null?null:{kind:a,specifier:o}}function ir(e,t){let[n,r]=[e[t+2],e[t+3]];if(n?.value!==`)`)return Qn(n)&&[`)`,`,`].includes(r?.value)?n.value:null}function ar(e,t=new Set){let n=Zn(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?ir(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=rr(n,e);t&&r.push(t)}}return r}var or=/^[\w$]*__d\(/gmu,sr=([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 cr(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(!sr(i))break;n=i,r=r>0?e.lastIndexOf(`},`,r-1):-1}return n}function lr(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 ur(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:lr(t)}function dr(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 fr(e,t){let n=[...e.matchAll(or)].map(e=>e.index);if(n.length===0)return null;let r=jn(e),i=t=>e.slice(r[t],r[t+1]),a=[];for(let[o,s]of n.entries()){let[c]=K(r,s),[l]=K(r,(n[o+1]??e.length)-1),u=cr(i(l));for(;!u&&l>c;)u=cr(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:Pn(t,r,s,d),dependencies:ur(u[1],e.slice(s,d))})}dr(a,t);let o=new Map(a.map(e=>[e.id,e])),{edges:s,link:c}=hn();for(let{file:e,dependencies:t}of a)for(let n of t)c(e,o.get(n)?.file,`dependency`);return s}var pr=e=>e.path!==null&&![`json`,null].includes(en(e.path)),mr=e=>e.path!==null&&en(e.path)===null;function hr(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 gr={jsxRuntime:`react/jsx-runtime`,jsxDevRuntime:`react/jsx-dev-runtime`};function _r(e){let{sources:t,names:n,nameList:r}=wn(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],hr(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(hr);o.length>0&&i.set(r,o.map(e=>gr[e]??`@babel/runtime/helpers/${e}`))}return i}function vr(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,vn(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:vn(t,e,r,i)}}var yr=e=>/(?:^|\/)__prelude__$/u.test(e.source??``),br=e=>e?.package?.name===`metro-runtime`&&e.package.path===`src/polyfills/require.js`;function xr(e){if(!e.files.some(yr)&&!br(e.files[0]))return null;if(!e.files.some(e=>e.content!==null&&!yr(e)&&!br(e)))throw Error("bundleEdges: the Metro map carries no sourcesContent, which its edges are read from; pass the bundle as `code`");let t=dn(e.files),n=e.files[e.files.findIndex(mr)+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&&pr(e)).map(e=>[e,ar(e.content)])),a=_r(e),o=vr([...[...i].map(([e,t])=>[e,t.flatMap(({specifier:e})=>e===null?[]:[e])]),...a],t),{edges:s,add:c,link:l}=hn();for(let t of e.files){mr(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 Sr=(e,t)=>t==null?xr(e):fr(t,e);function Cr(e,t){let n=Sr(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 wr(e){let t=JSON.parse(e.replace(/^\)\]\}'[^\n]*\n/u,``)),n=kn(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 Tr(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 Er(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 Dr(e){try{return Cr(e)}catch{return{edges:[]}}}var Or=Object.freeze([]);function X(e){return e?.edges?e.edges:e?.map?(e.edges=Er(e.map,Dr),e.edges):Or}var kr=new WeakMap,Ar=new WeakMap;function jr(e){let t=X(e);if(!kr.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);kr.set(t,e)}return kr.get(t)}function Mr(e){let t=X(e);if(!Ar.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));Ar.set(t,e)}return Ar.get(t)}var Nr=new WeakMap,Pr=new WeakMap,Fr=new WeakMap,Ir=new WeakMap,Lr=new WeakMap,Rr=new WeakMap;function Z(e){if(e?.metadataOnly)return new Map;let t=e?.bundle??e?.json;if(t&&Nr.has(t))return Nr.get(t);let n=new Map;if(!e)return n;if(e.kind===`stasis`){if(!e.bundle)return n;let t=e.bundle.formats;for(let[r,i]of e.bundle.sources)typeof i==`string`&&(F.isResourceFormat(t?.get(r))||n.set(r,i))}else if(e.kind===`sourcemap`)for(let[t,r]of Tr(e))typeof r==`string`&&n.set(t,r);return t&&Nr.set(t,n),n}function zr(e){let t=1;for(let n=e.indexOf(`
11
- `);n!==-1;n=e.indexOf(`
12
- `,n+1))t++;return t}var Br=new WeakMap;function Vr(e){let t=Br.get(e);if(!t){let n=[...e.keys()].toSorted();t={paths:n,numbers:new Map(n.map((e,t)=>[e,t+1]))},Br.set(e,t)}return t}function Hr(e,t){let n=Array.isArray(t)?t:[];return{integrity:e.integrity,kind:`sourcemap`,size:e.size,json:{version:3,sources:n.map(([e])=>e),sourcesContent:n.map(([,,e])=>typeof e==`string`?e:null)},fileSizes:new Map(n.map(([e,t])=>[e,t])),npmBinaries:new Map(n.filter(([,,e,t])=>typeof e!=`string`&&typeof t==`string`).map(([e,t,,n])=>[e,{size:t,digest:n}]))}}function Ur(e){let t=e?.bundle??e?.json;if(t&&Pr.has(t))return Pr.get(t);let n=new Map(Z(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&&Pr.set(t,n),n}var Wr=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`;function Gr(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&&Wr.indexOf(n.at(-1))&(r===2?15:3)?null:Math.floor(n.length*3/4)}function Kr(e){return typeof e==`string`?t(e):e?.format===`digest`?e.size:e?.format===`base64`?Gr(e.data):null}function Q(e){if(e?.fileSizes)return e.fileSizes;let t=e?.bundle??e?.json;if(t&&Fr.has(t))return Fr.get(t);let n=new Map,r=Ur(e),i=e?.kind===`stasis`?e.bundle?.sources.keys():e&&Tr(e).map(([e])=>e);for(let e of i??[])n.set(e,Kr(r.get(e)));return t&&Fr.set(t,n),n}function qr(e){if(e?.metadataOnly)return e.unsizedFiles??new Set;let t=Q(e);if(Rr.has(t))return Rr.get(t);let n=new Set;for(let r of Ur(e).keys())t.get(r)===null&&n.add(r);return Rr.set(t,n),n}function Jr(e){let t=Q(e);if(Lr.has(t))return Lr.get(t);let n=qr(e),r=e?.kind===`stasis`?e.bundle?.formats:null,i=new Map;for(let[a,o]of t)o===null&&!n.has(a)||i.set(a,F.isResourceFormat(r?.get(a))||e?.npmBinaries?.has(a)?`resource`:`source`);return Lr.set(t,i),i}function Yr(e){let t=Q(e),n=e?.kind===`stasis`?e.bundle?.formats:null;if(!n||n.size===0)return t;if(Ir.has(t))return Ir.get(t);let r=new Map;for(let[e,i]of t)F.isResourceFormat(n.get(e))||r.set(e,i);return Ir.set(t,r),r}var Xr=new WeakMap;function Zr(e){if(e?.kind!==`stasis`||!e.bundle?.modules)return null;if(Xr.has(e.bundle))return Xr.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 Xr.set(e.bundle,t),t}function Qr(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:Zr(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 $r=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`}),ei=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 ti(e){let t=typeof e==`string`?e.slice(e.lastIndexOf(`/`)+1):``,n=t.lastIndexOf(`.`),r=n>0?t.slice(n+1).trim().toLowerCase():``,i=Rt(e)??ei[r];return i?{key:i,label:$r[i]??i}:r?{key:`extension:${r}`,label:`.${r}`}:{key:`other`,label:`Other`}}function ni(e,t){let n=new Map,r=0,i=0;for(let[a,o]of e){let e=ti(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 ri=6,$=new WeakMap,ii=new Set([`terminal`,`code`,`search`,`compare`]);function ai(e,t=null){return!!t||ii.has(e)}var oi=/^sha512-[A-Za-z0-9+/]{86}==$/u;function si(t){if(t.fileHashes)return Promise.resolve(t.fileHashes);if($.has(t))return $.get(t);let n=(async()=>{let n=[...Z(t)],r=new Map;for(let t=0;t<n.length;t+=32){let i=await Promise.all(n.slice(t,t+32).map(async([t,n])=>[t,await e(n)]));for(let[e,t]of i)r.set(e,t)}return t.fileHashes=r,r})();return $.set(t,n),n.catch(()=>$.delete(t)),n}function ci(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 li(e){return e.lineCounts??=new Map([...Z(e)].map(([e,t])=>[e,ci(t)]))}function ui(e){return e instanceof Map?Object.fromEntries([...e].map(([e,t])=>[e,ui(t)])):e}async function di(e){let n=await si(e),r=Q(e),i=li(e),a={version:ri,integrity:e.integrity,kind:e.kind,size:e.size,codeStats:ni(i,r),files:[...r].map(([e,t])=>[e,t,n.get(e)??null,i.get(e)??null])},o=qr(e);if(o.size>0&&(a.unsized=[...o]),e.kind===`sourcemap`){let{version:n,file:r,sourceRoot:i,names:o}=e.json,s=Tr(e);a.json={version:n,file:r,sourceRoot:i,sources:s.map(([e])=>e)},a.sourceSizes=s.map(([,e])=>typeof e==`string`?t(e):null),a.namesCount=e.namesCount??o?.length??null;let c=new Map(a.files.map(([e],t)=>[e,t]));a.edges=X(e).map(([e,t,...n])=>[c.get(e),c.get(t),...n])}else{let t=e.bundle,n={version:t.version,config:t.config,repo:t.repo,package:t.package,formats:ui(t.formats),imports:ui(t.imports),reason:t.reason,executable:[...t.executable]};if(t.version===0)n.sources=Object.fromEntries([...r.keys()].map(e=>[e,null]));else{let e={},r={};for(let[n,i]of t.modules){let t=n.split(`/`).includes(`node_modules`)?e:r;Object.defineProperty(t,n,{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]))}})}n.modules=e,t.config.scope===`full`&&(n.sources=r,n.entries=[...t.entries])}a.bundle=n}return a}function fi(e,t){if(![1,2,3,4,5,ri].includes(e?.version)||e.integrity!==t||![`stasis`,`sourcemap`].includes(e.kind)||!Number.isSafeInteger(e.size)||e.size<0||!Array.isArray(e.files))throw Error(`Invalid bundle metadata`);let n=e.version!==ri,r=e.version===1,i=new Map,a=new Map,o=new Map;for(let t of e.files){if(!Array.isArray(t)||t.length!==4&&!(r&&t.length===3))throw Error(`Invalid bundle metadata file`);let[e,n,s,c]=t;if(typeof e!=`string`||a.has(e)||n!==null&&(!Number.isSafeInteger(n)||n<0)||s!==null&&(typeof s!=`string`||!oi.test(s))||n===null&&s!==null||r&&n!==null&&s===null||c!=null&&(!Number.isSafeInteger(c)||c<0))throw Error(`Invalid bundle metadata file`);a.set(e,n),s!==null&&i.set(e,s),c!=null&&o.set(e,c)}let s=new Set(e.unsized??[]);if(e.unsized!==void 0&&(r||!Array.isArray(e.unsized)||s.size!==e.unsized.length)||[...s].some(e=>typeof e!=`string`||!a.has(e)||a.get(e)!==null))throw Error(`Invalid bundle metadata`);let c={integrity:t,kind:e.kind,size:e.size,metadataOnly:!0,fileSizes:a,fileHashes:i,lineCounts:o,unsizedFiles:s,stale:n};if(e.kind===`stasis`){c.bundle=F.fromJSON(e.bundle);let t=c.bundle.sources;if(t.size!==a.size||[...t.keys()].some(e=>!a.has(e)))throw Error(`Invalid bundle metadata inventory`);let n=c.bundle.formats;if(!r&&[...a].some(([e,t])=>i.has(e)!==(t!==null&&!F.isResourceFormat(n.get(e))))||[...s].some(e=>n.get(e)!==`resource:base64`))throw Error(`Invalid bundle metadata inventory`)}else{if(!e.json||typeof e.json!=`object`||![null,void 0].includes(e.namesCount)&&(!Number.isSafeInteger(e.namesCount)||e.namesCount<0))throw Error(`Invalid sourcemap metadata`);if(!Array.isArray(e.json.sources)||e.json.sources.some(e=>!a.has(e))||!Array.isArray(e.sourceSizes)||e.sourceSizes.length!==e.json.sources.length||e.sourceSizes.some(e=>e!==null&&(!Number.isSafeInteger(e)||e<0))||[...a].some(([e,t])=>i.has(e)!==(t!==null))||s.size>0)throw Error(`Invalid sourcemap inventory`);c.json=e.json,c.sourceSizes=e.sourceSizes,c.namesCount=e.namesCount,e.edges!==void 0&&(c.edges=pi(e.edges,e.files))}if(e.codeStats===void 0)c.codeStats=ni(o,a);else{let t=e.codeStats,n=e=>Number.isSafeInteger(e)&&e>=0;if(!t||![t.files,t.lines,t.bytes].every(n)||!Array.isArray(t.languages)||t.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`);c.codeStats=t}return c}function pi(e,t){if(!Array.isArray(e))throw Error(`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 mi(e,{integrity:t,kind:n,size:r}){if(n===`stasis`)return{integrity:t,kind:n,size:r,bundle:F.parse(e)};if(n!==`sourcemap`)throw Error(`Unsupported bundle format`);return{integrity:t,kind:n,size:r,...wr(e)}}export{At as a,F as b,Rt as c,X as d,jr as e,Mr as f,Z as g,zr as h,Vr as i,Hr as j,Ur as k,Kr as l,Q as m,Jr as n,Yr as o,Zr as p,Qr as q,ni as r,ai as s,si as t,ci as u,li as v,di as w,fi as x,mi as y};