UNPKG

@verax-attestation-registry/verax-sdk

Version:

Verax Attestation Registry SDK to interact with the subgraph and the contracts

154 lines 6.25 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.subscribe = exports.execute = exports.getBuiltGraphClient = exports.pollingInterval = exports.createBuiltMeshHTTPHandler = exports.getMeshOptions = exports.rawServeConfig = void 0; const utils_1 = require("@graphql-mesh/utils"); const utils_2 = require("@graphql-mesh/utils"); const cache_localforage_1 = __importDefault(require("@graphql-mesh/cache-localforage")); const fetch_1 = require("@whatwg-node/fetch"); const graphql_1 = __importDefault(require("@graphql-mesh/graphql")); const merger_bare_1 = __importDefault(require("@graphql-mesh/merger-bare")); const http_1 = require("@graphql-mesh/http"); const runtime_1 = require("@graphql-mesh/runtime"); const store_1 = require("@graphql-mesh/store"); const cross_helpers_1 = require("@graphql-mesh/cross-helpers"); const importedModule$0 = __importStar(require("./sources/linea-attestation-registry/introspectionSchema")); const baseDir = cross_helpers_1.path.join(typeof __dirname === 'string' ? __dirname : '/', '..'); const importFn = (moduleId) => { const relativeModuleId = (cross_helpers_1.path.isAbsolute(moduleId) ? cross_helpers_1.path.relative(baseDir, moduleId) : moduleId).split('\\').join('/').replace(baseDir + '/', ''); switch (relativeModuleId) { case ".graphclient/sources/linea-attestation-registry/introspectionSchema": return Promise.resolve(importedModule$0); default: return Promise.reject(new Error(`Cannot find module '${relativeModuleId}'.`)); } }; const rootStore = new store_1.MeshStore('.graphclient', new store_1.FsStoreStorageAdapter({ cwd: baseDir, importFn, fileType: "ts", }), { readonly: true, validate: false }); exports.rawServeConfig = undefined; async function getMeshOptions() { const pubsub = new utils_1.PubSub(); const sourcesStore = rootStore.child('sources'); const logger = new utils_2.DefaultLogger("GraphClient"); const cache = new cache_localforage_1.default({ ...{}, importFn, store: rootStore.child('cache'), pubsub, logger, }); const sources = []; const transforms = []; const additionalEnvelopPlugins = []; const lineaAttestationRegistryTransforms = []; const additionalTypeDefs = []; const lineaAttestationRegistryHandler = new graphql_1.default({ name: "linea-attestation-registry", config: { "endpoint": "https://api.studio.thegraph.com/query/67521/verax-v2-linea/v0.0.1" }, baseDir, cache, pubsub, store: sourcesStore.child("linea-attestation-registry"), logger: logger.child("linea-attestation-registry"), importFn, }); sources[0] = { name: 'linea-attestation-registry', handler: lineaAttestationRegistryHandler, transforms: lineaAttestationRegistryTransforms }; const additionalResolvers = []; const merger = new merger_bare_1.default({ cache, pubsub, logger: logger.child('bareMerger'), store: rootStore.child('bareMerger') }); return { sources, transforms, additionalTypeDefs, additionalResolvers, cache, pubsub, merger, logger, additionalEnvelopPlugins, get documents() { return []; }, fetchFn: fetch_1.fetch, }; } exports.getMeshOptions = getMeshOptions; function createBuiltMeshHTTPHandler() { return (0, http_1.createMeshHTTPHandler)({ baseDir, getBuiltMesh: getBuiltGraphClient, rawServeConfig: undefined, }); } exports.createBuiltMeshHTTPHandler = createBuiltMeshHTTPHandler; let meshInstance$; exports.pollingInterval = null; function getBuiltGraphClient() { if (meshInstance$ == null) { if (exports.pollingInterval) { setInterval(() => { getMeshOptions() .then(meshOptions => (0, runtime_1.getMesh)(meshOptions)) .then(newMesh => meshInstance$.then(oldMesh => { oldMesh.destroy(); meshInstance$ = Promise.resolve(newMesh); })).catch(err => { console.error("Mesh polling failed so the existing version will be used:", err); }); }, exports.pollingInterval); } meshInstance$ = getMeshOptions().then(meshOptions => (0, runtime_1.getMesh)(meshOptions)).then(mesh => { const id = mesh.pubsub.subscribe('destroy', () => { meshInstance$ = undefined; mesh.pubsub.unsubscribe(id); }); return mesh; }); } return meshInstance$; } exports.getBuiltGraphClient = getBuiltGraphClient; const execute = (...args) => getBuiltGraphClient().then(({ execute }) => execute(...args)); exports.execute = execute; const subscribe = (...args) => getBuiltGraphClient().then(({ subscribe }) => subscribe(...args)); exports.subscribe = subscribe; //# sourceMappingURL=index.js.map