private async processPackageVersion()

in src/commands/repair-package-data.ts [271:313]


  private async processPackageVersion(S3: S3Client, bucketName: string, prefix: string): Promise<PackageVersionStatus> {
    const [, name, version] = /^data\/((?:@[^/]+\/)?[^/]+)\/v([^/]+)\/$/.exec(prefix)!;
    const result = {
      name,
      version,
      assemblyKey: undefined as string | undefined,
      metadataKey: undefined as string | undefined,
      tarballKey: undefined as string | undefined,
      docs: new Map<string, DocStatus>(),
      submodules: new Map<string, Map<string, DocStatus>>(),
    };

    for await (const { Contents: objects } of paginateListObjectsV2({ client: S3 }, { Bucket: bucketName, Prefix: prefix })) {
      if (!objects) { continue; }
      let matches: RegExpMatchArray | null = null;
      for (const { Key: key } of objects) {
        if (!key) { continue; }
        if (key.endsWith('/assembly.json')) {
          result.assemblyKey = key;
        } else if (key.endsWith('/metadata.json')) {
          result.metadataKey = key;
        } else if (key.endsWith('/package.tgz')) {
          result.tarballKey = key;
        } else if ((matches = /^.*\/docs-([^-]+-)?([a-z]+)\.md(\.not-supported)?$/.exec(key)) != null) {
          const [, submodule, lang, unsupported] = matches;
          const status = unsupported ? DocStatus.UNSUPPORTED : DocStatus.PRESENT;
          if (submodule) {
            if (!result.submodules.has(submodule)) {
              result.submodules.set(submodule, new Map());
            }
            result.submodules.get(submodule)!.set(lang, status);
          } else {
            result.docs.set(lang, status);
          }
        } else {
          console.error(`Unexpected key could not be attributed to any document category: ${key}`);
          process.exit(-1);
        }
      }
    }

    return result;
  }