Skip to content

Commit

Permalink
feat(bugs): cjs build and import alpha.13
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbeckers committed Nov 25, 2023
1 parent 15d3b45 commit 9443fe6
Show file tree
Hide file tree
Showing 42 changed files with 943 additions and 645 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"url": "git+https://github.com/hypercerts-org/hypercerts.git"
},
"overrides": {
"graphql": "^16.6.0",
"graphql": "^16.8.1",
"@hypercerts/contracts": {
"ethers": "6.8.0"
},
Expand Down
911 changes: 567 additions & 344 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sdk/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ parserOptions:
plugins:
- "@typescript-eslint"
root: true
ignorePatterns: ["rollup.config.js", "jest.config.ts", "dist/"]
ignorePatterns: ["rollup.config.js", "vitest.config.ts", "dist/"]
rules:
"@typescript-eslint/semi":
- warn
Expand Down
4 changes: 2 additions & 2 deletions sdk/.graphclientrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ additionalTypeDefs: |
}
additionalResolvers:
- ./src/utils/resolvers.ts
- src/utils/resolvers.ts

documents:
- ./src/indexer/queries/*.graphql
- src/indexer/queries/*.graphql

codegen:
contextType: "MeshContext & { graphName: string }"
Expand Down
1 change: 0 additions & 1 deletion sdk/global.d.ts

This file was deleted.

20 changes: 0 additions & 20 deletions sdk/jest.config.ts

This file was deleted.

29 changes: 10 additions & 19 deletions sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hypercerts-org/sdk",
"version": "1.0.0-alpha.10",
"version": "1.0.0-alpha.13",
"description": "SDK for hypercerts protocol",
"repository": "[email protected]:hypercerts-org/hypercerts.git",
"author": "Hypercerts team",
Expand All @@ -11,11 +11,9 @@
"module": "./dist/esm/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"types": "./dist/index.d.ts"
}
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"types": "./dist/index.d.ts"
},
"files": [
"dist",
Expand All @@ -26,6 +24,7 @@
"@ethereum-attestation-service/eas-sdk": "1.2.2-beta.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@graphprotocol/client-add-source-name": "^2.0.0",
"@graphprotocol/client-cli": "^3.0.0",
"@graphprotocol/client-polling-live": "^2.0.0",
"@graphql-mesh/cache-localforage": "^0.96.0",
"@graphql-mesh/cross-helpers": "^0.4.1",
Expand All @@ -34,7 +33,6 @@
"@graphql-mesh/merger-bare": "^0.95.7",
"@graphql-mesh/runtime": "^0.96.12",
"@graphql-mesh/store": "^0.95.7",
"@graphql-mesh/types": "^0.95.7",
"@graphql-mesh/utils": "^0.95.7",
"@graphql-typed-document-node/core": "^3.2.0",
"@hypercerts-org/contracts": "1.0.0-alpha.2",
Expand All @@ -57,8 +55,6 @@
"@babel/preset-env": "^7.23.2",
"@babel/preset-typescript": "^7.23.2",
"@faker-js/faker": "^8.0.2",
"@graphprotocol/client-cli": "^3.0.0",
"@jest/globals": "^29.7.0",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
Expand All @@ -70,17 +66,12 @@
"@types/sinon": "^10.0.15",
"@viem/anvil": "^0.0.6",
"abitype": "^0.10.2",
"babel-jest": "^29.7.0",
"chai": "^4.3.7",
"chai-assertions-count": "^1.0.2",
"chai-subset": "^1.6.0",
"esbuild": "^0.17.10",
"ethereum-waffle": "^4.0.10",
"fetch-mock": "^9.11.0",
"it-all": "^2.0.0",
"jest": "^29.3.1",
"jest-extended": "^4.0.0",
"jest-fetch-mock": "^3.0.3",
"json-schema-to-typescript": "^12.0.0",
"nyc": "^15.1.0",
"rollup": "^3.17.2",
Expand All @@ -90,28 +81,28 @@
"rollup-plugin-node-polyfills": "^0.2.1",
"shx": "^0.3.4",
"sinon": "^15.2.0",
"ts-jest": "^29.0.3",
"ts-jest-resolver": "^2.0.0",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.1",
"tslib": "^2.5.0",
"tsx": "^3.14.0",
"typedoc": "^0.23.25",
"typedoc-plugin-markdown": "^3.14.0",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "5.1.6"
"typescript": "5.1.6",
"vitest": "^0.28.4"
},
"scripts": {
"build": "pnpm types:json && pnpm graph:build:esm && rollup -c",
"build": "pnpm types:json && pnpm graph:build && rollup -c",
"docs": "typedoc",
"graph:compile": "graphql-codegen",
"graph:serve": "graphclient serve-dev",
"graph:watch": "graphql-codegen -w",
"graph:build": "rm -rf ./src/.graphclient && graphclient build --throwOnInvalidConfig",
"graph:build:esm": "rm -rf ./src/.graphclient && NODE_OPTIONS='--loader ts-node/esm' graphclient build --throwOnInvalidConfig",
"clean": "rm -rf ./dist",
"prebuild": "pnpm clean",
"prepack": "pnpm build",
"test": "NODE_OPTIONS=\"--no-warnings --experimental-vm-modules\" jest --detectOpenHandles --forceExit",
"test": "vitest",
"types:json": "pnpm json2ts -i './src/resources/schema/' -o 'src/types' --cwd './src/resources/schema'"
}
}
10 changes: 5 additions & 5 deletions sdk/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { HypercertMinterAbi } from "@hypercerts-org/contracts";
import { StandardMerkleTree } from "@openzeppelin/merkle-tree";
import { ByteArray, GetContractReturnType, Hex, PublicClient, WalletClient, getContract, parseAbi } from "viem";
import HypercertEvaluator from "./evaluations";
import HypercertIndexer from "./indexer";
import HypercertsStorage from "./storage";
import { HypercertEvaluator } from "./evaluations";
import { HypercertIndexer } from "./indexer";
import { HypercertsStorage } from "./storage";
import {
AllowlistEntry,
ClientError,
Expand All @@ -16,7 +16,7 @@ import {
TransferRestrictions,
} from "./types";
import { getConfig } from "./utils/config";
import logger from "./utils/logger";
import { logger } from "./utils";
import { validateAllowlist, validateMetaData, verifyMerkleProof, verifyMerkleProofs } from "./validator";

/**
Expand All @@ -33,7 +33,7 @@ import { validateAllowlist, validateMetaData, verifyMerkleProof, verifyMerklePro
*
* @param {Partial<HypercertClientConfig>} config - The configuration options for the client.
*/
export default class HypercertClient implements HypercertClientInterface {
export class HypercertClient implements HypercertClientInterface {
readonly _config;
private _storage: HypercertsStorage;
// TODO better handling readonly. For now not needed since we don't use this class;
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/evaluations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isAddress } from "viem";
// @ts-ignore
import { CIDString } from "nft.storage";

import HypercertsStorage from "../storage";
import { HypercertsStorage } from "../storage";
import { HypercertClientConfig, HypercertEvaluationSchema, MalformedDataError } from "../types";

export interface EvaluatorInterface {
Expand All @@ -15,7 +15,7 @@ export interface EvaluatorInterface {
submitEvaluation: (evaluation: HypercertEvaluationSchema) => Promise<CIDString>;
}

export default class HypercertEvaluator implements EvaluatorInterface {
export class HypercertEvaluator implements EvaluatorInterface {
storage: HypercertsStorage;

readonly = true;
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HypercertMinterAbi, HypercertExchangeAbi } from "@hypercerts-org/contracts";

import { execute } from "../.graphclient";
import HypercertClient from "./client";
import HypercertsStorage from "./storage";
import { HypercertClient } from "./client";
import { HypercertsStorage } from "./storage";
import { DEPLOYMENTS } from "./constants";

/**
Expand Down
96 changes: 68 additions & 28 deletions sdk/src/indexer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
import { logger } from "ethers";
import { getBuiltGraphSDK, Sdk as GraphClient } from "../.graphclient";
import { logger } from "./utils";
import {
getBuiltGraphSDK,
Sdk as GraphClient,
execute,
ClaimsByOwnerDocument,
ClaimsByOwnerQuery,
ClaimByIdDocument,
ClaimByIdQuery,
RecentClaimsDocument,
RecentClaimsQuery,
ClaimsByOwnerQueryVariables,
ClaimByIdQueryVariables,
RecentClaimsQueryVariables,
ClaimTokensByOwnerDocument,
ClaimTokensByOwnerQuery,
ClaimTokensByOwnerQueryVariables,
ClaimTokensByClaimDocument,
ClaimTokensByClaimQueryVariables,
ClaimTokensByClaimQuery,
ClaimTokenByIdDocument,
ClaimTokenByIdQueryVariables,
ClaimTokenByIdQuery,
} from "../.graphclient";
import { defaultQueryParams } from "./indexer/utils";
import { HypercertClientConfig, HypercertIndexerInterface, QueryParams } from "./types";

Expand All @@ -15,27 +37,28 @@ import { HypercertClientConfig, HypercertIndexerInterface, QueryParams } from ".
* const indexer = new HypercertIndexer({ graphUrl: 'your-graph-url', graphName: 'your-graph-name' });
* const claims = await indexer.claimsByOwner('your-address');
*/
export default class HypercertIndexer implements HypercertIndexerInterface {
export class HypercertIndexer implements HypercertIndexerInterface {
/** The Graph client used by the indexer. */
private _graphClient: GraphClient;
private _graphName: string;

/**
* Creates a new instance of the `HypercertIndexer` class.
* @param options The configuration options for the indexer.
*/
constructor(options: Partial<HypercertClientConfig>) {
logger.info("Creating HypercertIndexer", "constructor", options);
this._graphClient = getBuiltGraphSDK({
graphName: options.graphName,
});
logger.info("Creating HypercertIndexer", "constructor", { name: options.graphName, url: options.graphUrl });
if (!options.graphName) throw new Error("Missing graphName");
this._graphName = options.graphName;
}

/**
* Gets the Graph client used by the indexer.
* @returns The Graph client.
*/
get graphClient(): GraphClient {
return this._graphClient;
return getBuiltGraphSDK({
graphName: this._graphName,
});
}

/**
Expand All @@ -44,63 +67,80 @@ export default class HypercertIndexer implements HypercertIndexerInterface {
* @param params The query parameters.
* @returns A Promise that resolves to the claims.
*/
claimsByOwner = async (owner: string, params: QueryParams = defaultQueryParams) =>
this.graphClient.ClaimsByOwner({
claimsByOwner = async (owner: string, params: QueryParams = defaultQueryParams) => {
const query = ClaimsByOwnerDocument;
const variables: ClaimsByOwnerQueryVariables = {
owner,
...params,
});
};
return (await execute(query, variables, { graphName: this._graphName })) as ClaimsByOwnerQuery;
};

/**
* Gets a claim by its ID.
* @param id The ID of the claim.
* @returns A Promise that resolves to the claim.
*/
claimById = async (id: string) =>
this.graphClient.ClaimById({
claimById = async (id: string) => {
const query = ClaimByIdDocument;
const variables: ClaimByIdQueryVariables = {
id,
});

};
return (await execute(query, variables, { graphName: this._graphName })) as ClaimByIdQuery;
};
/**
* Gets the most recent claims.
* @param params The query parameters.
* @returns A Promise that resolves to the claims.
*/
firstClaims = async (params: QueryParams = defaultQueryParams) =>
this.graphClient.RecentClaims({
firstClaims = async (params: QueryParams = defaultQueryParams) => {
const query = RecentClaimsDocument;
const variables: RecentClaimsQueryVariables = {
...params,
});
};
return (await execute(query, variables, { graphName: this._graphName })) as RecentClaimsQuery;
};

/**
* Gets the claim tokens owned by a given address.
* @param owner The address of the owner.
* @param params The query parameters.
* @returns A Promise that resolves to the claim tokens.
*/
fractionsByOwner = async (owner: string, params: QueryParams = defaultQueryParams) =>
this.graphClient.ClaimTokensByOwner({
fractionsByOwner = async (owner: string, params: QueryParams = defaultQueryParams) => {
const query = ClaimTokensByOwnerDocument;
const variables: ClaimTokensByOwnerQueryVariables = {
owner,
...params,
});
};
return (await execute(query, variables, { graphName: this._graphName })) as ClaimTokensByOwnerQuery;
};

/**
* Gets the claim tokens for a given claim.
* @param claimId The ID of the claim.
* @param params The query parameters.
* @returns A Promise that resolves to the claim tokens.
*/
fractionsByClaim = async (claimId: string, params: QueryParams = defaultQueryParams) =>
this.graphClient.ClaimTokensByClaim({
fractionsByClaim = async (claimId: string, params: QueryParams = defaultQueryParams) => {
const query = ClaimTokensByClaimDocument;
const variables: ClaimTokensByClaimQueryVariables = {
claimId,
...params,
});
};
return (await execute(query, variables, { graphName: this._graphName })) as ClaimTokensByClaimQuery;
};

/**
* Gets a claim token by its ID.
* @param fractionId The ID of the claim token.
* @returns A Promise that resolves to the claim token.
*/
fractionById = async (fractionId: string) =>
this.graphClient.ClaimTokenById({
fractionById = async (fractionId: string) => {
const query = ClaimTokenByIdDocument;
const variables: ClaimTokenByIdQueryVariables = {
claimTokenId: fractionId,
});
};
return (await execute(query, variables, { graphName: this._graphName })) as ClaimTokenByIdQuery;
};
}
Loading

0 comments on commit 9443fe6

Please sign in to comment.