@kleros/kleros-sdk 2.0.1-2 → 2.1.0

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.
Files changed (85) hide show
  1. package/README.md +2 -3
  2. package/lib/src/consts.js +0 -1
  3. package/lib/src/dataMappings/actions/callAction.d.ts +2 -2
  4. package/lib/src/dataMappings/actions/callAction.js +5 -3
  5. package/lib/src/dataMappings/actions/eventAction.d.ts +2 -2
  6. package/lib/src/dataMappings/actions/eventAction.js +5 -4
  7. package/lib/src/dataMappings/actions/fetchIpfsJsonAction.d.ts +2 -2
  8. package/lib/src/dataMappings/actions/fetchIpfsJsonAction.js +9 -7
  9. package/lib/src/dataMappings/actions/jsonAction.d.ts +2 -2
  10. package/lib/src/dataMappings/actions/jsonAction.js +3 -3
  11. package/lib/src/dataMappings/actions/subgraphAction.d.ts +2 -2
  12. package/lib/src/dataMappings/actions/subgraphAction.js +1 -6
  13. package/lib/src/dataMappings/disputeDetails.js +0 -1
  14. package/lib/src/dataMappings/executeActions.d.ts +5 -4
  15. package/lib/src/dataMappings/executeActions.js +13 -17
  16. package/lib/src/dataMappings/retrieveRealityData.d.ts +15 -1
  17. package/lib/src/dataMappings/retrieveRealityData.js +8 -3
  18. package/lib/src/dataMappings/utils/actionTypeValidators.d.ts +7 -0
  19. package/lib/src/dataMappings/utils/{dataMappingValidators.js → actionTypeValidators.js} +2 -3
  20. package/lib/src/dataMappings/utils/actionTypes.d.ts +40 -0
  21. package/lib/src/dataMappings/utils/{disputeRequest.js → actionTypes.js} +0 -1
  22. package/lib/src/dataMappings/utils/createResultObject.d.ts +1 -1
  23. package/lib/src/dataMappings/utils/createResultObject.js +10 -11
  24. package/lib/src/dataMappings/utils/disputeDetailsSchema.d.ts +57 -92
  25. package/lib/src/dataMappings/utils/disputeDetailsSchema.js +24 -19
  26. package/lib/src/dataMappings/utils/disputeDetailsTypes.js +0 -1
  27. package/lib/src/dataMappings/utils/populateTemplate.js +6 -4
  28. package/lib/src/dataMappings/utils/replacePlaceholdersWithValues.d.ts +2 -1
  29. package/lib/src/dataMappings/utils/replacePlaceholdersWithValues.js +27 -9
  30. package/lib/src/dataMappings/utils/retrieveVariables.d.ts +2 -0
  31. package/lib/src/dataMappings/utils/retrieveVariables.js +15 -0
  32. package/lib/src/index.d.ts +2 -0
  33. package/lib/src/index.js +2 -1
  34. package/lib/src/requests/fetchDisputeDetails.d.ts +12 -0
  35. package/lib/src/requests/fetchDisputeDetails.js +24 -0
  36. package/lib/src/requests/fetchDisputeTemplateFromId.d.ts +8 -0
  37. package/lib/src/requests/fetchDisputeTemplateFromId.js +20 -0
  38. package/lib/src/sdk.d.ts +4 -4
  39. package/lib/src/sdk.js +2 -16
  40. package/lib/src/types/index.d.ts +15 -0
  41. package/lib/src/types/index.js +2 -0
  42. package/lib/src/utils/getDispute.d.ts +3 -0
  43. package/lib/src/utils/getDispute.js +44 -0
  44. package/package.json +10 -12
  45. package/lib/src/consts.js.map +0 -1
  46. package/lib/src/dataMappings/actions/callAction.js.map +0 -1
  47. package/lib/src/dataMappings/actions/eventAction.js.map +0 -1
  48. package/lib/src/dataMappings/actions/fetchIpfsJsonAction.js.map +0 -1
  49. package/lib/src/dataMappings/actions/jsonAction.js.map +0 -1
  50. package/lib/src/dataMappings/actions/subgraphAction.js.map +0 -1
  51. package/lib/src/dataMappings/decoder.d.ts +0 -7
  52. package/lib/src/dataMappings/decoder.js +0 -41
  53. package/lib/src/dataMappings/decoder.js.map +0 -1
  54. package/lib/src/dataMappings/disputeDetails.js.map +0 -1
  55. package/lib/src/dataMappings/executeActions.js.map +0 -1
  56. package/lib/src/dataMappings/retrieveRealityData.js.map +0 -1
  57. package/lib/src/dataMappings/utils/createResultObject.js.map +0 -1
  58. package/lib/src/dataMappings/utils/dataMappingTypes.d.ts +0 -43
  59. package/lib/src/dataMappings/utils/dataMappingTypes.js +0 -51
  60. package/lib/src/dataMappings/utils/dataMappingTypes.js.map +0 -1
  61. package/lib/src/dataMappings/utils/dataMappingValidators.d.ts +0 -7
  62. package/lib/src/dataMappings/utils/dataMappingValidators.js.map +0 -1
  63. package/lib/src/dataMappings/utils/disputeDetailsSchema.js.map +0 -1
  64. package/lib/src/dataMappings/utils/disputeDetailsTypes.js.map +0 -1
  65. package/lib/src/dataMappings/utils/disputeDetailsValidator.d.ts +0 -32
  66. package/lib/src/dataMappings/utils/disputeDetailsValidator.js +0 -29
  67. package/lib/src/dataMappings/utils/disputeDetailsValidator.js.map +0 -1
  68. package/lib/src/dataMappings/utils/disputeRequest.d.ts +0 -8
  69. package/lib/src/dataMappings/utils/disputeRequest.js.map +0 -1
  70. package/lib/src/dataMappings/utils/populateTemplate.js.map +0 -1
  71. package/lib/src/dataMappings/utils/replacePlaceholdersWithValues.js.map +0 -1
  72. package/lib/src/graphql/fragment-masking.d.ts +0 -15
  73. package/lib/src/graphql/fragment-masking.js +0 -23
  74. package/lib/src/graphql/fragment-masking.js.map +0 -1
  75. package/lib/src/graphql/gql.d.ts +0 -108
  76. package/lib/src/graphql/gql.js +0 -56
  77. package/lib/src/graphql/gql.js.map +0 -1
  78. package/lib/src/graphql/graphql.d.ts +0 -4869
  79. package/lib/src/graphql/graphql.js +0 -719
  80. package/lib/src/graphql/graphql.js.map +0 -1
  81. package/lib/src/graphql/index.d.ts +0 -2
  82. package/lib/src/graphql/index.js +0 -19
  83. package/lib/src/graphql/index.js.map +0 -1
  84. package/lib/src/index.js.map +0 -1
  85. package/lib/src/sdk.js.map +0 -1
package/README.md CHANGED
@@ -2,11 +2,10 @@
2
2
 
3
3
  _Archon's successor_
4
4
 
5
- Make sure to set the environment variables first by copying the file `.env.example`, pasting it, renaming it to `.env`, and then setting the variables.
6
- To run the data mappings tests:
5
+ To run the data mappings tests, at the root folder level, do:
7
6
 
8
7
  ```bash
9
- yarn run test-data-mappings
8
+ yarn test
10
9
  ```
11
10
 
12
11
  🚧 ⚖️ 🚧
package/lib/src/consts.js CHANGED
@@ -2,4 +2,3 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MAX_BYTE_SIZE = void 0;
4
4
  exports.MAX_BYTE_SIZE = 1000000;
5
- //# sourceMappingURL=consts.js.map
@@ -1,2 +1,2 @@
1
- import { AbiCallMapping } from "~src/dataMappings/utils/dataMappingTypes";
2
- export declare const callAction: (mapping: AbiCallMapping) => Promise<{}>;
1
+ import { AbiCallMapping } from "src/dataMappings/utils/actionTypes";
2
+ export declare const callAction: (mapping: AbiCallMapping) => Promise<Record<string, any>>;
@@ -5,16 +5,18 @@ const viem_1 = require("viem");
5
5
  const createResultObject_1 = require("src/dataMappings/utils/createResultObject");
6
6
  const sdk_1 = require("src/sdk");
7
7
  const callAction = async (mapping) => {
8
- (0, sdk_1.configureSDK)({ apiKey: process.env.ALCHEMY_API_KEY });
9
8
  const publicClient = (0, sdk_1.getPublicClient)();
10
- const { abi: source, address, args, seek, populate } = mapping;
9
+ if (!publicClient) {
10
+ throw new Error("SDK not configured. Please call `configureSDK` before using.");
11
+ }
12
+ const { abi: source, address, functionName, args, seek, populate } = mapping;
11
13
  const parsedAbi = typeof source === "string" ? (0, viem_1.parseAbiItem)(source) : source;
12
14
  const data = await publicClient.readContract({
13
15
  address,
14
16
  abi: [parsedAbi],
17
+ functionName,
15
18
  args,
16
19
  });
17
20
  return (0, createResultObject_1.createResultObject)(data, seek, populate);
18
21
  };
19
22
  exports.callAction = callAction;
20
- //# sourceMappingURL=callAction.js.map
@@ -1,2 +1,2 @@
1
- import { AbiEventMapping } from "~src/dataMappings/utils/dataMappingTypes";
2
- export declare const eventAction: (mapping: AbiEventMapping) => Promise<{}>;
1
+ import { AbiEventMapping } from "src/dataMappings/utils/actionTypes";
2
+ export declare const eventAction: (mapping: AbiEventMapping) => Promise<Record<string, any>>;
@@ -5,10 +5,12 @@ const viem_1 = require("viem");
5
5
  const createResultObject_1 = require("src/dataMappings/utils/createResultObject");
6
6
  const sdk_1 = require("src/sdk");
7
7
  const eventAction = async (mapping) => {
8
- (0, sdk_1.configureSDK)({ apiKey: process.env.ALCHEMY_API_KEY });
9
8
  const publicClient = (0, sdk_1.getPublicClient)();
9
+ if (!publicClient) {
10
+ throw new Error("SDK not configured. Please call `configureSDK` before using.");
11
+ }
10
12
  const { abi: source, address, eventFilter, seek, populate } = mapping;
11
- const parsedAbi = typeof source === "string" ? (0, viem_1.parseAbiItem)(source) : source;
13
+ const parsedAbi = (0, viem_1.parseAbiItem)(source);
12
14
  const filter = await publicClient.createEventFilter({
13
15
  address,
14
16
  event: parsedAbi,
@@ -16,9 +18,8 @@ const eventAction = async (mapping) => {
16
18
  fromBlock: eventFilter.fromBlock,
17
19
  toBlock: eventFilter.toBlock,
18
20
  });
19
- const contractEvent = await publicClient.getFilterLogs({ filter: filter });
21
+ const contractEvent = await publicClient.getFilterLogs({ filter });
20
22
  const eventData = contractEvent[0].args;
21
23
  return (0, createResultObject_1.createResultObject)(eventData, seek, populate);
22
24
  };
23
25
  exports.eventAction = eventAction;
24
- //# sourceMappingURL=eventAction.js.map
@@ -1,2 +1,2 @@
1
- import { FetchIpfsJsonMapping } from "~src/dataMappings/utils/dataMappingTypes";
2
- export declare const fetchIpfsJsonAction: (mapping: FetchIpfsJsonMapping) => Promise<{}>;
1
+ import { FetchIpfsJsonMapping } from "src/dataMappings/utils/actionTypes";
2
+ export declare const fetchIpfsJsonAction: (mapping: FetchIpfsJsonMapping) => Promise<Record<string, any>>;
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.fetchIpfsJsonAction = void 0;
7
- const node_fetch_1 = __importDefault(require("node-fetch"));
8
4
  const createResultObject_1 = require("src/dataMappings/utils/createResultObject");
9
5
  const consts_1 = require("src/consts");
10
6
  const fetchIpfsJsonAction = async (mapping) => {
@@ -19,8 +15,15 @@ const fetchIpfsJsonAction = async (mapping) => {
19
15
  else if (!ipfsUri.startsWith("http")) {
20
16
  httpUri = `https://ipfs.io/ipfs/${ipfsUri}`;
21
17
  }
22
- const response = await (0, node_fetch_1.default)(httpUri, { method: "GET" });
23
- if (response.headers.get("content-length") > consts_1.MAX_BYTE_SIZE) {
18
+ else {
19
+ throw new Error("Invalid IPFS URI format");
20
+ }
21
+ const response = await fetch(httpUri, { method: "GET" });
22
+ if (!response.ok) {
23
+ throw new Error("Failed to fetch data from IPFS");
24
+ }
25
+ const contentLength = response.headers.get("content-length");
26
+ if (contentLength && parseInt(contentLength) > consts_1.MAX_BYTE_SIZE) {
24
27
  throw new Error("Response size is too large");
25
28
  }
26
29
  const contentType = response.headers.get("content-type");
@@ -31,4 +34,3 @@ const fetchIpfsJsonAction = async (mapping) => {
31
34
  return (0, createResultObject_1.createResultObject)(data, seek, populate);
32
35
  };
33
36
  exports.fetchIpfsJsonAction = fetchIpfsJsonAction;
34
- //# sourceMappingURL=fetchIpfsJsonAction.js.map
@@ -1,2 +1,2 @@
1
- import { JsonMapping } from "../utils/dataMappingTypes";
2
- export declare const jsonAction: (mapping: JsonMapping) => {};
1
+ import { JsonMapping } from "../utils/actionTypes";
2
+ export declare const jsonAction: (mapping: JsonMapping) => Record<string, any>;
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.jsonAction = void 0;
4
4
  const createResultObject_1 = require("src/dataMappings/utils/createResultObject");
5
5
  const jsonAction = (mapping) => {
6
- const { value: source, seek, populate } = mapping;
7
- return (0, createResultObject_1.createResultObject)(source, seek, populate);
6
+ const { value, seek, populate } = mapping;
7
+ const parsedValue = typeof value === "string" ? JSON.parse(value) : value;
8
+ return (0, createResultObject_1.createResultObject)(parsedValue, seek, populate);
8
9
  };
9
10
  exports.jsonAction = jsonAction;
10
- //# sourceMappingURL=jsonAction.js.map
@@ -1,2 +1,2 @@
1
- import { SubgraphMapping } from "../utils/dataMappingTypes";
2
- export declare const subgraphAction: (mapping: SubgraphMapping) => Promise<{}>;
1
+ import { SubgraphMapping } from "../utils/actionTypes";
2
+ export declare const subgraphAction: (mapping: SubgraphMapping) => Promise<Record<string, any>>;
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.subgraphAction = void 0;
7
- const node_fetch_1 = __importDefault(require("node-fetch"));
8
4
  const createResultObject_1 = require("src/dataMappings/utils/createResultObject");
9
5
  const subgraphAction = async (mapping) => {
10
6
  const { endpoint, query, variables, seek, populate } = mapping;
11
- const response = await (0, node_fetch_1.default)(endpoint, {
7
+ const response = await fetch(endpoint, {
12
8
  method: "POST",
13
9
  headers: {
14
10
  "Content-Type": "application/json",
@@ -20,4 +16,3 @@ const subgraphAction = async (mapping) => {
20
16
  return (0, createResultObject_1.createResultObject)(data, seek, populate);
21
17
  };
22
18
  exports.subgraphAction = subgraphAction;
23
- //# sourceMappingURL=subgraphAction.js.map
@@ -9,4 +9,3 @@ var QuestionType;
9
9
  QuestionType["SingleSelect"] = "single-select";
10
10
  QuestionType["Uint"] = "uint";
11
11
  })(QuestionType || (exports.QuestionType = QuestionType = {}));
12
- //# sourceMappingURL=disputeDetails.js.map
@@ -1,4 +1,5 @@
1
- import { DataMapping } from "./utils/dataMappingTypes";
2
- import { DisputeRequest } from "./utils/disputeRequest";
3
- export declare const executeAction: (mapping: DataMapping<any>, context?: DisputeRequest) => any;
4
- export declare const executeActions: (mappings: any, initialContext?: DisputeRequest) => Promise<DisputeRequest>;
1
+ import { ActionMapping } from "./utils/actionTypes";
2
+ type ActionResult = Record<string, unknown> | null | undefined;
3
+ export declare const executeAction: (mapping: ActionMapping, context?: Record<string, unknown>) => Promise<ActionResult>;
4
+ export declare const executeActions: (mappings: ActionMapping[], initialContext?: Record<string, unknown>) => Promise<Record<string, unknown>>;
5
+ export {};
@@ -2,39 +2,36 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeActions = exports.executeAction = void 0;
4
4
  const callAction_1 = require("./actions/callAction");
5
- const eventAction_1 = require("./actions/eventAction");
5
+ const eventAction_js_1 = require("./actions/eventAction.js");
6
6
  const fetchIpfsJsonAction_1 = require("./actions/fetchIpfsJsonAction");
7
7
  const jsonAction_1 = require("./actions/jsonAction");
8
8
  const subgraphAction_1 = require("./actions/subgraphAction");
9
9
  const retrieveRealityData_1 = require("./retrieveRealityData");
10
- const dataMappingValidators_1 = require("./utils/dataMappingValidators");
10
+ const actionTypeValidators_1 = require("./utils/actionTypeValidators");
11
11
  const replacePlaceholdersWithValues_1 = require("./utils/replacePlaceholdersWithValues");
12
- const executeAction = async (mapping, context) => {
12
+ const executeAction = async (mapping, context = {}) => {
13
13
  mapping = (0, replacePlaceholdersWithValues_1.replacePlaceholdersWithValues)(mapping, context);
14
14
  switch (mapping.type) {
15
15
  case "graphql":
16
- return await (0, subgraphAction_1.subgraphAction)((0, dataMappingValidators_1.validateSubgraphMapping)(mapping));
16
+ return await (0, subgraphAction_1.subgraphAction)((0, actionTypeValidators_1.validateSubgraphMapping)(mapping));
17
17
  case "json":
18
- return (0, jsonAction_1.jsonAction)((0, dataMappingValidators_1.validateJsonMapping)(mapping));
18
+ return (0, jsonAction_1.jsonAction)((0, actionTypeValidators_1.validateJsonMapping)(mapping));
19
19
  case "abi/call":
20
- return await (0, callAction_1.callAction)((0, dataMappingValidators_1.validateAbiCallMapping)(mapping));
20
+ return await (0, callAction_1.callAction)((0, actionTypeValidators_1.validateAbiCallMapping)(mapping));
21
21
  case "abi/event":
22
- return await (0, eventAction_1.eventAction)((0, dataMappingValidators_1.validateAbiEventMapping)(mapping));
22
+ return await (0, eventAction_js_1.eventAction)((0, actionTypeValidators_1.validateAbiEventMapping)(mapping));
23
23
  case "fetch/ipfs/json":
24
- return await (0, fetchIpfsJsonAction_1.fetchIpfsJsonAction)((0, dataMappingValidators_1.validateFetchIpfsJsonMapping)(mapping));
24
+ return await (0, fetchIpfsJsonAction_1.fetchIpfsJsonAction)((0, actionTypeValidators_1.validateFetchIpfsJsonMapping)(mapping));
25
25
  case "reality":
26
- mapping = (0, dataMappingValidators_1.validateRealityMapping)(mapping);
27
- if (!context?.arbitrable) {
28
- throw new Error("Arbitrable address is required for reality action");
29
- }
30
- return await (0, retrieveRealityData_1.retrieveRealityData)(mapping.realityQuestionID, context.arbitrable);
26
+ mapping = (0, actionTypeValidators_1.validateRealityMapping)(mapping);
27
+ return await (0, retrieveRealityData_1.retrieveRealityData)(mapping.realityQuestionID, context.arbitrableAddress);
31
28
  default:
32
- throw new Error(`Unsupported action type: ${mapping.type}`);
29
+ throw new Error(`Unsupported action type: ${JSON.stringify(mapping)}`);
33
30
  }
34
31
  };
35
32
  exports.executeAction = executeAction;
36
- const executeActions = async (mappings, initialContext) => {
37
- const context = Object.assign({}, initialContext);
33
+ const executeActions = async (mappings, initialContext = {}) => {
34
+ const context = { ...initialContext };
38
35
  for (const mapping of mappings) {
39
36
  const actionResult = await (0, exports.executeAction)(mapping, context);
40
37
  if (actionResult) {
@@ -46,4 +43,3 @@ const executeActions = async (mappings, initialContext) => {
46
43
  return context;
47
44
  };
48
45
  exports.executeActions = executeActions;
49
- //# sourceMappingURL=executeActions.js.map
@@ -1 +1,15 @@
1
- export declare const retrieveRealityData: (realityQuestionID: string, arbitrable?: `0x${string}`) => any;
1
+ export type RealityAnswer = {
2
+ title: string;
3
+ description: string;
4
+ id: string;
5
+ reserved: boolean;
6
+ last?: boolean;
7
+ };
8
+ export declare const retrieveRealityData: (realityQuestionID: string, arbitrable?: `0x${string}`) => Promise<{
9
+ question: unknown;
10
+ type: any;
11
+ realityAddress: unknown;
12
+ questionId: unknown;
13
+ realityUser: unknown;
14
+ answers: RealityAnswer[];
15
+ }>;
@@ -12,7 +12,7 @@ const retrieveRealityData = async (realityQuestionID, arbitrable) => {
12
12
  address: arbitrable,
13
13
  eventFilter: {
14
14
  args: [realityQuestionID],
15
- fromBlock: "0x1",
15
+ fromBlock: "earliest",
16
16
  toBlock: "latest",
17
17
  },
18
18
  seek: [
@@ -48,7 +48,7 @@ const retrieveRealityData = async (realityQuestionID, arbitrable) => {
48
48
  address: arbitrable,
49
49
  eventFilter: {
50
50
  args: [0],
51
- fromBlock: "0x1",
51
+ fromBlock: "earliest",
52
52
  toBlock: "latest",
53
53
  },
54
54
  seek: ["template_id", "question_text"],
@@ -56,6 +56,9 @@ const retrieveRealityData = async (realityQuestionID, arbitrable) => {
56
56
  };
57
57
  const templateData = await (0, executeActions_1.executeAction)(templateMapping);
58
58
  console.log("templateData", templateData);
59
+ if (!templateData || !questionData) {
60
+ throw new Error("Failed to retrieve template or question data");
61
+ }
59
62
  const rc_question = require("@reality.eth/reality-eth-lib/formatters/question.js");
60
63
  const populatedTemplate = rc_question.populatedJSONForTemplate(templateData.questionText, questionData.realityQuestion);
61
64
  console.log("populatedTemplate", populatedTemplate);
@@ -82,6 +85,9 @@ const retrieveRealityData = async (realityQuestionID, arbitrable) => {
82
85
  description: "",
83
86
  reserved: true,
84
87
  });
88
+ for (let i = 0; i < answers.length; i++) {
89
+ answers[i].last = i === answers.length - 1;
90
+ }
85
91
  return {
86
92
  question: questionData.realityQuestion,
87
93
  type: populatedTemplate.type,
@@ -92,4 +98,3 @@ const retrieveRealityData = async (realityQuestionID, arbitrable) => {
92
98
  };
93
99
  };
94
100
  exports.retrieveRealityData = retrieveRealityData;
95
- //# sourceMappingURL=retrieveRealityData.js.map
@@ -0,0 +1,7 @@
1
+ import { SubgraphMapping, AbiEventMapping, AbiCallMapping, JsonMapping, ActionMapping, FetchIpfsJsonMapping, RealityMapping } from "./actionTypes";
2
+ export declare const validateSubgraphMapping: (mapping: ActionMapping) => SubgraphMapping;
3
+ export declare const validateAbiEventMapping: (mapping: ActionMapping) => AbiEventMapping;
4
+ export declare const validateAbiCallMapping: (mapping: ActionMapping) => AbiCallMapping;
5
+ export declare const validateJsonMapping: (mapping: ActionMapping) => JsonMapping;
6
+ export declare const validateFetchIpfsJsonMapping: (mapping: ActionMapping) => FetchIpfsJsonMapping;
7
+ export declare const validateRealityMapping: (mapping: ActionMapping) => RealityMapping;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateRealityMapping = exports.validateFetchIpfsJsonMapping = exports.validateJsonMapping = exports.validateAbiCallMapping = exports.validateAbiEventMapping = exports.validateSubgraphMapping = void 0;
4
4
  const validateSubgraphMapping = (mapping) => {
5
- if (mapping.endpoint !== undefined) {
5
+ if (mapping.endpoint === undefined) {
6
6
  throw new Error("Invalid mapping for graphql action.");
7
7
  }
8
8
  return mapping;
@@ -16,7 +16,7 @@ const validateAbiEventMapping = (mapping) => {
16
16
  };
17
17
  exports.validateAbiEventMapping = validateAbiEventMapping;
18
18
  const validateAbiCallMapping = (mapping) => {
19
- if (mapping.abi === undefined || mapping.args === undefined) {
19
+ if (mapping.abi === undefined || mapping.functionName === undefined) {
20
20
  throw new Error("Invalid mapping for abi/call action.");
21
21
  }
22
22
  return mapping;
@@ -43,4 +43,3 @@ const validateRealityMapping = (mapping) => {
43
43
  return mapping;
44
44
  };
45
45
  exports.validateRealityMapping = validateRealityMapping;
46
- //# sourceMappingURL=dataMappingValidators.js.map
@@ -0,0 +1,40 @@
1
+ import { type Address, type BlockNumber, type BlockTag } from "viem";
2
+ type MappingType = "graphql" | "abi/call" | "abi/event" | "json" | "fetch/ipfs/json" | "reality";
3
+ type AbstractMapping<T extends MappingType> = {
4
+ type: T;
5
+ seek: string[];
6
+ populate: string[];
7
+ };
8
+ export type JsonMapping = AbstractMapping<"json"> & {
9
+ value: object;
10
+ };
11
+ export type SubgraphMapping = AbstractMapping<"graphql"> & {
12
+ endpoint: string;
13
+ query: string;
14
+ variables: {
15
+ [key: string]: unknown;
16
+ };
17
+ };
18
+ export type AbiCallMapping = AbstractMapping<"abi/call"> & {
19
+ abi: string;
20
+ address: Address;
21
+ functionName: string;
22
+ args: any[];
23
+ };
24
+ export type AbiEventMapping = AbstractMapping<"abi/event"> & {
25
+ abi: string;
26
+ address: Address;
27
+ eventFilter: {
28
+ fromBlock: BlockNumber | BlockTag;
29
+ toBlock: BlockNumber | BlockTag;
30
+ args: any;
31
+ };
32
+ };
33
+ export type FetchIpfsJsonMapping = AbstractMapping<"fetch/ipfs/json"> & {
34
+ ipfsUri: string;
35
+ };
36
+ export type RealityMapping = AbstractMapping<"reality"> & {
37
+ realityQuestionID: string;
38
+ };
39
+ export type ActionMapping = SubgraphMapping | AbiEventMapping | AbiCallMapping | JsonMapping | FetchIpfsJsonMapping | RealityMapping;
40
+ export {};
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=disputeRequest.js.map
@@ -1 +1 @@
1
- export declare const createResultObject: (sourceData: any, seek: any, populate: any) => {};
1
+ export declare const createResultObject: (sourceData: Record<string, any>, seek: string[], populate: string[]) => Record<string, any>;
@@ -3,22 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createResultObject = void 0;
4
4
  const createResultObject = (sourceData, seek, populate) => {
5
5
  const result = {};
6
+ const getNestedValue = (obj, path) => {
7
+ return path.split(".").reduce((acc, part) => {
8
+ if (acc && part.includes("[")) {
9
+ const [key, index] = part.replace(/\]/g, "").split("[");
10
+ return acc[key]?.[index];
11
+ }
12
+ return acc ? acc[part] : undefined;
13
+ }, obj);
14
+ };
6
15
  seek.forEach((key, idx) => {
7
- let foundValue;
8
- if (typeof sourceData !== "object" || key === "0") {
9
- foundValue = sourceData;
10
- }
11
- else {
12
- foundValue = sourceData[key];
13
- }
14
- console.log(`Seek key: ${key}, Found value:`, foundValue);
16
+ const foundValue = getNestedValue(sourceData, key);
15
17
  if (foundValue !== undefined) {
16
18
  result[populate[idx]] = foundValue;
17
- console.log(`Populate key: ${populate[idx]}, Value to add:`, foundValue);
18
19
  }
19
20
  });
20
- console.log("Result object:", result);
21
21
  return result;
22
22
  };
23
23
  exports.createResultObject = createResultObject;
24
- //# sourceMappingURL=createResultObject.js.map
@@ -1,4 +1,7 @@
1
1
  import { z } from "zod";
2
+ export declare const isHexAddress: (str: string) => boolean;
3
+ export declare const isHexId: (str: string) => boolean;
4
+ export declare const isMultiaddr: (str: string) => boolean;
2
5
  export declare const ethAddressSchema: z.ZodEffects<z.ZodString, string, string>;
3
6
  export declare const ensNameSchema: z.ZodEffects<z.ZodString, string, string>;
4
7
  export declare const ethAddressOrEnsNameSchema: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>;
@@ -11,20 +14,20 @@ export declare enum QuestionType {
11
14
  }
12
15
  export declare const QuestionTypeSchema: z.ZodNativeEnum<typeof QuestionType>;
13
16
  export declare const AnswerSchema: z.ZodObject<{
14
- id: z.ZodString;
17
+ id: z.ZodOptional<z.ZodString>;
15
18
  title: z.ZodString;
16
19
  description: z.ZodString;
17
- reserved: z.ZodBoolean;
20
+ reserved: z.ZodOptional<z.ZodBoolean>;
18
21
  }, "strip", z.ZodTypeAny, {
19
- id: string;
20
- title: string;
21
22
  description: string;
22
- reserved: boolean;
23
- }, {
24
- id: string;
25
23
  title: string;
24
+ id?: string | undefined;
25
+ reserved?: boolean | undefined;
26
+ }, {
26
27
  description: string;
27
- reserved: boolean;
28
+ title: string;
29
+ id?: string | undefined;
30
+ reserved?: boolean | undefined;
28
31
  }>;
29
32
  export declare const AttachmentSchema: z.ZodObject<{
30
33
  label: z.ZodString;
@@ -36,42 +39,29 @@ export declare const AttachmentSchema: z.ZodObject<{
36
39
  label: string;
37
40
  uri: string;
38
41
  }>;
39
- export declare const AliasSchema: z.ZodObject<{
40
- id: z.ZodOptional<z.ZodString>;
41
- name: z.ZodString;
42
- address: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>;
43
- }, "strip", z.ZodTypeAny, {
44
- name: string;
45
- address: string;
46
- id?: string | undefined;
47
- }, {
48
- name: string;
49
- address: string;
50
- id?: string | undefined;
51
- }>;
42
+ export declare const AliasSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
52
43
  declare const DisputeDetailsSchema: z.ZodObject<{
53
44
  title: z.ZodString;
54
45
  description: z.ZodString;
55
46
  question: z.ZodString;
56
- type: z.ZodNativeEnum<typeof QuestionType>;
57
47
  answers: z.ZodArray<z.ZodObject<{
58
- id: z.ZodString;
48
+ id: z.ZodOptional<z.ZodString>;
59
49
  title: z.ZodString;
60
50
  description: z.ZodString;
61
- reserved: z.ZodBoolean;
51
+ reserved: z.ZodOptional<z.ZodBoolean>;
62
52
  }, "strip", z.ZodTypeAny, {
63
- id: string;
64
- title: string;
65
53
  description: string;
66
- reserved: boolean;
67
- }, {
68
- id: string;
69
54
  title: string;
55
+ id?: string | undefined;
56
+ reserved?: boolean | undefined;
57
+ }, {
70
58
  description: string;
71
- reserved: boolean;
59
+ title: string;
60
+ id?: string | undefined;
61
+ reserved?: boolean | undefined;
72
62
  }>, "many">;
73
- policyURI: z.ZodString;
74
- attachment: z.ZodObject<{
63
+ policyURI: z.ZodEffects<z.ZodString, string, string>;
64
+ attachment: z.ZodOptional<z.ZodObject<{
75
65
  label: z.ZodString;
76
66
  uri: z.ZodString;
77
67
  }, "strip", z.ZodTypeAny, {
@@ -80,88 +70,63 @@ declare const DisputeDetailsSchema: z.ZodObject<{
80
70
  }, {
81
71
  label: string;
82
72
  uri: string;
83
- }>;
84
- frontendUrl: z.ZodString;
85
- arbitrableChainID: z.ZodString;
86
- arbitrableAddress: z.ZodEffects<z.ZodString, string, string>;
73
+ }>>;
74
+ frontendUrl: z.ZodOptional<z.ZodString>;
75
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
87
76
  arbitratorChainID: z.ZodString;
88
77
  arbitratorAddress: z.ZodEffects<z.ZodString, string, string>;
89
- category: z.ZodString;
90
- lang: z.ZodString;
91
- specification: z.ZodString;
92
- aliases: z.ZodOptional<z.ZodArray<z.ZodObject<{
93
- id: z.ZodOptional<z.ZodString>;
94
- name: z.ZodString;
95
- address: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>;
96
- }, "strip", z.ZodTypeAny, {
97
- name: string;
98
- address: string;
99
- id?: string | undefined;
100
- }, {
101
- name: string;
102
- address: string;
103
- id?: string | undefined;
104
- }>, "many">>;
78
+ category: z.ZodOptional<z.ZodString>;
79
+ lang: z.ZodOptional<z.ZodString>;
80
+ specification: z.ZodOptional<z.ZodString>;
81
+ aliases: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>>;
105
82
  version: z.ZodString;
106
83
  }, "strip", z.ZodTypeAny, {
107
- type: QuestionType;
108
- title: string;
109
84
  description: string;
110
85
  question: string;
111
86
  answers: {
112
- id: string;
113
- title: string;
114
87
  description: string;
115
- reserved: boolean;
88
+ title: string;
89
+ id?: string | undefined;
90
+ reserved?: boolean | undefined;
116
91
  }[];
92
+ title: string;
117
93
  policyURI: string;
118
- attachment: {
119
- label: string;
120
- uri: string;
121
- };
122
- frontendUrl: string;
123
- arbitrableChainID: string;
124
- arbitrableAddress: string;
125
94
  arbitratorChainID: string;
126
95
  arbitratorAddress: string;
127
- category: string;
128
- lang: string;
129
- specification: string;
130
96
  version: string;
131
- aliases?: {
132
- name: string;
133
- address: string;
134
- id?: string | undefined;
135
- }[] | undefined;
97
+ attachment?: {
98
+ label: string;
99
+ uri: string;
100
+ } | undefined;
101
+ frontendUrl?: string | undefined;
102
+ metadata?: Record<string, unknown> | undefined;
103
+ category?: string | undefined;
104
+ lang?: string | undefined;
105
+ specification?: string | undefined;
106
+ aliases?: Record<string, string> | undefined;
136
107
  }, {
137
- type: QuestionType;
138
- title: string;
139
108
  description: string;
140
109
  question: string;
141
110
  answers: {
142
- id: string;
143
- title: string;
144
111
  description: string;
145
- reserved: boolean;
112
+ title: string;
113
+ id?: string | undefined;
114
+ reserved?: boolean | undefined;
146
115
  }[];
116
+ title: string;
147
117
  policyURI: string;
148
- attachment: {
149
- label: string;
150
- uri: string;
151
- };
152
- frontendUrl: string;
153
- arbitrableChainID: string;
154
- arbitrableAddress: string;
155
118
  arbitratorChainID: string;
156
119
  arbitratorAddress: string;
157
- category: string;
158
- lang: string;
159
- specification: string;
160
120
  version: string;
161
- aliases?: {
162
- name: string;
163
- address: string;
164
- id?: string | undefined;
165
- }[] | undefined;
121
+ attachment?: {
122
+ label: string;
123
+ uri: string;
124
+ } | undefined;
125
+ frontendUrl?: string | undefined;
126
+ metadata?: Record<string, unknown> | undefined;
127
+ category?: string | undefined;
128
+ lang?: string | undefined;
129
+ specification?: string | undefined;
130
+ aliases?: Record<string, string> | undefined;
166
131
  }>;
167
132
  export default DisputeDetailsSchema;