construct-hub 0.3.337 → 0.3.340

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/.jsii CHANGED
@@ -15450,6 +15450,6 @@
15450
15450
  "symbolId": "src/package-sources/npmjs:NpmJsProps"
15451
15451
  }
15452
15452
  },
15453
- "version": "0.3.337",
15454
- "fingerprint": "GiBg+z52QoKEcOp9tICbMbk1KURmFxGp37AO5v7djfo="
15453
+ "version": "0.3.340",
15454
+ "fingerprint": "S0Q8aQnP/TyHexqnVHykEwOLUKH5iJiWWTDTJwjrQq4="
15455
15455
  }
package/changelog.md CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- ### [0.3.337](https://github.com/cdklabs/construct-hub/compare/v0.3.336...v0.3.337) (2022-05-01)
2
+ ### [0.3.340](https://github.com/cdklabs/construct-hub/compare/v0.3.339...v0.3.340) (2022-05-02)
@@ -9577,9 +9577,14 @@ var require_lib2 = __commonJS({
9577
9577
  // src/backend/inventory/canary.lambda.ts
9578
9578
  var canary_lambda_exports = {};
9579
9579
  __export(canary_lambda_exports, {
9580
- handler: () => handler
9580
+ DocumentationStatus: () => DocumentationStatus,
9581
+ Grain: () => Grain,
9582
+ deserialize: () => deserialize,
9583
+ handler: () => handler,
9584
+ serialize: () => serialize
9581
9585
  });
9582
9586
  module.exports = __toCommonJS(canary_lambda_exports);
9587
+ var import_zlib2 = require("zlib");
9583
9588
  var import_aws_embedded_metrics = __toESM(require_lib());
9584
9589
  var import_semver = __toESM(require_semver2());
9585
9590
 
@@ -9707,83 +9712,140 @@ var LANGUAGE_DIMENSION = "Language";
9707
9712
  import_aws_embedded_metrics.Configuration.namespace = METRICS_NAMESPACE;
9708
9713
  async function handler(event, context) {
9709
9714
  console.log("Event:", JSON.stringify(event, null, 2));
9710
- const indexedPackages = /* @__PURE__ */ new Map();
9711
- const packageNames = /* @__PURE__ */ new Set();
9712
- const packageMajorVersions = /* @__PURE__ */ new Set();
9713
- const perLanguage = /* @__PURE__ */ new Map();
9715
+ const scratchworkBucket = requireEnv("SCRATCHWORK_BUCKET_NAME");
9716
+ const { continuationToken, indexedPackages, packageNames, packageMajorVersions, perLanguage } = event.continuationObjectKey ? await loadProgress(event.continuationObjectKey) : {
9717
+ continuationToken: void 0,
9718
+ indexedPackages: /* @__PURE__ */ new Map(),
9719
+ packageNames: /* @__PURE__ */ new Set(),
9720
+ packageMajorVersions: /* @__PURE__ */ new Set(),
9721
+ perLanguage: /* @__PURE__ */ new Map()
9722
+ };
9723
+ async function loadProgress(continuationObjectKey) {
9724
+ console.log("Found a continuation object key, retrieving data from the existing run...");
9725
+ let { Body, ContentEncoding } = await s3().getObject({
9726
+ Bucket: scratchworkBucket,
9727
+ Key: continuationObjectKey
9728
+ }).promise();
9729
+ if (ContentEncoding === "gzip") {
9730
+ Body = (0, import_zlib2.gunzipSync)(Buffer.from(Body));
9731
+ }
9732
+ if (!Body) {
9733
+ throw new Error(`Object key "${event.continuationObjectKey}" not found in bucket "${scratchworkBucket}".`);
9734
+ }
9735
+ console.log("Deserializing data...");
9736
+ const serializedState = Body.toString("utf-8");
9737
+ const state = deserialize(serializedState);
9738
+ console.log("Deserializing finished.");
9739
+ return state;
9740
+ }
9714
9741
  function recordPerLanguage(language, status, pkgName, pkgMajor, pkgVersion, submodule) {
9715
9742
  for (const lang of DocumentationLanguage.ALL) {
9716
- doRecordPerLanguage(perLanguage, lang, lang === language ? status : PerLanguageStatus.MISSING, pkgName, pkgMajor, pkgVersion, submodule);
9717
- }
9718
- }
9719
- const bucket = requireEnv("BUCKET_NAME");
9720
- for await (const key of relevantObjectKeys(bucket)) {
9721
- const [, name, version] = STORAGE_KEY_FORMAT_REGEX.exec(key);
9722
- packageNames.add(name);
9723
- const majorVersion = `${name}@${new import_semver.SemVer(version).major}`;
9724
- packageMajorVersions.add(majorVersion);
9725
- const fullName = `${name}@${version}`;
9726
- for (const language of DocumentationLanguage.ALL) {
9727
- recordPerLanguage(language, PerLanguageStatus.MISSING, name, majorVersion, fullName);
9728
- }
9729
- if (!indexedPackages.has(fullName)) {
9730
- indexedPackages.set(fullName, {});
9731
- }
9732
- const status = indexedPackages.get(fullName);
9733
- if (key.endsWith(METADATA_KEY_SUFFIX)) {
9734
- status.metadataPresent = true;
9735
- } else if (key.endsWith(PACKAGE_KEY_SUFFIX)) {
9736
- status.tarballPresent = true;
9737
- } else if (key.endsWith(ASSEMBLY_KEY_SUFFIX)) {
9738
- status.assemblyPresent = true;
9739
- } else if (key.endsWith(UNINSTALLABLE_PACKAGE_SUFFIX)) {
9740
- status.uninstallable = true;
9741
- } else {
9742
- let identified = false;
9743
+ doRecordPerLanguage(perLanguage, lang, lang === language ? status : DocumentationStatus.MISSING, pkgName, pkgMajor, pkgVersion, submodule);
9744
+ }
9745
+ }
9746
+ async function saveProgress(latestContinuationToken) {
9747
+ console.log("Serializing data...");
9748
+ const serializedState = serialize({
9749
+ continuationToken: latestContinuationToken,
9750
+ packageNames,
9751
+ packageMajorVersions,
9752
+ indexedPackages,
9753
+ perLanguage
9754
+ });
9755
+ console.log("Serializing finished.");
9756
+ const { buffer, contentEncoding } = compressContent(Buffer.from(serializedState));
9757
+ const keyName = `inventory-canary-progress-${Date.now()}`;
9758
+ await s3().putObject({
9759
+ Bucket: scratchworkBucket,
9760
+ Key: keyName,
9761
+ Body: buffer,
9762
+ ContentType: "application/json",
9763
+ ContentEncoding: contentEncoding,
9764
+ Metadata: {
9765
+ "Lambda-Log-Group": context.logGroupName,
9766
+ "Lambda-Log-Stream": context.logStreamName,
9767
+ "Lambda-Run-Id": context.awsRequestId
9768
+ }
9769
+ }).promise();
9770
+ return {
9771
+ continuationObjectKey: keyName
9772
+ };
9773
+ }
9774
+ const maxMetricProcessingTime = 6e4;
9775
+ const packageDataBucket = requireEnv("PACKAGE_DATA_BUCKET_NAME");
9776
+ for await (const [keys, latestContinuationToken] of relevantObjectKeys(packageDataBucket, continuationToken)) {
9777
+ for (const key of keys) {
9778
+ const [, name, version] = STORAGE_KEY_FORMAT_REGEX.exec(key);
9779
+ packageNames.add(name);
9780
+ const majorVersion = `${name}@${new import_semver.SemVer(version).major}`;
9781
+ packageMajorVersions.add(majorVersion);
9782
+ const fullName = `${name}@${version}`;
9743
9783
  for (const language of DocumentationLanguage.ALL) {
9744
- const matchJson = submoduleKeyRegexp(language, "json").exec(key);
9745
- const matchMd = submoduleKeyRegexp(language, "md").exec(key);
9746
- if (matchJson != null) {
9747
- const [, submodule, isUnsupported] = matchJson;
9748
- if (status.submodules == null) {
9749
- status.submodules = /* @__PURE__ */ new Set();
9750
- }
9751
- status.submodules.add(`${fullName}.${submodule}`);
9752
- recordPerLanguage(language, isUnsupported ? PerLanguageStatus.UNSUPPORTED : PerLanguageStatus.SUPPORTED, name, majorVersion, fullName, submodule);
9753
- identified = true;
9754
- } else if (key.endsWith(docsKeySuffix(language, void 0, "json"))) {
9755
- recordPerLanguage(language, PerLanguageStatus.SUPPORTED, name, majorVersion, fullName);
9756
- identified = true;
9757
- } else if (key.endsWith(notSupportedKeySuffix(language, void 0, "json"))) {
9758
- recordPerLanguage(language, PerLanguageStatus.UNSUPPORTED, name, majorVersion, fullName);
9759
- identified = true;
9760
- } else if (key.endsWith(corruptAssemblyKeySuffix(language, void 0, "json"))) {
9761
- recordPerLanguage(language, PerLanguageStatus.CORRUPT_ASSEMBLY, name, majorVersion, fullName);
9762
- identified = true;
9763
- } else if (matchMd != null) {
9764
- identified = true;
9765
- } else if (key.endsWith(docsKeySuffix(language, void 0, "md"))) {
9766
- identified = true;
9767
- } else if (key.endsWith(notSupportedKeySuffix(language, void 0, "md"))) {
9768
- identified = true;
9769
- } else if (key.endsWith(corruptAssemblyKeySuffix(language, void 0, "md"))) {
9770
- identified = true;
9771
- }
9772
- }
9773
- if (!identified) {
9774
- status.unknownObjects = status.unknownObjects ?? [];
9775
- status.unknownObjects.push(key);
9776
- }
9784
+ recordPerLanguage(language, DocumentationStatus.MISSING, name, majorVersion, fullName);
9785
+ }
9786
+ if (!indexedPackages.has(fullName)) {
9787
+ indexedPackages.set(fullName, {});
9788
+ }
9789
+ const status = indexedPackages.get(fullName);
9790
+ if (key.endsWith(METADATA_KEY_SUFFIX)) {
9791
+ status.metadataPresent = true;
9792
+ } else if (key.endsWith(PACKAGE_KEY_SUFFIX)) {
9793
+ status.tarballPresent = true;
9794
+ } else if (key.endsWith(ASSEMBLY_KEY_SUFFIX)) {
9795
+ status.assemblyPresent = true;
9796
+ } else if (key.endsWith(UNINSTALLABLE_PACKAGE_SUFFIX)) {
9797
+ status.uninstallable = true;
9798
+ } else {
9799
+ let identified = false;
9800
+ for (const language of DocumentationLanguage.ALL) {
9801
+ const matchJson = submoduleKeyRegexp(language, "json").exec(key);
9802
+ const matchMd = submoduleKeyRegexp(language, "md").exec(key);
9803
+ if (matchJson != null) {
9804
+ const [, submodule, isUnsupported] = matchJson;
9805
+ if (status.submodules == null) {
9806
+ status.submodules = /* @__PURE__ */ new Set();
9807
+ }
9808
+ status.submodules.add(`${fullName}.${submodule}`);
9809
+ recordPerLanguage(language, isUnsupported ? DocumentationStatus.UNSUPPORTED : DocumentationStatus.SUPPORTED, name, majorVersion, fullName, submodule);
9810
+ identified = true;
9811
+ } else if (key.endsWith(docsKeySuffix(language, void 0, "json"))) {
9812
+ recordPerLanguage(language, DocumentationStatus.SUPPORTED, name, majorVersion, fullName);
9813
+ identified = true;
9814
+ } else if (key.endsWith(notSupportedKeySuffix(language, void 0, "json"))) {
9815
+ recordPerLanguage(language, DocumentationStatus.UNSUPPORTED, name, majorVersion, fullName);
9816
+ identified = true;
9817
+ } else if (key.endsWith(corruptAssemblyKeySuffix(language, void 0, "json"))) {
9818
+ recordPerLanguage(language, DocumentationStatus.CORRUPT_ASSEMBLY, name, majorVersion, fullName);
9819
+ identified = true;
9820
+ } else if (matchMd != null) {
9821
+ identified = true;
9822
+ } else if (key.endsWith(docsKeySuffix(language, void 0, "md"))) {
9823
+ identified = true;
9824
+ } else if (key.endsWith(notSupportedKeySuffix(language, void 0, "md"))) {
9825
+ identified = true;
9826
+ } else if (key.endsWith(corruptAssemblyKeySuffix(language, void 0, "md"))) {
9827
+ identified = true;
9828
+ }
9829
+ }
9830
+ if (!identified) {
9831
+ status.unknownObjects = status.unknownObjects ?? [];
9832
+ status.unknownObjects.push(key);
9833
+ }
9834
+ }
9835
+ }
9836
+ if (latestContinuationToken && context.getRemainingTimeInMillis() <= maxMetricProcessingTime) {
9837
+ console.log("Running up to the Lambda time limit and there are still items to process. Saving our current progress...");
9838
+ return saveProgress(latestContinuationToken);
9777
9839
  }
9778
9840
  }
9779
9841
  const reports = [];
9780
9842
  function createReport(reportKey, packageVersions) {
9781
9843
  const report = JSON.stringify(packageVersions, null, 2);
9782
9844
  const { buffer, contentEncoding } = compressContent(Buffer.from(report));
9783
- console.log(`Uploading list to s3://${bucket}/${reportKey}`);
9845
+ console.log(`Uploading list to s3://${packageDataBucket}/${reportKey}`);
9784
9846
  reports.push(s3().putObject({
9785
9847
  Body: buffer,
9786
- Bucket: bucket,
9848
+ Bucket: packageDataBucket,
9787
9849
  ContentEncoding: contentEncoding,
9788
9850
  ContentType: "application/json",
9789
9851
  Expires: new Date(Date.now() + 3e5),
@@ -9843,16 +9905,17 @@ async function handler(event, context) {
9843
9905
  console.log(`### Start of data for ${language}`);
9844
9906
  metrics.setDimensions({ [LANGUAGE_DIMENSION]: language.toString() });
9845
9907
  for (const forStatus of [
9846
- PerLanguageStatus.SUPPORTED,
9847
- PerLanguageStatus.UNSUPPORTED,
9848
- PerLanguageStatus.MISSING,
9849
- PerLanguageStatus.CORRUPT_ASSEMBLY
9908
+ DocumentationStatus.SUPPORTED,
9909
+ DocumentationStatus.UNSUPPORTED,
9910
+ DocumentationStatus.MISSING,
9911
+ DocumentationStatus.CORRUPT_ASSEMBLY
9850
9912
  ]) {
9851
- for (const [key, statuses] of Object.entries(data)) {
9913
+ for (const [key, statuses] of data.entries()) {
9852
9914
  let filtered = Array.from(statuses.entries()).filter(([, status]) => forStatus === status);
9853
9915
  let metricName = METRIC_NAME_BY_STATUS_AND_GRAIN[forStatus][key];
9854
- if (forStatus === PerLanguageStatus.MISSING && metricName === "MissingPackageVersionCount" /* PER_LANGUAGE_MISSING_VERSIONS */ || forStatus === PerLanguageStatus.CORRUPT_ASSEMBLY && metricName === "CorruptAssemblyPackageVersionCount" /* PER_LANGUAGE_CORRUPT_ASSEMBLY_VERSIONS */) {
9855
- const reportKey = forStatus === PerLanguageStatus.MISSING ? missingDocumentationReport(language) : corruptAssemblyReport(language);
9916
+ if (forStatus === DocumentationStatus.MISSING && metricName === "MissingPackageVersionCount" /* PER_LANGUAGE_MISSING_VERSIONS */ || forStatus === DocumentationStatus.CORRUPT_ASSEMBLY && metricName === "CorruptAssemblyPackageVersionCount" /* PER_LANGUAGE_CORRUPT_ASSEMBLY_VERSIONS */) {
9917
+ const lang = DocumentationLanguage.fromString(language);
9918
+ const reportKey = forStatus === DocumentationStatus.MISSING ? missingDocumentationReport(lang) : corruptAssemblyReport(lang);
9856
9919
  createReport(reportKey, filtered.map(([name]) => name).sort());
9857
9920
  }
9858
9921
  console.log(`${forStatus} ${key} for ${language}: ${filtered.length} entries`);
@@ -9867,20 +9930,25 @@ async function handler(event, context) {
9867
9930
  for (const report of reports) {
9868
9931
  await report;
9869
9932
  }
9933
+ return {};
9870
9934
  }
9871
- async function* relevantObjectKeys(bucket) {
9935
+ async function* relevantObjectKeys(bucket, continuationToken) {
9872
9936
  const request = {
9873
9937
  Bucket: bucket,
9874
9938
  Prefix: STORAGE_KEY_PREFIX
9875
9939
  };
9940
+ if (continuationToken)
9941
+ request.ContinuationToken = continuationToken;
9876
9942
  do {
9877
9943
  const response = await s3().listObjectsV2(request).promise();
9944
+ const keys = [];
9878
9945
  for (const { Key } of response.Contents ?? []) {
9879
9946
  if (Key == null) {
9880
9947
  continue;
9881
9948
  }
9882
- yield Key;
9949
+ keys.push(Key);
9883
9950
  }
9951
+ yield [keys, response.ContinuationToken];
9884
9952
  request.ContinuationToken = response.NextContinuationToken;
9885
9953
  } while (request.ContinuationToken != null);
9886
9954
  }
@@ -9892,13 +9960,20 @@ function submoduleKeyRegexp(language, fileExt) {
9892
9960
  return str.replace(/([+*.()?$[\]])/g, "\\$1");
9893
9961
  }
9894
9962
  }
9895
- var PerLanguageStatus = /* @__PURE__ */ ((PerLanguageStatus2) => {
9896
- PerLanguageStatus2["MISSING"] = "Missing";
9897
- PerLanguageStatus2["UNSUPPORTED"] = "Unsupported";
9898
- PerLanguageStatus2["CORRUPT_ASSEMBLY"] = "CorruptAssembly";
9899
- PerLanguageStatus2["SUPPORTED"] = "Supported";
9900
- return PerLanguageStatus2;
9901
- })(PerLanguageStatus || {});
9963
+ var Grain = /* @__PURE__ */ ((Grain2) => {
9964
+ Grain2["PACKAGE_MAJOR_VERSIONS"] = "package major versions";
9965
+ Grain2["PACKAGE_VERSION_SUBMODULES"] = "package version submodules";
9966
+ Grain2["PACKAGE_VERSIONS"] = "package versions";
9967
+ Grain2["PACKAGES"] = "packages";
9968
+ return Grain2;
9969
+ })(Grain || {});
9970
+ var DocumentationStatus = /* @__PURE__ */ ((DocumentationStatus2) => {
9971
+ DocumentationStatus2["MISSING"] = "Missing";
9972
+ DocumentationStatus2["UNSUPPORTED"] = "Unsupported";
9973
+ DocumentationStatus2["CORRUPT_ASSEMBLY"] = "CorruptAssembly";
9974
+ DocumentationStatus2["SUPPORTED"] = "Supported";
9975
+ return DocumentationStatus2;
9976
+ })(DocumentationStatus || {});
9902
9977
  var METRIC_NAME_BY_STATUS_AND_GRAIN = {
9903
9978
  ["Missing" /* MISSING */]: {
9904
9979
  ["packages" /* PACKAGES */]: "MissingPackageCount" /* PER_LANGUAGE_MISSING_PACKAGES */,
@@ -9926,21 +10001,21 @@ var METRIC_NAME_BY_STATUS_AND_GRAIN = {
9926
10001
  }
9927
10002
  };
9928
10003
  function doRecordPerLanguage(perLanguage, language, status, pkgName, pkgMajor, pkgVersion, submodule) {
9929
- if (!perLanguage.has(language)) {
9930
- perLanguage.set(language, {
9931
- ["package major versions" /* PACKAGE_MAJOR_VERSIONS */]: /* @__PURE__ */ new Map(),
9932
- ["packages" /* PACKAGES */]: /* @__PURE__ */ new Map(),
9933
- ["package version submodules" /* PACKAGE_VERSION_SUBMODULES */]: /* @__PURE__ */ new Map(),
9934
- ["package versions" /* PACKAGE_VERSIONS */]: /* @__PURE__ */ new Map()
9935
- });
9936
- }
9937
- const data = perLanguage.get(language);
10004
+ if (!perLanguage.has(language.name)) {
10005
+ const perGrainData = /* @__PURE__ */ new Map();
10006
+ perGrainData.set("package major versions" /* PACKAGE_MAJOR_VERSIONS */, /* @__PURE__ */ new Map());
10007
+ perGrainData.set("packages" /* PACKAGES */, /* @__PURE__ */ new Map());
10008
+ perGrainData.set("package version submodules" /* PACKAGE_VERSION_SUBMODULES */, /* @__PURE__ */ new Map());
10009
+ perGrainData.set("package versions" /* PACKAGE_VERSIONS */, /* @__PURE__ */ new Map());
10010
+ perLanguage.set(language.name, perGrainData);
10011
+ }
10012
+ const data = perLanguage.get(language.name);
9938
10013
  const outputDomains = submodule ? [
9939
- [data["package version submodules" /* PACKAGE_VERSION_SUBMODULES */], `${pkgVersion}.${submodule}`]
10014
+ [data.get("package version submodules" /* PACKAGE_VERSION_SUBMODULES */), `${pkgVersion}.${submodule}`]
9940
10015
  ] : [
9941
- [data["package major versions" /* PACKAGE_MAJOR_VERSIONS */], pkgMajor],
9942
- [data["package versions" /* PACKAGE_VERSIONS */], pkgVersion],
9943
- [data["packages" /* PACKAGES */], pkgName]
10016
+ [data.get("package major versions" /* PACKAGE_MAJOR_VERSIONS */), pkgMajor],
10017
+ [data.get("package versions" /* PACKAGE_VERSIONS */), pkgVersion],
10018
+ [data.get("packages" /* PACKAGES */), pkgName]
9944
10019
  ];
9945
10020
  for (const [map, name] of outputDomains) {
9946
10021
  switch (status) {
@@ -9961,8 +10036,44 @@ function doRecordPerLanguage(perLanguage, language, status, pkgName, pkgMajor, p
9961
10036
  }
9962
10037
  }
9963
10038
  }
10039
+ function safeReplacer(_key, value) {
10040
+ if (value instanceof Map) {
10041
+ return {
10042
+ _type: "Map",
10043
+ value: Array.from(value.entries())
10044
+ };
10045
+ } else if (value instanceof Set) {
10046
+ return {
10047
+ _type: "Set",
10048
+ value: Array.from([...value])
10049
+ };
10050
+ } else {
10051
+ return value;
10052
+ }
10053
+ }
10054
+ function safeReviver(_key, value) {
10055
+ if (typeof value === "object" && value !== null) {
10056
+ if (value._type === "Map") {
10057
+ return new Map(value.value);
10058
+ }
10059
+ if (value._type === "Set") {
10060
+ return new Set(value.value);
10061
+ }
10062
+ }
10063
+ return value;
10064
+ }
10065
+ function serialize(value) {
10066
+ return JSON.stringify(value, safeReplacer, 2);
10067
+ }
10068
+ function deserialize(value) {
10069
+ return JSON.parse(value, safeReviver);
10070
+ }
9964
10071
  // Annotate the CommonJS export names for ESM import in node:
9965
10072
  0 && (module.exports = {
9966
- handler
10073
+ DocumentationStatus,
10074
+ Grain,
10075
+ deserialize,
10076
+ handler,
10077
+ serialize
9967
10078
  });
9968
10079
  //# sourceMappingURL=index.js.map