<commit_before>const { default: convert } = require("@gnd/jsonschema2graphql");

import { makeExecutableSchema } from "@gnd/graphql-tools";

import {
  printSchema, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLString
} from "graphql";

const rawSchemas = {
  abi: require("@truffle/contract-schema/spec/abi.spec.json"),
  networkObject: require("@truffle/contract-schema/spec/network-object.spec.json"),
  contractObject: require("@truffle/contract-schema/spec/contract-object.spec.json"),
};

import { resolvers } from "./resolvers";

function searchReplace(predicate, func) {
  const search = (item) => {
    if (item instanceof Array) {
      return item.map(search);
    } else if (typeof item === "object") {
      return Object.assign(
        {}, ...Object.entries(item)
          .map(
            ([ key, value ]: any) => {
              return predicate(key, value)
                ? func(key, value)
                : { [key]: search(value) }
            }
          )
      );
    } else {
      return item;
    }
  }

  return search;
}

function convertToArray(schema, keyName = "key", valueName = "value") {
  const valueTypes = [
    ...Object.values(schema.patternProperties || {}),
    ...(schema.additionalProperties || [])
  ];

  if (!valueTypes.length) {
    return schema;
  }

  const valueType = (valueTypes.length > 1)
    ? { oneOf: valueTypes }
    : valueTypes[0];

  return {
    type: "array",
    items: {
      type: "object",
      properties: {
        [keyName]: { type: "string" },
        [valueName]: valueType
      }
    }
  }
}

function processSchema(name, schema) {
  const definitions = [
    ...Object.entries(schema.definitions)
      .map( ([ id, definition ]) => ({
        ...definition,

        "$id": id
      }))<commit_msg>Add some minimal typing to fix processSchema()<commit_after>const { default: convert } = require("@gnd/jsonschema2graphql");

import { makeExecutableSchema } from "@gnd/graphql-tools";

import {
  printSchema, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLString
} from "graphql";

const rawSchemas = {
  abi: require("@truffle/contract-schema/spec/abi.spec.json"),
  networkObject: require("@truffle/contract-schema/spec/network-object.spec.json"),
  contractObject: require("@truffle/contract-schema/spec/contract-object.spec.json"),
};

import { resolvers } from "./resolvers";

function searchReplace(predicate, func) {
  const search = (item) => {
    if (item instanceof Array) {
      return item.map(search);
    } else if (typeof item === "object") {
      return Object.assign(
        {}, ...Object.entries(item)
          .map(
            ([ key, value ]: any) => {
              return predicate(key, value)
                ? func(key, value)
                : { [key]: search(value) }
            }
          )
      );
    } else {
      return item;
    }
  }

  return search;
}

function convertToArray(schema, keyName = "key", valueName = "value") {
  const valueTypes = [
    ...Object.values(schema.patternProperties || {}),
    ...(schema.additionalProperties || [])
  ];

  if (!valueTypes.length) {
    return schema;
  }

  const valueType = (valueTypes.length > 1)
    ? { oneOf: valueTypes }
    : valueTypes[0];

  return {
    type: "array",
    items: {
      type: "object",
      properties: {
        [keyName]: { type: "string" },
        [valueName]: valueType
      }
    }
  }
}

interface SchemaDefinitions {
  [name: string]: {
    [k: string]: any;
  }
}

function processSchema(name, schema: { definitions: SchemaDefinitions }) {
  const definitions = [
    ...Object.entries(schema.definitions)
      .map( ([ id, definition ]) => ({
        ...definition,

        "$id": id
      }))
{'fraction_non_alphanumeric': 0.15432098765432098, 'fraction_numerical': 0.001610305958132045, 'mean_word_length': 2.5461465271170316, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7242252', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1148, 'n_words': 233}