@powerhousedao/registry 6.2.3-dev.37 → 6.2.3-dev.39

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/dist/cli.mjs CHANGED
@@ -2946,6 +2946,12 @@ async function indexedRevision(db, pkg) {
2946
2946
  }
2947
2947
  return (await db.query("SELECT rev FROM verdaccio_manifests WHERE name = $1", [pkg])).rows[0]?.rev ?? null;
2948
2948
  }
2949
+ async function publishedHere(db, pkg) {
2950
+ if (!(await db.query("SELECT to_regclass('verdaccio_packages') IS NOT NULL AS exists")).rows[0]?.exists) return null;
2951
+ return (await db.query(`SELECT EXISTS (SELECT 1 FROM verdaccio_packages WHERE name = $1)
2952
+ OR EXISTS (SELECT 1 FROM registry_package_owners WHERE package_name = $1)
2953
+ AS published`, [pkg])).rows[0]?.published === true;
2954
+ }
2949
2955
  async function upsertPackage(tx, pkg, packument, local, manifestRev) {
2950
2956
  const versions = Object.keys(packument.versions ?? {}).sort(compareSemver);
2951
2957
  const times = {};
@@ -3030,7 +3036,7 @@ function publisherOf$1(job) {
3030
3036
  async function processVersion(ctx, job, finish) {
3031
3037
  const pkg = job.package;
3032
3038
  const version = job.version;
3033
- const local = job.payload.local === true;
3039
+ const local = await publishedHere(ctx.db, pkg) ?? job.payload.local === true;
3034
3040
  const manifestRev = await indexedRevision(ctx.db, pkg);
3035
3041
  const packument = await fetchPackument(ctx.registryUrl, pkg);
3036
3042
  if (!packument?.versions?.[version]) {
@@ -3115,15 +3121,22 @@ async function syncPackage(ctx, job, finish) {
3115
3121
  const known = await ctx.db.query("SELECT version FROM registry_versions WHERE package = $1", [pkg]);
3116
3122
  const listed = new Set(Object.keys(packument?.versions ?? {}));
3117
3123
  const removed = known.rows.map((r) => r.version).filter((v) => !listed.has(v));
3124
+ const published = await publishedHere(ctx.db, pkg);
3125
+ const local = published ?? job.payload.local === true;
3126
+ if (!packument && published) throw new Error(`metadata for published ${pkg} returned 404`);
3118
3127
  await ctx.db.transaction(async (tx) => {
3119
3128
  await removeVersionRows(tx, pkg, removed);
3120
3129
  if (!packument) await tx.query("DELETE FROM registry_packages WHERE name = $1", [pkg]);
3121
3130
  else {
3122
- await upsertPackage(tx, pkg, packument, job.payload.local === true, manifestRev);
3131
+ await upsertPackage(tx, pkg, packument, local, manifestRev);
3123
3132
  await recomputeLatest(tx, pkg);
3124
- if ((await tx.query("SELECT local FROM registry_packages WHERE name = $1", [pkg])).rows[0]?.local) {
3133
+ if (local) {
3125
3134
  const have = new Set(known.rows.map((r) => r.version));
3126
- for (const version of listed) if (!have.has(version)) await enqueue(tx, "process", pkg, version, { local: true }, job.priority);
3135
+ const tagged = new Set(Object.values(packument["dist-tags"] ?? {}));
3136
+ for (const version of tagged) {
3137
+ if (!listed.has(version)) continue;
3138
+ if (!have.has(version)) await enqueue(tx, "process", pkg, version, { local: true }, job.priority);
3139
+ }
3127
3140
  }
3128
3141
  }
3129
3142
  await finish(tx);
@@ -4840,9 +4853,9 @@ const QUICK_MISSING = `
4840
4853
  AND j.version = r.version)
4841
4854
  LIMIT 1000`;
4842
4855
  const FULL_MISSING = `
4843
- SELECT m.name, v.version
4856
+ SELECT DISTINCT m.name, v.version
4844
4857
  FROM verdaccio_manifests m
4845
- CROSS JOIN LATERAL jsonb_array_elements_text(m.versions) AS v(version)
4858
+ CROSS JOIN LATERAL jsonb_each_text(m.dist_tags) AS v(tag, version)
4846
4859
  LEFT JOIN registry_versions r ON r.package = m.name AND r.version = v.version
4847
4860
  WHERE m.updated_at < now() - interval '30 seconds' AND ${PUBLISHED}
4848
4861
  AND (r.package IS NULL
@@ -4856,7 +4869,7 @@ const FULL_CHANGED = `
4856
4869
  FROM verdaccio_manifests m
4857
4870
  LEFT JOIN registry_packages p ON p.name = m.name
4858
4871
  WHERE m.updated_at < now() - interval '30 seconds' AND ${PUBLISHED}
4859
- AND (p.name IS NULL OR p.dist_tags <> m.dist_tags
4872
+ AND (p.name IS NULL OR NOT p.local OR p.dist_tags <> m.dist_tags
4860
4873
  OR EXISTS (SELECT 1 FROM registry_versions r
4861
4874
  WHERE r.package = m.name AND NOT m.versions ? r.version))
4862
4875
  UNION ${UNPUBLISHED}
@@ -4893,6 +4906,10 @@ function publisherOf(job) {
4893
4906
  }
4894
4907
  async function runJob(ctx, job, options) {
4895
4908
  const finish = (tx) => complete(tx, job);
4909
+ if (job.priority === 10 && await publishedHere(ctx.db, job.package) === false) {
4910
+ await ctx.db.transaction(finish);
4911
+ return;
4912
+ }
4896
4913
  if (job.kind === "process") {
4897
4914
  if (await processVersion(ctx, job, finish) && job.payload.notify === true) await options.webhooks?.notifyPublish({
4898
4915
  packageName: job.package,
@@ -4976,7 +4993,7 @@ async function startWorker(ctx, options) {
4976
4993
  };
4977
4994
  const loops = Array.from({ length: Math.max(1, options.concurrency) }, () => loop());
4978
4995
  let sweeper;
4979
- let lastFull = 0;
4996
+ let lastFull = Date.now() - SWEEP_INTERVAL_MS + RECONCILE_INTERVAL_MS;
4980
4997
  const sweep = async () => {
4981
4998
  try {
4982
4999
  const full = Date.now() - lastFull >= SWEEP_INTERVAL_MS;