mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-05-01 18:51:15 +00:00
* Add a CLI to fill state for a given range * Refactor code * Add a CLI to reset IPLD state * Replace ORDER BY clause in the query to get latest IPLD block * Optimize delete query in CLI to reset IPLD state * Add an option to decouple subgraph state creation from mapping code * Use a raw SQL query to delete IPLD blocks in a block range * Accomodate changes in codegen
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
//
|
|
// Copyright 2021 Vulcanize, Inc.
|
|
//
|
|
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import Handlebars from 'handlebars';
|
|
import { Writable } from 'stream';
|
|
|
|
const FILL_TEMPLATE_FILE = './templates/fill-template.handlebars';
|
|
const FILL_STATE_TEMPLATE_FILE = './templates/fill-state-template.handlebars';
|
|
|
|
/**
|
|
* Writes the fill file generated from a template to a stream.
|
|
* @param fillOutStream A writable output stream to write the fill file to.
|
|
* @param fillStateOutStream A writable output stream to write the fill state file to.
|
|
*/
|
|
export function exportFill (fillOutStream: Writable, fillStateOutStream: Writable | undefined, subgraphPath: string): void {
|
|
const templateString = fs.readFileSync(path.resolve(__dirname, FILL_TEMPLATE_FILE)).toString();
|
|
const template = Handlebars.compile(templateString);
|
|
const fill = template({ subgraphPath });
|
|
fillOutStream.write(fill);
|
|
|
|
if (fillStateOutStream) {
|
|
const templateString = fs.readFileSync(path.resolve(__dirname, FILL_STATE_TEMPLATE_FILE)).toString();
|
|
const template = Handlebars.compile(templateString);
|
|
const fillState = template({});
|
|
fillStateOutStream.write(fillState);
|
|
}
|
|
}
|