Skip to content

Commit

Permalink
merge prealpha-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dOrgJelli committed Mar 22, 2022
2 parents 62fcaaa + 4662b68 commit 4cbd20e
Show file tree
Hide file tree
Showing 199 changed files with 7,287 additions and 776 deletions.
38 changes: 38 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
# Default
* @dOrgJelli

# Wasm Runtime
packages/wasm/as @dOrgJelli @krisbitney @namesty @Niraj-Kamdar

# Schema
packages/schema/parse @dOrgJelli @namesty @nerfZael @Niraj-Kamdar
packages/schema/compose @dOrgJelli @namesty @nerfZael @Niraj-Kamdar
packages/schema/bind @dOrgJelli @krisbitney @nerfZael @Niraj-Kamdar

# Project Manifests
packages/manifest-schemas/ @dOrgJelli

# CLI
packages/js/cli @dOrgJelli @krisbitney @namesty @nerfZael @Niraj-Kamdar

# Client Interfaces
packages/core-interfaces @dOrgJelli

# JS Client
packages/js/client @dOrgJelli @krisbitney @namesty @nerfZael
packages/js/react @dOrgJelli @nerfZael
packages/js/core @dOrgJelli @krisbitney @namesty @nerfZael
packages/js/os @dOrgJelli
packages/js/asyncify @namesty @dOrgJelli
packages/js/tracing @dOrgJelli @Niraj-Kamdar
packages/js/test-env @dOrgJelli

# JS Plugins
packages/js/plugins/ens @dOrgJelli @krisbitney
packages/js/plugins/ethereum @dOrgJelli @krisbitney @namesty
packages/js/plugins/filesystem @krisbitney @dOrgJelli @Niraj-Kamdar
packages/js/plugins/graph-node @namesty
packages/js/plugins/http @dOrgJelli @ramilexe
packages/js/plugins/ipfs @dOrgJelli @krisbitney @nerfZael
packages/js/plugins/logger @dOrgJelli @nerfZael
packgaes/js/plugins/sha3 @namesty @dOrgJelli @krisbitney
packages/js/plugins/uts46 @namesty @dOrgJelli @krisbitney
10 changes: 7 additions & 3 deletions packages/cli/src/__tests__/plugin/expected-build/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ scalar Int32
scalar Bytes
scalar BigInt
scalar JSON
scalar Map

directive @imported(
uri: String!
Expand All @@ -28,6 +29,9 @@ directive @capability(
) repeatable on OBJECT

directive @enabled_interface on OBJECT

directive @annotate(type: String!) on FIELD

### Web3API Header END ###

type Query @imports(
Expand Down Expand Up @@ -283,7 +287,7 @@ type Ethereum_TxRequest @imported(
gasPrice: BigInt
data: String
value: BigInt
chainId: UInt32
chainId: BigInt
type: UInt32
}

Expand Down Expand Up @@ -343,7 +347,7 @@ type Ethereum_Network @imported(
nativeType: "Network"
) {
name: String!
chainId: Int!
chainId: BigInt!
ensAddress: String
}

Expand All @@ -360,7 +364,7 @@ type Ethereum_TxResponse @imported(
gasPrice: BigInt
data: String!
value: BigInt!
chainId: UInt32!
chainId: BigInt!
blockNumber: BigInt
blockHash: String
timestamp: UInt32
Expand Down
10 changes: 7 additions & 3 deletions packages/cli/src/__tests__/plugin/expected-types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ scalar Int32
scalar Bytes
scalar BigInt
scalar JSON
scalar Map
directive @imported(
uri: String!
Expand All @@ -28,6 +29,9 @@ directive @capability(
) repeatable on OBJECT
directive @enabled_interface on OBJECT
directive @annotate(type: String!) on FIELD
### Web3API Header END ###
type Query @imports(
Expand Down Expand Up @@ -283,7 +287,7 @@ type Ethereum_TxRequest @imported(
gasPrice: BigInt
data: String
value: BigInt
chainId: UInt32
chainId: BigInt
type: UInt32
}
Expand Down Expand Up @@ -343,7 +347,7 @@ type Ethereum_Network @imported(
nativeType: "Network"
) {
name: String!
chainId: Int!
chainId: BigInt!
ensAddress: String
}
Expand All @@ -360,7 +364,7 @@ type Ethereum_TxResponse @imported(
gasPrice: BigInt
data: String!
value: BigInt!
chainId: UInt32!
chainId: BigInt!
blockNumber: BigInt
blockHash: String
timestamp: UInt32
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/__tests__/plugin/expected-types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface Ethereum_TxRequest {
gasPrice?: BigInt | null;
data?: String | null;
value?: BigInt | null;
chainId?: UInt32 | null;
chainId?: BigInt | null;
type?: UInt32 | null;
}

Expand Down Expand Up @@ -104,7 +104,7 @@ export interface Ethereum_EventNotification {
/* URI: "ens/ethereum.web3api.eth" */
export interface Ethereum_Network {
name: String;
chainId: Int;
chainId: BigInt;
ensAddress?: String | null;
}

Expand All @@ -118,7 +118,7 @@ export interface Ethereum_TxResponse {
gasPrice?: BigInt | null;
data: String;
value: BigInt;
chainId: UInt32;
chainId: BigInt;
blockNumber?: BigInt | null;
blockHash?: String | null;
timestamp?: UInt32 | null;
Expand Down
26 changes: 19 additions & 7 deletions packages/cli/src/__tests__/project/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ scalar Int32
scalar Bytes
scalar BigInt
scalar JSON
scalar Map
directive @imported(
uri: String!
Expand All @@ -30,6 +31,9 @@ directive @capability(
) repeatable on OBJECT
directive @enabled_interface on OBJECT
directive @annotate(type: String!) on FIELD
### Web3API Header END ###
type Query @imports(
Expand Down Expand Up @@ -205,7 +209,7 @@ type Ethereum_TxRequest @imported(
gasPrice: BigInt
data: String
value: BigInt
chainId: UInt32
chainId: BigInt
type: UInt32
}
Expand Down Expand Up @@ -265,7 +269,7 @@ type Ethereum_Network @imported(
nativeType: "Network"
) {
name: String!
chainId: Int!
chainId: BigInt!
ensAddress: String
}
Expand All @@ -284,6 +288,7 @@ scalar Int32
scalar Bytes
scalar BigInt
scalar JSON
scalar Map
directive @imported(
uri: String!
Expand All @@ -302,6 +307,9 @@ directive @capability(
) repeatable on OBJECT
directive @enabled_interface on OBJECT
directive @annotate(type: String!) on FIELD
### Web3API Header END ###
type Mutation @imports(
Expand Down Expand Up @@ -424,7 +432,7 @@ type Ethereum_TxResponse @imported(
gasPrice: BigInt
data: String!
value: BigInt!
chainId: UInt32!
chainId: BigInt!
blockNumber: BigInt
blockHash: String
timestamp: UInt32
Expand Down Expand Up @@ -498,7 +506,7 @@ type Ethereum_TxRequest @imported(
gasPrice: BigInt
data: String
value: BigInt
chainId: UInt32
chainId: BigInt
type: UInt32
}
Expand All @@ -517,6 +525,7 @@ scalar Int32
scalar Bytes
scalar BigInt
scalar JSON
scalar Map
directive @imported(
uri: String!
Expand All @@ -535,6 +544,9 @@ directive @capability(
) repeatable on OBJECT
directive @enabled_interface on OBJECT
directive @annotate(type: String!) on FIELD
### Web3API Header END ###
type Query @imports(
Expand Down Expand Up @@ -792,7 +804,7 @@ type Ethereum_TxRequest @imported(
gasPrice: BigInt
data: String
value: BigInt
chainId: UInt32
chainId: BigInt
type: UInt32
}
Expand Down Expand Up @@ -852,7 +864,7 @@ type Ethereum_Network @imported(
nativeType: "Network"
) {
name: String!
chainId: Int!
chainId: BigInt!
ensAddress: String
}
Expand All @@ -869,7 +881,7 @@ type Ethereum_TxResponse @imported(
gasPrice: BigInt
data: String!
value: BigInt!
chainId: UInt32!
chainId: BigInt!
blockNumber: BigInt
blockHash: String
timestamp: UInt32
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/lib/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,13 +580,19 @@ export class Compiler {
__w3_subinvoke_result: () => {},
__w3_subinvoke_error_len: () => {},
__w3_subinvoke_error: () => {},
__w3_subinvokeImplementation: () => {},
__w3_subinvokeImplementation_result_len: () => {},
__w3_subinvokeImplementation_result: () => {},
__w3_subinvokeImplementation_error_len: () => {},
__w3_subinvokeImplementation_error: () => {},
__w3_invoke_args: () => {},
__w3_invoke_result: () => {},
__w3_invoke_error: () => {},
__w3_getImplementations: () => {},
__w3_getImplementations_result_len: () => {},
__w3_getImplementations_result: () => {},
__w3_abort: () => {},
__w3_debug_log: () => {},
__w3_load_env: () => {},
__w3_sanitize_env_args: () => {},
__w3_sanitize_env_result: () => {},
Expand Down
1 change: 0 additions & 1 deletion packages/js/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"test:watch": "jest --watch --passWithNoTests --verbose --detectOpenHandles"
},
"dependencies": {
"@msgpack/msgpack": "2.3.0",
"@web3api/asyncify-js": "0.0.1-prealpha.68",
"@web3api/core-js": "0.0.1-prealpha.68",
"@web3api/ens-plugin-js": "0.0.1-prealpha.68",
Expand Down
64 changes: 61 additions & 3 deletions packages/js/client/src/Web3ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export class Web3ApiClient implements Client {

this._validateConfig();

this._sanitizeConfig();

Tracer.setAttribute("config", this._config);
} catch (error) {
Tracer.recordException(error);
Expand Down Expand Up @@ -362,9 +364,7 @@ export class Web3ApiClient implements Client {
if (freq && (freq.ms || freq.sec || freq.min || freq.hours)) {
frequency =
(freq.ms ?? 0) +
((freq.hours ?? 0) * 3600 +
(freq.min ?? 0) * 60 +
(freq.sec ?? 0)) *
((freq.hours ?? 0) * 3600 + (freq.min ?? 0) * 60 + (freq.sec ?? 0)) *
1000;
} else {
frequency = 60000;
Expand Down Expand Up @@ -525,6 +525,64 @@ export class Web3ApiClient implements Client {
}
}

@Tracer.traceMethod("Web3ApiClient: sanitizeConfig")
private _sanitizeConfig(): void {
this._sanitizeInterfacesAndImplementations();
}

// Make sure interface URIs are unique and that all of their implementation URIs are unique
// If not, then merge them
@Tracer.traceMethod("Web3ApiClient: sanitizeInterfacesAndImplementations")
private _sanitizeInterfacesAndImplementations(): void {
const interfaces = this._config.interfaces;
// Interface hash map used to keep track of interfaces with same URI
// A set is used to keep track of unique implementation URIs
const addedInterfacesHashMap = new Map<string, Set<string>>();

for (const interfaceImplementations of interfaces) {
const interfaceUri = interfaceImplementations.interface.uri;

if (!addedInterfacesHashMap.has(interfaceUri)) {
// If the interface is not added yet then just add it along with its implementations
addedInterfacesHashMap.set(
interfaceUri,
new Set(interfaceImplementations.implementations.map((x) => x.uri))
);
} else {
const existingInterfaceImplementations = addedInterfacesHashMap.get(
interfaceUri
) as Set<string>;

// Get implementations to add to existing set of implementations
const newImplementationUris = interfaceImplementations.implementations.map(
(x) => x.uri
);

// Add new implementations to existing set
newImplementationUris.forEach(
existingInterfaceImplementations.add,
existingInterfaceImplementations
);
}
}

// Collection of unique interfaces with implementations merged
const sanitizedInterfaces: InterfaceImplementations<Uri>[] = [];

// Go through the unique hash map of interfaces and implementations and add them to the sanitized interfaces
for (const [
interfaceUri,
implementationSet,
] of addedInterfacesHashMap.entries()) {
sanitizedInterfaces.push({
interface: new Uri(interfaceUri),
implementations: [...implementationSet].map((x) => new Uri(x)),
});
}

this._config.interfaces = sanitizedInterfaces;
}

@Tracer.traceMethod("Web3ApiClient: validateConfig")
private _validateConfig(): void {
// Require plugins to use non-interface URIs
Expand Down
Loading

0 comments on commit 4cbd20e

Please sign in to comment.