@prosopo/datasets 0.2.40 → 0.3.1

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.
@@ -120,7 +120,7 @@ function matchItemsToSolutions(solutions, items) {
120
120
  }
121
121
  return solutions.map((solution) => {
122
122
  if (typeof solution === "string" && util$2.isHex(solution)) {
123
- if (!(items == null ? void 0 : items.some((item) => item.hash === solution))) {
123
+ if (!items?.some((item) => item.hash === solution)) {
124
124
  throw new common.ProsopoDatasetError("CAPTCHA.INVALID_ITEM_HASH");
125
125
  }
126
126
  return solution;
@@ -139,7 +139,7 @@ function computePendingRequestHash(captchaIds, userAccount, salt) {
139
139
  return common.hexHashArray([...captchaIds.sort(), userAccount, salt]);
140
140
  }
141
141
  function parseCaptchaAssets(item, assetsResolver) {
142
- return { ...item, path: (assetsResolver == null ? void 0 : assetsResolver.resolveAsset(item.data).getURL()) || item.data };
142
+ return { ...item, path: assetsResolver?.resolveAsset(item.data).getURL() || item.data };
143
143
  }
144
144
  exports.NO_SOLUTION_VALUE = NO_SOLUTION_VALUE;
145
145
  exports.captchaSort = captchaSort;
@@ -34,28 +34,24 @@ async function validateDatasetContent(datasetOriginal) {
34
34
  return hashes.every((hash) => hash);
35
35
  }
36
36
  async function buildDataset(datasetRaw) {
37
- var _a, _b;
38
37
  logger.debug(`Adding solution hashes to dataset`);
39
38
  const dataset = await addSolutionHashesToDataset(datasetRaw);
40
39
  logger.debug(`Building dataset merkle trees`);
41
40
  const contentTree = await buildCaptchaTree(dataset, false, false, true);
42
41
  const solutionTree = await buildCaptchaTree(dataset, true, true, false);
43
42
  dataset.captchas = dataset.captchas.map(
44
- (captcha2, index) => {
45
- var _a2, _b2;
46
- return {
47
- ...captcha2,
48
- captchaId: util.at(solutionTree.leaves, index).hash,
49
- captchaContentId: util.at(contentTree.leaves, index).hash,
50
- datasetId: (_a2 = solutionTree.root) == null ? void 0 : _a2.hash,
51
- datasetContentId: (_b2 = contentTree.root) == null ? void 0 : _b2.hash
52
- };
53
- }
43
+ (captcha2, index) => ({
44
+ ...captcha2,
45
+ captchaId: util.at(solutionTree.leaves, index).hash,
46
+ captchaContentId: util.at(contentTree.leaves, index).hash,
47
+ datasetId: solutionTree.root?.hash,
48
+ datasetContentId: contentTree.root?.hash
49
+ })
54
50
  );
55
51
  dataset.solutionTree = solutionTree.layers;
56
52
  dataset.contentTree = contentTree.layers;
57
- dataset.datasetId = (_a = solutionTree.root) == null ? void 0 : _a.hash;
58
- dataset.datasetContentId = (_b = contentTree.root) == null ? void 0 : _b.hash;
53
+ dataset.datasetId = solutionTree.root?.hash;
54
+ dataset.datasetContentId = contentTree.root?.hash;
59
55
  return dataset;
60
56
  }
61
57
  async function buildCaptchaTree(dataset, includeSolution, includeSalt, sortItemHashes) {
@@ -1030,14 +1030,11 @@ const datasetWithSolutionHashes = {
1030
1030
  };
1031
1031
  const datasetWithIndexSolutions = {
1032
1032
  ...datasetWithSolutionHashes,
1033
- captchas: datasetWithSolutionHashes.captchas.map((captcha, index) => {
1034
- var _a;
1035
- return {
1036
- ...captcha,
1037
- //for solution in captcha.solution, find the index of captcha.item with item.hash == solution
1038
- solution: (_a = captcha.solution) == null ? void 0 : _a.map((solution) => captcha.items.findIndex((item) => item.hash === solution))
1039
- };
1040
- })
1033
+ captchas: datasetWithSolutionHashes.captchas.map((captcha, index) => ({
1034
+ ...captcha,
1035
+ //for solution in captcha.solution, find the index of captcha.item with item.hash == solution
1036
+ solution: captcha.solution?.map((solution) => captcha.items.findIndex((item) => item.hash === solution))
1037
+ }))
1041
1038
  };
1042
1039
  exports.datasetWithIndexSolutions = datasetWithIndexSolutions;
1043
1040
  exports.datasetWithSolutionHashes = datasetWithSolutionHashes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prosopo/datasets",
3
- "version": "0.2.40",
3
+ "version": "0.3.1",
4
4
  "author": "PROSOPO LIMITED <info@prosopo.io>",
5
5
  "license": "Apache-2.0",
6
6
  "private": false,
@@ -46,13 +46,13 @@
46
46
  }
47
47
  },
48
48
  "dependencies": {
49
- "@polkadot/util": "^12.3.2",
50
- "@prosopo/common": "0.2.40",
51
- "@prosopo/types": "0.2.40",
52
- "vitest": "^0.34.6"
49
+ "@polkadot/util": "12.6.1",
50
+ "@prosopo/common": "0.3.1",
51
+ "@prosopo/types": "0.3.1",
52
+ "vitest": "^1.3.1"
53
53
  },
54
54
  "devDependencies": {
55
- "@prosopo/config": "0.2.40",
55
+ "@prosopo/config": "0.3.1",
56
56
  "tslib": "2.6.2",
57
57
  "typescript": "5.1.6"
58
58
  },
@@ -0,0 +1,6 @@
1
+ export default {
2
+ entryPoints: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.js', 'src/**/*.jsx', 'src/**/*.json'],
3
+ includes: 'src',
4
+ extends: '../../typedoc.base.config.js',
5
+ readme: 'README.md',
6
+ }