mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-09 01:04:07 +00:00
Implement remaining json host APIs (#487)
* Instantiate a new wasm string to convert JSON value to BigInt * Implement remaining json host APIs * Upgrade graph-ts and graph-cli in test example subgraph * Handle null context for dataSource context host API * Use JSONBig for parsing JSON strings
This commit is contained in:
@@ -20,20 +20,17 @@ import { RawSqlResultsToEntityTransformer } from 'typeorm/query-builder/transfor
|
||||
import { SelectionNode } from 'graphql';
|
||||
import _ from 'lodash';
|
||||
import debug from 'debug';
|
||||
import JSONbig from 'json-bigint';
|
||||
|
||||
import { Database as BaseDatabase, QueryOptions, Where, CanonicalBlockHeight } from '../database';
|
||||
import { BlockProgressInterface } from '../types';
|
||||
import { cachePrunedEntitiesCount, eventProcessingLoadEntityCacheHitCount, eventProcessingLoadEntityCount, eventProcessingLoadEntityDBQueryDuration } from '../metrics';
|
||||
import { ServerConfig } from '../config';
|
||||
import { Block, formatValue, fromEntityValue, getLatestEntityFromEntity, parseEntityValue, resolveEntityFieldConflicts, toEntityValue } from './utils';
|
||||
import { Block, formatValue, fromEntityValue, getLatestEntityFromEntity, parseEntityValue, resolveEntityFieldConflicts, toEntityValue, JSONbigNative } from './utils';
|
||||
import { fromStateEntityValues } from './state-utils';
|
||||
import { ValueKind } from './types';
|
||||
|
||||
const log = debug('vulcanize:graph-database');
|
||||
|
||||
const JSONbigNative = JSONbig({ useNativeBigInt: true });
|
||||
|
||||
export const FILTER_CHANGE_BLOCK = '_change_block';
|
||||
|
||||
export const DEFAULT_LIMIT = 100;
|
||||
@@ -962,7 +959,7 @@ export class GraphDatabase {
|
||||
const contextInstance = await Entity.__new();
|
||||
|
||||
const { __newString } = instanceExports;
|
||||
const contextValuePromises = Object.entries(contextData as Record<string, { type: ValueKind, data: any }>).map(async ([key, { type, data }]) => {
|
||||
const contextValuePromises = Object.entries((contextData ?? {}) as Record<string, { type: ValueKind, data: any }>).map(async ([key, { type, data }]) => {
|
||||
const contextKey = await __newString(key);
|
||||
|
||||
const value = JSONbigNative.parse(data);
|
||||
|
||||
@@ -7,6 +7,7 @@ import { DeepPartial, EntityTarget, InsertEvent, ObjectLiteral, Repository, Upda
|
||||
import { ColumnMetadata } from 'typeorm/metadata/ColumnMetadata';
|
||||
import assert from 'assert';
|
||||
import _ from 'lodash';
|
||||
import JSONbig from 'json-bigint';
|
||||
|
||||
import { MappingKey, StorageLayout } from '@cerc-io/solidity-mapper';
|
||||
|
||||
@@ -14,6 +15,7 @@ import { GraphDecimal } from './graph-decimal';
|
||||
import { EthereumValueKind, TypeId, TypeNameToValueKind, ValueKind } from './types';
|
||||
|
||||
const log = debug('vulcanize:utils');
|
||||
export const JSONbigNative = JSONbig({ useNativeBigInt: true });
|
||||
|
||||
export const INT256_MIN = '-57896044618658097711785492504343953926634992332820282019728792003956564819968';
|
||||
export const INT256_MAX = '57896044618658097711785492504343953926634992332820282019728792003956564819967';
|
||||
@@ -762,7 +764,7 @@ export const toJSONValue = async (instanceExports: any, value: any): Promise<any
|
||||
return CustomJSONValue.fromString(stringPtr);
|
||||
}
|
||||
|
||||
if (typeof value === 'number') {
|
||||
if (typeof value === 'number' || typeof value === 'bigint') {
|
||||
const stringPtr = await __newString(value.toString());
|
||||
|
||||
return CustomJSONValue.fromNumber(stringPtr);
|
||||
@@ -778,7 +780,7 @@ export const jsonFromBytes = async (instanceExports: any, bytesPtr: number): Pro
|
||||
|
||||
const byteArray = await ByteArray.wrap(bytesPtr);
|
||||
const jsonStringPtr = await byteArray.toString();
|
||||
const json = JSON.parse(__getString(jsonStringPtr));
|
||||
const json = JSONbigNative.parse(__getString(jsonStringPtr));
|
||||
const jsonValue = await toJSONValue(instanceExports, json);
|
||||
|
||||
return jsonValue;
|
||||
|
||||
Reference in New Issue
Block a user