UNPKG

3.82 kBPlain TextView Raw
1// Side-effect to evaluate eagerly the offset of stub AS runtime
2import './common/eager_offset';
3import { ByteArray, Bytes, Entity } from './common/collections';
4import { Value } from './common/value';
5// Arweave support
6export * from './chain/arweave';
7// Ethereum support
8export * from './chain/ethereum';
9// NEAR support
10export * from './chain/near';
11// Cosmos support
12export * from './chain/cosmos';
13// Regular re-exports
14export * from './common/collections';
15export * from './common/conversion';
16export * from './common/datasource';
17export * from './common/json';
18export * from './common/numbers';
19export * from './common/value';
20
21/**
22 * Host store interface.
23 */
24export declare namespace store {
25 function get(entity: string, id: string): Entity | null;
26 function set(entity: string, id: string, data: Entity): void;
27 function remove(entity: string, id: string): void;
28}
29
30/** Host IPFS interface */
31export declare namespace ipfs {
32 function cat(hash: string): Bytes | null;
33 function map(hash: string, callback: string, userData: Value, flags: string[]): void;
34}
35
36export namespace ipfs {
37 export function mapJSON(hash: string, callback: string, userData: Value): void {
38 ipfs.map(hash, callback, userData, ['json']);
39 }
40}
41
42/** Host crypto utilities interface */
43export declare namespace crypto {
44 function keccak256(input: ByteArray): ByteArray;
45}
46
47/**
48 * Special function for ENS name lookups, not meant for general purpose use.
49 * This function will only be useful if the graph-node instance has additional
50 * data loaded **
51 */
52export declare namespace ens {
53 function nameByHash(hash: string): string | null;
54}
55
56function format(fmt: string, args: string[]): string {
57 let out = '';
58 let argIndex = 0;
59 for (let i: i32 = 0, len: i32 = fmt.length; i < len; i++) {
60 if (
61 i < len - 1 &&
62 fmt.charCodeAt(i) == 0x7b /* '{' */ &&
63 fmt.charCodeAt(i + 1) == 0x7d /* '}' */
64 ) {
65 if (argIndex >= args.length) {
66 throw new Error('Too few arguments for format string: ' + fmt);
67 } else {
68 out += args[argIndex++];
69 i++;
70 }
71 } else {
72 out += fmt.charAt(i);
73 }
74 }
75 return out;
76}
77
78// Host interface for logging
79export declare namespace log {
80 // Host export for logging, providing basic logging functionality
81 export function log(level: Level, msg: string): void;
82}
83
84export namespace log {
85 export enum Level {
86 CRITICAL = 0,
87 ERROR = 1,
88 WARNING = 2,
89 INFO = 3,
90 DEBUG = 4,
91 }
92
93 /**
94 * Logs a critical message that terminates the subgraph.
95 *
96 * @param msg Format string a la "Value = {}, other = {}".
97 * @param args Format string arguments.
98 */
99 export function critical(msg: string, args: Array<string>): void {
100 log.log(Level.CRITICAL, format(msg, args));
101 }
102
103 /**
104 * Logs an error message.
105 *
106 * @param msg Format string a la "Value = {}, other = {}".
107 * @param args Format string arguments.
108 */
109 export function error(msg: string, args: Array<string>): void {
110 log.log(Level.ERROR, format(msg, args));
111 }
112
113 /** Logs a warning message.
114 *
115 * @param msg Format string a la "Value = {}, other = {}".
116 * @param args Format string arguments.
117 */
118 export function warning(msg: string, args: Array<string>): void {
119 log.log(Level.WARNING, format(msg, args));
120 }
121
122 /** Logs an info message.
123 *
124 * @param msg Format string a la "Value = {}, other = {}".
125 * @param args Format string arguments.
126 */
127 export function info(msg: string, args: Array<string>): void {
128 log.log(Level.INFO, format(msg, args));
129 }
130
131 /** Logs a debug message.
132 *
133 * @param msg Format string a la "Value = {}, other = {}".
134 * @param args Format string arguments.
135 */
136 export function debug(msg: string, args: Array<string>): void {
137 log.log(Level.DEBUG, format(msg, args));
138 }
139}