@powerhousedao/registry 6.2.3-dev.50 → 6.2.3-dev.52

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
@@ -2993,6 +2993,10 @@ async function publishedHere(db, pkg) {
2993
2993
  OR EXISTS (SELECT 1 FROM registry_package_owners WHERE package_name = $1)
2994
2994
  AS published`, [pkg])).rows[0]?.published === true;
2995
2995
  }
2996
+ async function lockLatestPackument(tx, registryUrl, pkg, fallback) {
2997
+ await tx.query("SELECT pg_advisory_xact_lock(hashtext($1))", [pkg]);
2998
+ return await fetchPackument(registryUrl, pkg) ?? fallback;
2999
+ }
2996
3000
  async function upsertPackage(tx, pkg, packument, local, manifestRev) {
2997
3001
  const versions = Object.keys(packument.versions ?? {}).sort(compareSemver);
2998
3002
  const times = {};
@@ -3094,8 +3098,9 @@ async function processVersion(ctx, job, finish) {
3094
3098
  const unpacked = await unpackVersion(ctx, pkg, version);
3095
3099
  const times = packument.time ?? {};
3096
3100
  const isLocal = await ctx.db.transaction(async (tx) => {
3101
+ const latest = await lockLatestPackument(tx, ctx.registryUrl, pkg, packument);
3097
3102
  await claimPieces(tx, pkg, unpacked.pieces);
3098
- await upsertPackage(tx, pkg, packument, local, manifestRev);
3103
+ await upsertPackage(tx, pkg, latest, local, manifestRev);
3099
3104
  await tx.query("DELETE FROM registry_pieces WHERE package = $1 AND version = $2", [pkg, version]);
3100
3105
  for (const piece of unpacked.pieces) await tx.query(`INSERT INTO registry_pieces
3101
3106
  (name, version, package, display_name, description, descriptor,
@@ -3170,14 +3175,15 @@ async function syncPackage(ctx, job, finish) {
3170
3175
  const local = published ?? job.payload.local === true;
3171
3176
  if (!packument && published) throw new Error(`metadata for published ${pkg} returned 404`);
3172
3177
  await ctx.db.transaction(async (tx) => {
3178
+ const latest = packument ? await lockLatestPackument(tx, ctx.registryUrl, pkg, packument) : null;
3173
3179
  await removeVersionRows(tx, pkg, removed);
3174
- if (!packument) await tx.query("DELETE FROM registry_packages WHERE name = $1", [pkg]);
3180
+ if (!latest) await tx.query("DELETE FROM registry_packages WHERE name = $1", [pkg]);
3175
3181
  else {
3176
- await upsertPackage(tx, pkg, packument, local, manifestRev);
3182
+ await upsertPackage(tx, pkg, latest, local, manifestRev);
3177
3183
  await recomputeLatest(tx, pkg);
3178
3184
  if (local) {
3179
3185
  const have = new Set(known.rows.map((r) => r.version));
3180
- const tagged = new Set(Object.values(packument["dist-tags"] ?? {}));
3186
+ const tagged = new Set(Object.values(latest["dist-tags"] ?? {}));
3181
3187
  for (const version of tagged) {
3182
3188
  if (!listed.has(version)) continue;
3183
3189
  if (!have.has(version)) await enqueue(tx, "process", pkg, version, { local: true }, job.priority);