From ebf6541851549acd23cae541d91bd8f3c9d6f11b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Fri, 17 Jun 2022 12:02:44 +0200 Subject: [PATCH 01/23] separate ipfs plugin and ipfs-resolver plugin, add ipfs plugin interface --- package.json | 4 +- packages/core-interfaces/ipfs/.gitignore | 3 + packages/core-interfaces/ipfs/.nvmrc | 1 + packages/core-interfaces/ipfs/README.md | 1 + packages/core-interfaces/ipfs/package.json | 18 +++ .../core-interfaces/ipfs/src/schema.graphql | 34 +++++ .../core-interfaces/ipfs/web3api.deploy.yaml | 5 + packages/core-interfaces/ipfs/web3api.yaml | 5 + packages/js/client/package.json | 1 + .../src/__tests__/core/plugin-wrapper.spec.ts | 1 + .../src/__tests__/core/resolveUri.spec.ts | 12 +- .../client/src/__tests__/core/sanity.spec.ts | 9 +- .../js/client/src/default-client-config.ts | 10 +- packages/js/plugins/ipfs/src/index.ts | 113 ++++----------- packages/js/plugins/ipfs/src/schema.graphql | 40 +----- packages/js/plugins/ipfs/src/w3-man/index.ts | 9 -- .../js/plugins/ipfs/src/w3-man/manifest.ts | 11 -- packages/js/plugins/ipfs/src/w3-man/module.ts | 60 -------- packages/js/plugins/ipfs/src/w3-man/schema.ts | 130 ----------------- packages/js/plugins/ipfs/src/w3-man/types.ts | 97 ------------- packages/js/plugins/ipfs/web3api.plugin.yaml | 4 +- .../uri-resolvers/ipfs-resolver/README.md | 1 + .../ipfs-resolver/jest.config.js | 13 ++ .../uri-resolvers/ipfs-resolver/package.json | 44 ++++++ .../ipfs-resolver/src/__tests__/e2e.spec.ts | 5 + .../uri-resolvers/ipfs-resolver/src/index.ts | 135 ++++++++++++++++++ .../ipfs-resolver/src/schema.graphql | 12 ++ .../ipfs-resolver/tsconfig.build.json | 9 ++ .../uri-resolvers/ipfs-resolver/tsconfig.json | 10 ++ .../ipfs-resolver/web3api.plugin.yaml | 10 ++ yarn.lock | 76 +++++----- 31 files changed, 399 insertions(+), 484 deletions(-) create mode 100644 packages/core-interfaces/ipfs/.gitignore create mode 100644 packages/core-interfaces/ipfs/.nvmrc create mode 100644 packages/core-interfaces/ipfs/README.md create mode 100644 packages/core-interfaces/ipfs/package.json create mode 100644 packages/core-interfaces/ipfs/src/schema.graphql create mode 100644 packages/core-interfaces/ipfs/web3api.deploy.yaml create mode 100644 packages/core-interfaces/ipfs/web3api.yaml delete mode 100644 packages/js/plugins/ipfs/src/w3-man/index.ts delete mode 100644 packages/js/plugins/ipfs/src/w3-man/manifest.ts delete mode 100644 packages/js/plugins/ipfs/src/w3-man/module.ts delete mode 100644 packages/js/plugins/ipfs/src/w3-man/schema.ts delete mode 100644 packages/js/plugins/ipfs/src/w3-man/types.ts create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/README.md create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/jest.config.js create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/package.json create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/schema.graphql create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/tsconfig.build.json create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/tsconfig.json create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/web3api.plugin.yaml diff --git a/package.json b/package.json index 4fd8927b3d..fb925a7641 100644 --- a/package.json +++ b/package.json @@ -28,11 +28,11 @@ "preinstall": "yarn dependencies:install", "build": "yarn build:core && yarn build:plugins && yarn build:client && yarn build:test-env && yarn build:cli && yarn build:plugins:patch", "build:core": "lerna run build --no-private --ignore @web3api/*-plugin-js --ignore @web3api/cli* --ignore @web3api/react --ignore @web3api/test-env-js", - "build:plugins": "lerna run build --scope @web3api/*-plugin-js --concurrency 1", + "build:plugins": "lerna run build --scope @web3api/*-plugin-js --ignore @web3api/ipfs-resolver-plugin-js --concurrency 1", "build:client": "lerna run build --scope @web3api/client-js --scope @web3api/react", "build:test-env": "lerna run build --scope @web3api/test-env-js", "build:cli": "lerna run build --scope @web3api/cli", - "build:plugins:patch": "lerna run codegen:patch --scope @web3api/*-plugin-js --concurrency 1", + "build:plugins:patch": "lerna run codegen:patch --scope @web3api/*-plugin-js --ignore @web3api/ipfs-resolver-plugin-js --concurrency 1", "lint": "lerna run lint", "lint:fix": "lerna run lint -- --fix", "lint:ci": "yarn lint", diff --git a/packages/core-interfaces/ipfs/.gitignore b/packages/core-interfaces/ipfs/.gitignore new file mode 100644 index 0000000000..1e8f0fdefe --- /dev/null +++ b/packages/core-interfaces/ipfs/.gitignore @@ -0,0 +1,3 @@ +build +node_modules +w3 diff --git a/packages/core-interfaces/ipfs/.nvmrc b/packages/core-interfaces/ipfs/.nvmrc new file mode 100644 index 0000000000..5dbac1ed0f --- /dev/null +++ b/packages/core-interfaces/ipfs/.nvmrc @@ -0,0 +1 @@ +v16.13.0 \ No newline at end of file diff --git a/packages/core-interfaces/ipfs/README.md b/packages/core-interfaces/ipfs/README.md new file mode 100644 index 0000000000..30404ce4c5 --- /dev/null +++ b/packages/core-interfaces/ipfs/README.md @@ -0,0 +1 @@ +TODO \ No newline at end of file diff --git a/packages/core-interfaces/ipfs/package.json b/packages/core-interfaces/ipfs/package.json new file mode 100644 index 0000000000..855c67fbed --- /dev/null +++ b/packages/core-interfaces/ipfs/package.json @@ -0,0 +1,18 @@ +{ + "name": "@webapi3/ipfs-interface", + "description": "Web3API Ipfs Interface", + "private": true, + "version": "0.0.1-prealpha.85", + "scripts": { + "build": "rimraf ./build && node ../../../dependencies/node_modules/@web3api/cli/bin/w3 build", + "build:patch": "rimraf ./build && node ../../cli/bin/w3 build", + "lint": "eslint --color -c ../../../.eslintrc.js .", + "test:env:up": "npx w3 test-env up", + "test:env:down": "npx w3 test-env down", + "deploy": "npx w3 deploy" + }, + "devDependencies": { + "@web3api/client-js": "0.0.1-prealpha.85", + "rimraf": "3.0.2" + } +} diff --git a/packages/core-interfaces/ipfs/src/schema.graphql b/packages/core-interfaces/ipfs/src/schema.graphql new file mode 100644 index 0000000000..10c01b694a --- /dev/null +++ b/packages/core-interfaces/ipfs/src/schema.graphql @@ -0,0 +1,34 @@ +type Module { + cat(cid: String!, options: Options): Bytes! + + catFile(cid: String!, options: Options): Bytes! + + catToString(cid: String!, options: Options): String! + + resolve(cid: String!, options: Options): ResolveResult + + addFile(data: Bytes!): String! +} + +type ResolveResult { + cid: String! + provider: String! +} + +type Options { + """ + Timeout (in ms) for the operation. + Fallback providers are used if timeout is reached. + """ + timeout: UInt32 + + """ + The IPFS provider to be used + """ + provider: String + + """ + Disable querying providers in parallel when resolving URIs + """ + disableParallelRequests: Boolean +} diff --git a/packages/core-interfaces/ipfs/web3api.deploy.yaml b/packages/core-interfaces/ipfs/web3api.deploy.yaml new file mode 100644 index 0000000000..b5a9c3dd7d --- /dev/null +++ b/packages/core-interfaces/ipfs/web3api.deploy.yaml @@ -0,0 +1,5 @@ +format: 0.0.1-prealpha.1 +stages: + ipfs_deploy: + package: ipfs + uri: fs/./build \ No newline at end of file diff --git a/packages/core-interfaces/ipfs/web3api.yaml b/packages/core-interfaces/ipfs/web3api.yaml new file mode 100644 index 0000000000..b63e4cdd34 --- /dev/null +++ b/packages/core-interfaces/ipfs/web3api.yaml @@ -0,0 +1,5 @@ +format: 0.0.1-prealpha.9 +name: Filesystem +language: interface +deploy: ./web3api.deploy.yaml +schema: ./src/schema.graphql \ No newline at end of file diff --git a/packages/js/client/package.json b/packages/js/client/package.json index 3234bf0114..b893933bc6 100644 --- a/packages/js/client/package.json +++ b/packages/js/client/package.json @@ -34,6 +34,7 @@ "@web3api/sha3-plugin-js": "0.0.1-prealpha.85", "@web3api/tracing-js": "0.0.1-prealpha.85", "@web3api/uts46-plugin-js": "0.0.1-prealpha.85", + "@web3api/ipfs-resolver-plugin-js": "0.0.1-prealpha.85", "graphql": "15.5.0", "js-yaml": "3.14.0", "uuid": "8.3.2" diff --git a/packages/js/client/src/__tests__/core/plugin-wrapper.spec.ts b/packages/js/client/src/__tests__/core/plugin-wrapper.spec.ts index 4db62ff3ab..83a73c0377 100644 --- a/packages/js/client/src/__tests__/core/plugin-wrapper.spec.ts +++ b/packages/js/client/src/__tests__/core/plugin-wrapper.spec.ts @@ -17,6 +17,7 @@ const defaultPlugins = [ "w3://ens/sha3.web3api.eth", "w3://ens/graph-node.web3api.eth", "w3://ens/fs.web3api.eth", + "w3://ens/ipfs-resolver.web3api.eth", ]; describe("plugin-wrapper", () => { diff --git a/packages/js/client/src/__tests__/core/resolveUri.spec.ts b/packages/js/client/src/__tests__/core/resolveUri.spec.ts index bde731b231..e9fd605632 100644 --- a/packages/js/client/src/__tests__/core/resolveUri.spec.ts +++ b/packages/js/client/src/__tests__/core/resolveUri.spec.ts @@ -331,7 +331,7 @@ describe("resolveUri", () => { result: { uri: ipfsUri, api: true, - implementationUri: new Uri("w3://ens/ipfs.web3api.eth"), + implementationUri: new Uri("w3://ens/ipfs-resolver.web3api.eth"), }, }, ]); @@ -395,7 +395,7 @@ describe("resolveUri", () => { result: { uri: ipfsUri, api: true, - implementationUri: new Uri("w3://ens/ipfs.web3api.eth"), + implementationUri: new Uri("w3://ens/ipfs-resolver.web3api.eth"), }, }, ]); @@ -522,7 +522,7 @@ describe("resolveUri", () => { result: { uri: ipfsUri, api: true, - implementationUri: new Uri("w3://ens/ipfs.web3api.eth"), + implementationUri: new Uri("w3://ens/ipfs-resolver.web3api.eth"), }, }, ]); @@ -586,7 +586,7 @@ describe("resolveUri", () => { result: { uri: ipfsUri, api: true, - implementationUri: new Uri("w3://ens/ipfs.web3api.eth"), + implementationUri: new Uri("w3://ens/ipfs-resolver.web3api.eth"), }, }, ]); @@ -650,7 +650,7 @@ describe("resolveUri", () => { result: { uri: ipfsUri, api: true, - implementationUri: new Uri("w3://ens/ipfs.web3api.eth"), + implementationUri: new Uri("w3://ens/ipfs-resolver.web3api.eth"), }, }, ]); @@ -730,7 +730,7 @@ describe("resolveUri", () => { result: { uri: ipfsUri, api: true, - implementationUri: new Uri("w3://ens/ipfs.web3api.eth"), + implementationUri: new Uri("w3://ens/ipfs-resolver.web3api.eth"), }, }, ]); diff --git a/packages/js/client/src/__tests__/core/sanity.spec.ts b/packages/js/client/src/__tests__/core/sanity.spec.ts index 30ee49f0d6..6f6dc02a9b 100644 --- a/packages/js/client/src/__tests__/core/sanity.spec.ts +++ b/packages/js/client/src/__tests__/core/sanity.spec.ts @@ -1,6 +1,4 @@ -import { - coreInterfaceUris, -} from "@web3api/core-js"; +import { coreInterfaceUris, PluginModule } from "@web3api/core-js"; import { Uri, Web3ApiClient, @@ -24,12 +22,13 @@ describe("sanity", () => { new Uri("w3://ens/sha3.web3api.eth"), new Uri("w3://ens/graph-node.web3api.eth"), new Uri("w3://ens/fs.web3api.eth"), + new Uri("w3://ens/ipfs-resolver.web3api.eth"), ]); expect(client.getInterfaces()).toStrictEqual([ { interface: coreInterfaceUris.uriResolver, implementations: [ - new Uri("w3://ens/ipfs.web3api.eth"), + new Uri("w3://ens/ipfs-resolver.web3api.eth"), new Uri("w3://ens/ens.web3api.eth"), new Uri("w3://ens/fs.web3api.eth"), ], @@ -87,7 +86,7 @@ describe("sanity", () => { { uri: implementationUri, plugin: { - factory: () => ({} as Plugin), + factory: () => ({} as PluginModule), manifest: { schema: schemaStr, implements: [], diff --git a/packages/js/client/src/default-client-config.ts b/packages/js/client/src/default-client-config.ts index 96c4649a54..e6b7ec9ed2 100644 --- a/packages/js/client/src/default-client-config.ts +++ b/packages/js/client/src/default-client-config.ts @@ -13,6 +13,7 @@ import { RedirectsResolver, } from "@web3api/core-js"; import { ipfsPlugin } from "@web3api/ipfs-plugin-js"; +import { ipfsResolverPlugin } from "@web3api/ipfs-resolver-plugin-js"; import { ethereumPlugin } from "@web3api/ethereum-plugin-js"; import { ensPlugin } from "@web3api/ens-plugin-js"; import { graphNodePlugin } from "@web3api/graph-node-plugin-js"; @@ -80,12 +81,19 @@ export const getDefaultClientConfig = Tracer.traceFunc( uri: new Uri("w3://ens/fs.web3api.eth"), plugin: filesystemPlugin({}), }, + { + uri: new Uri("w3://ens/ipfs-resolver.web3api.eth"), + plugin: ipfsResolverPlugin({ + provider: defaultIpfsProviders[0], + fallbackProviders: defaultIpfsProviders.slice(1), + }), + }, ], interfaces: [ { interface: coreInterfaceUris.uriResolver, implementations: [ - new Uri("w3://ens/ipfs.web3api.eth"), + new Uri("w3://ens/ipfs-resolver.web3api.eth"), new Uri("w3://ens/ens.web3api.eth"), new Uri("w3://ens/fs.web3api.eth"), ], diff --git a/packages/js/plugins/ipfs/src/index.ts b/packages/js/plugins/ipfs/src/index.ts index e71613beed..535cd027d3 100644 --- a/packages/js/plugins/ipfs/src/index.ts +++ b/packages/js/plugins/ipfs/src/index.ts @@ -2,27 +2,29 @@ import { Module, Input_catFile, Input_resolve, - Input_tryResolveUri, - Input_getFile, Input_addFile, Bytes, - Options, - ResolveResult, + Ipfs_Options, + Ipfs_ResolveResult, Env, - UriResolver_MaybeUriOrManifest, manifest, -} from "./w3-man"; + Input_catToString, + Input_cat, +} from "./w3"; import { IpfsClient } from "./utils/IpfsClient"; import { execSimple, execFallbacks } from "./utils/exec"; -import { PluginFactory } from "@web3api/core-js"; +import { Client, PluginFactory } from "@web3api/core-js"; // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports const isIPFS = require("is-ipfs"); // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, @typescript-eslint/naming-convention const createIpfsClient = require("@dorgjelli-test/ipfs-http-client-lite"); -const getOptions = (input: Options | undefined | null, env: Env): Options => { +const getOptions = ( + input: Ipfs_Options | undefined | null, + env: Env +): Ipfs_Options => { const options = input || {}; if ( @@ -54,27 +56,34 @@ export class IpfsPlugin extends Module { return isIPFS.cid(cid) || isIPFS.cidPath(cid) || isIPFS.ipfsPath(cid); } - public async cat(cid: string, options?: Options): Promise { + public async cat(input: Input_cat, _client: Client): Promise { return await this._execWithOptions( "cat", (ipfs: IpfsClient, _provider: string, options: unknown) => { - return ipfs.cat(cid, options); + return ipfs.cat(input.cid, options); }, - options + input.options ?? undefined ); } - public async catToString(cid: string, options?: Options): Promise { - const buffer = await this.cat(cid, options); + public async catToString( + input: Input_catToString, + _client: Client + ): Promise { + const buffer = await this.cat(input, _client); return buffer.toString("utf-8"); } - public async catFile(input: Input_catFile): Promise { - const options = getOptions(input.options, this.env); - return await this.cat(input.cid, options); + public async catFile(input: Input_catFile, client: Client): Promise { + // TODO: Pull env into options? + // const options = getOptions(input.options, this.env); + return await this.cat(input, client); } - public async resolve(input: Input_resolve): Promise { + public async resolve( + input: Input_resolve, + _client: Client + ): Promise { const options = getOptions(input.options, this.env); return await this._execWithOptions( "resolve", @@ -89,74 +98,6 @@ export class IpfsPlugin extends Module { ); } - // uri-resolver.core.web3api.eth - public async tryResolveUri( - input: Input_tryResolveUri - ): Promise { - if (input.authority !== "ipfs") { - return null; - } - - if (!IpfsPlugin.isCID(input.path)) { - // Not a valid CID - return { manifest: null, uri: null }; - } - - const manifestSearchPatterns = [ - "web3api.json", - "web3api.yaml", - "web3api.yml", - ]; - - let manifest: string | undefined; - - for (const manifestSearchPattern of manifestSearchPatterns) { - try { - manifest = await this.catToString( - `${input.path}/${manifestSearchPattern}`, - { - timeout: 5000, - disableParallelRequests: this.env.disableParallelRequests, - } - ); - } catch (e) { - // TODO: logging - // https://github.com/web3-api/monorepo/issues/33 - } - } - - if (manifest) { - return { uri: null, manifest }; - } else { - // Nothing found - return { uri: null, manifest: null }; - } - } - - public async getFile(input: Input_getFile): Promise { - try { - const result = await this.resolve({ - cid: input.path, - options: { - timeout: 5000, - disableParallelRequests: this.env.disableParallelRequests, - }, - }); - - if (!result) { - return null; - } - - return await this.cat(result.cid, { - provider: result.provider, - timeout: 20000, - disableParallelRequests: true, - }); - } catch (e) { - return null; - } - } - public async addFile(input: Input_addFile): Promise { const result = await this._ipfs.add(new Uint8Array(input.data)); @@ -176,7 +117,7 @@ export class IpfsPlugin extends Module { provider: string, options: unknown ) => Promise, - options?: Options + options?: Ipfs_Options ): Promise { if (!options) { // Default behavior if no options are provided diff --git a/packages/js/plugins/ipfs/src/schema.graphql b/packages/js/plugins/ipfs/src/schema.graphql index b7885eea30..a39586bdbb 100644 --- a/packages/js/plugins/ipfs/src/schema.graphql +++ b/packages/js/plugins/ipfs/src/schema.graphql @@ -1,4 +1,4 @@ -#import { Module, MaybeUriOrManifest } into UriResolver from "ens/uri-resolver.core.web3api.eth" +#import { Module } into Ipfs from "ens/ipfs.web3api.eth" type Env { """ @@ -7,39 +7,5 @@ type Env { disableParallelRequests: Boolean } -type Module implements UriResolver_Module { - catFile( - cid: String! - options: Options - ): Bytes! - - resolve( - cid: String! - options: Options - ): ResolveResult - - addFile(data: Bytes!): String! -} - -type ResolveResult { - cid: String! - provider: String! -} - -type Options { - """ - Timeout (in ms) for the operation. - Fallback providers are used if timeout is reached. - """ - timeout: UInt32 - - """ - The IPFS provider to be used - """ - provider: String - - """ - Disable querying providers in parallel when resolving URIs - """ - disableParallelRequests: Boolean -} +type Module implements Ipfs_Module { +} \ No newline at end of file diff --git a/packages/js/plugins/ipfs/src/w3-man/index.ts b/packages/js/plugins/ipfs/src/w3-man/index.ts deleted file mode 100644 index ff371c0cd8..0000000000 --- a/packages/js/plugins/ipfs/src/w3-man/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -/// NOTE: This is an auto-generated file. -/// All modifications will be overwritten. - -export * from "./schema"; -export * from "./manifest"; -export * from "./module"; -export * from "./types"; - -export { Client } from "@web3api/core-js"; diff --git a/packages/js/plugins/ipfs/src/w3-man/manifest.ts b/packages/js/plugins/ipfs/src/w3-man/manifest.ts deleted file mode 100644 index 18126678b4..0000000000 --- a/packages/js/plugins/ipfs/src/w3-man/manifest.ts +++ /dev/null @@ -1,11 +0,0 @@ -/// NOTE: This is an auto-generated file. -/// All modifications will be overwritten. - -import { schema } from "./"; - -import { PluginPackageManifest } from "@web3api/core-js"; - -export const manifest: PluginPackageManifest = { - schema, - implements: [], -}; diff --git a/packages/js/plugins/ipfs/src/w3-man/module.ts b/packages/js/plugins/ipfs/src/w3-man/module.ts deleted file mode 100644 index c6227ba796..0000000000 --- a/packages/js/plugins/ipfs/src/w3-man/module.ts +++ /dev/null @@ -1,60 +0,0 @@ -/// NOTE: This is an auto-generated file. -/// All modifications will be overwritten. - -/* eslint-disable @typescript-eslint/naming-convention */ - -import * as Types from "./types"; - -import { Client, PluginModule, MaybeAsync } from "@web3api/core-js"; - -export interface Input_catFile extends Record { - cid: Types.String; - options?: Types.Options | null; -} - -export interface Input_resolve extends Record { - cid: Types.String; - options?: Types.Options | null; -} - -export interface Input_tryResolveUri extends Record { - authority: Types.String; - path: Types.String; -} - -export interface Input_getFile extends Record { - path: Types.String; -} - -export interface Input_addFile extends Record { - data: Types.Bytes; -} - -export abstract class Module< - TConfig extends Record -> extends PluginModule { - abstract catFile( - input: Input_catFile, - client: Client - ): MaybeAsync; - - abstract resolve( - input: Input_resolve, - client: Client - ): MaybeAsync; - - abstract tryResolveUri( - input: Input_tryResolveUri, - client: Client - ): MaybeAsync; - - abstract getFile( - input: Input_getFile, - client: Client - ): MaybeAsync; - - abstract addFile( - input: Input_addFile, - client: Client - ): MaybeAsync; -} diff --git a/packages/js/plugins/ipfs/src/w3-man/schema.ts b/packages/js/plugins/ipfs/src/w3-man/schema.ts deleted file mode 100644 index df29254e24..0000000000 --- a/packages/js/plugins/ipfs/src/w3-man/schema.ts +++ /dev/null @@ -1,130 +0,0 @@ -/// NOTE: This is an auto-generated file. -/// All modifications will be overwritten. - -export const schema = `### Web3API Header START ### -scalar UInt -scalar UInt8 -scalar UInt16 -scalar UInt32 -scalar Int -scalar Int8 -scalar Int16 -scalar Int32 -scalar Bytes -scalar BigInt -scalar BigNumber -scalar JSON -scalar Map - -directive @imported( - uri: String! - namespace: String! - nativeType: String! -) on OBJECT | ENUM - -directive @imports( - types: [String!]! -) on OBJECT - -directive @capability( - type: String! - uri: String! - namespace: String! -) repeatable on OBJECT - -directive @enabled_interface on OBJECT - -directive @annotate(type: String!) on FIELD - -### Web3API Header END ### - -type Module implements UriResolver_Module @imports( - types: [ - "UriResolver_Module", - "UriResolver_MaybeUriOrManifest" - ] -) { - catFile( - cid: String! - options: Options - ): Bytes! - - resolve( - cid: String! - options: Options - ): ResolveResult - - tryResolveUri( - authority: String! - path: String! - ): UriResolver_MaybeUriOrManifest - - getFile( - path: String! - ): Bytes - - addFile( - data: Bytes! - ): String! -} - -type Env { - """ - Disable querying providers in parallel when resolving URIs - """ - disableParallelRequests: Boolean -} - -type ResolveResult { - cid: String! - provider: String! -} - -type Options { - """ - Timeout (in ms) for the operation. -Fallback providers are used if timeout is reached. - """ - timeout: UInt32 - """ - The IPFS provider to be used - """ - provider: String - """ - Disable querying providers in parallel when resolving URIs - """ - disableParallelRequests: Boolean -} - -### Imported Modules START ### - -type UriResolver_Module @imported( - uri: "ens/uri-resolver.core.web3api.eth", - namespace: "UriResolver", - nativeType: "Module" -) { - tryResolveUri( - authority: String! - path: String! - ): UriResolver_MaybeUriOrManifest - - getFile( - path: String! - ): Bytes -} - -### Imported Modules END ### - -### Imported Objects START ### - -type UriResolver_MaybeUriOrManifest @imported( - uri: "ens/uri-resolver.core.web3api.eth", - namespace: "UriResolver", - nativeType: "MaybeUriOrManifest" -) { - uri: String - manifest: String -} - -### Imported Objects END ### -`; diff --git a/packages/js/plugins/ipfs/src/w3-man/types.ts b/packages/js/plugins/ipfs/src/w3-man/types.ts deleted file mode 100644 index 11774e8bc3..0000000000 --- a/packages/js/plugins/ipfs/src/w3-man/types.ts +++ /dev/null @@ -1,97 +0,0 @@ -/// NOTE: This is an auto-generated file. -/// All modifications will be overwritten. - -/* eslint-disable @typescript-eslint/naming-convention */ - -import * as Types from "./"; - -import { Client, InvokeApiResult } from "@web3api/core-js"; - -export type UInt = number; -export type UInt8 = number; -export type UInt16 = number; -export type UInt32 = number; -export type Int = number; -export type Int8 = number; -export type Int16 = number; -export type Int32 = number; -export type Bytes = ArrayBuffer; -export type BigInt = string; -export type BigNumber = string; -export type Json = string; -export type String = string; -export type Boolean = boolean; - -/// Envs START /// -export interface Env extends Record { - disableParallelRequests?: Types.Boolean | null; -} -/// Envs END /// - -/// Objects START /// -export interface ResolveResult { - cid: Types.String; - provider: Types.String; -} - -export interface Options { - timeout?: Types.UInt32 | null; - provider?: Types.String | null; - disableParallelRequests?: Types.Boolean | null; -} - -/// Objects END /// - -/// Enums START /// -/// Enums END /// - -/// Imported Objects START /// - -/* URI: "ens/uri-resolver.core.web3api.eth" */ -export interface UriResolver_MaybeUriOrManifest { - uri?: Types.String | null; - manifest?: Types.String | null; -} - -/// Imported Objects END /// - -/// Imported Modules START /// - -/* URI: "ens/uri-resolver.core.web3api.eth" */ -interface UriResolver_Module_Input_tryResolveUri - extends Record { - authority: Types.String; - path: Types.String; -} - -/* URI: "ens/uri-resolver.core.web3api.eth" */ -interface UriResolver_Module_Input_getFile extends Record { - path: Types.String; -} - -/* URI: "ens/uri-resolver.core.web3api.eth" */ -export const UriResolver_Module = { - tryResolveUri: async ( - input: UriResolver_Module_Input_tryResolveUri, - client: Client - ): Promise> => { - return client.invoke({ - uri: "ens/uri-resolver.core.web3api.eth", - method: "tryResolveUri", - input, - }); - }, - - getFile: async ( - input: UriResolver_Module_Input_getFile, - client: Client - ): Promise> => { - return client.invoke({ - uri: "ens/uri-resolver.core.web3api.eth", - method: "getFile", - input, - }); - }, -}; - -/// Imported Modules END /// diff --git a/packages/js/plugins/ipfs/web3api.plugin.yaml b/packages/js/plugins/ipfs/web3api.plugin.yaml index 54151d04fe..6be0e5ec76 100644 --- a/packages/js/plugins/ipfs/web3api.plugin.yaml +++ b/packages/js/plugins/ipfs/web3api.plugin.yaml @@ -4,5 +4,5 @@ language: plugin/typescript module: ./src/index.ts schema: ./src/schema.graphql import_redirects: - - uri: "ens/uri-resolver.core.web3api.eth" - schema: ../../../core-interfaces/uri-resolver/src/query.graphql + - uri: "ens/ipfs.web3api.eth" + schema: ../../../core-interfaces/ipfs/build/schema.graphql diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/README.md b/packages/js/plugins/uri-resolvers/ipfs-resolver/README.md new file mode 100644 index 0000000000..30404ce4c5 --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/README.md @@ -0,0 +1 @@ +TODO \ No newline at end of file diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/jest.config.js b/packages/js/plugins/uri-resolvers/ipfs-resolver/jest.config.js new file mode 100644 index 0000000000..38888109ca --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/jest.config.js @@ -0,0 +1,13 @@ +module.exports = { + "roots": [ + "/src" + ], + "testMatch": [ + "**/__tests__/**/*.+(ts|tsx|js)", + "**/?(*.)+(spec|test).+(ts|tsx|js)" + ], + "transform": { + "^.+\\.(ts|tsx)$": "ts-jest" + }, + testEnvironment: 'node' +} diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json b/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json new file mode 100644 index 0000000000..96d75673f3 --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json @@ -0,0 +1,44 @@ +{ + "name": "@web3api/ipfs-resolver-plugin-js", + "description": "Web3API IPFS Javascript Plugin", + "version": "0.0.1-prealpha.85", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/web3-api/monorepo.git" + }, + "main": "build/index.js", + "files": [ + "build" + ], + "scripts": { + "build": "rimraf ./build && tsc --project tsconfig.build.json", + "codegen": "node ../../../../../dependencies/node_modules/@web3api/cli/bin/w3 plugin codegen", + "codegen:patch": "node ../../../../cli/bin/w3 plugin codegen", + "lint": "eslint --color -c ../../../../.eslintrc.js src/", + "test": "jest --passWithNoTests --runInBand --verbose", + "test:ci": "jest --passWithNoTests --runInBand --verbose", + "test:watch": "jest --watch --passWithNoTests --verbose" + }, + "dependencies": { + "@dorgjelli-test/ipfs-http-client-lite": "0.3.1", + "@web3api/core-js": "0.0.1-prealpha.85", + "abort-controller": "3.0.0", + "cids": "^1.1.4", + "is-ipfs": "1.0.3" + }, + "devDependencies": { + "@types/jest": "26.0.8", + "@types/prettier": "2.6.0", + "abort-controller": "3.0.0", + "jest": "26.6.3", + "rimraf": "3.0.2", + "ts-jest": "26.5.4", + "ts-node": "8.10.2", + "typescript": "4.0.7" + }, + "gitHead": "7346adaf5adb7e6bbb70d9247583e995650d390a", + "publishConfig": { + "access": "public" + } +} diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts new file mode 100644 index 0000000000..e9397a2000 --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts @@ -0,0 +1,5 @@ +/* eslint-disable @typescript-eslint/no-empty-function */ +// TODO: create client, add plugin, test all the methods +describe("TODO", () => { + it("TODO", () => {}); +}); diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts new file mode 100644 index 0000000000..3738086773 --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts @@ -0,0 +1,135 @@ +import { + Module, + Input_tryResolveUri, + Input_getFile, + Bytes, + UriResolver_MaybeUriOrManifest, + manifest, + Ipfs_Module, + Client, +} from "./w3"; + +import { PluginFactory } from "@web3api/core-js"; + +// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports +const isIPFS = require("is-ipfs"); + +export interface IpfsResolverPluginConfig extends Record { + provider: string; + fallbackProviders?: string[]; +} + +export class IpfsResolverPlugin extends Module { + public static isCID(cid: string): boolean { + return isIPFS.cid(cid) || isIPFS.cidPath(cid) || isIPFS.ipfsPath(cid); + } + + // uri-resolver.core.web3api.eth + public async tryResolveUri( + input: Input_tryResolveUri, + _client: Client + ): Promise { + if (input.authority !== "ipfs") { + return null; + } + + if (!IpfsResolverPlugin.isCID(input.path)) { + // Not a valid CID + return { manifest: null, uri: null }; + } + + const manifestSearchPatterns = [ + "web3api.json", + "web3api.yaml", + "web3api.yml", + ]; + + let manifest: string | undefined; + + for (const manifestSearchPattern of manifestSearchPatterns) { + try { + const manifestResult = await Ipfs_Module.catToString( + { + cid: `${input.path}/${manifestSearchPattern}`, + options: { + timeout: 5000, + disableParallelRequests: this.env.disableParallelRequests, + }, + }, + _client + ); + + if (manifestResult.data) { + manifest = manifestResult.data; + } else { + throw manifestResult.error; + } + } catch (e) { + // TODO: logging + // https://github.com/web3-api/monorepo/issues/33 + } + } + + if (manifest) { + return { uri: null, manifest }; + } else { + // Nothing found + return { uri: null, manifest: null }; + } + } + + public async getFile( + input: Input_getFile, + client: Client + ): Promise { + try { + const resolveResult = await Ipfs_Module.resolve( + { + cid: input.path, + options: { + timeout: 5000, + disableParallelRequests: this.env.disableParallelRequests, + }, + }, + client + ); + + const result = resolveResult.data; + + if (!result) { + return null; + } + + const catResult = await Ipfs_Module.cat( + { + cid: result.cid, + options: { + provider: result.provider, + timeout: 20000, + disableParallelRequests: true, + }, + }, + client + ); + + if (catResult.data) { + return catResult.data; + } else { + return null; + } + } catch (e) { + return null; + } + } +} + +export const ipfsResolverPlugin: PluginFactory = ( + opts: IpfsResolverPluginConfig +) => { + return { + factory: () => new IpfsResolverPlugin(opts), + manifest, + }; +}; + +export const plugin = ipfsResolverPlugin; diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/schema.graphql b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/schema.graphql new file mode 100644 index 0000000000..30f70e09a8 --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/schema.graphql @@ -0,0 +1,12 @@ +#import { Module, MaybeUriOrManifest } into UriResolver from "ens/uri-resolver.core.web3api.eth" +#import { Module } into Ipfs from "ens/ipfs.web3api.eth" + +type Env { + """ + Disable querying providers in parallel when resolving URIs + """ + disableParallelRequests: Boolean +} + +type Module implements UriResolver_Module { +} \ No newline at end of file diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/tsconfig.build.json b/packages/js/plugins/uri-resolvers/ipfs-resolver/tsconfig.build.json new file mode 100644 index 0000000000..77aadfdd2f --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "include": [ + "./src/**/*.ts" + ], + "exclude": [ + "./src/**/__tests__" + ] +} diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/tsconfig.json b/packages/js/plugins/uri-resolvers/ipfs-resolver/tsconfig.json new file mode 100644 index 0000000000..57a0c4369c --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../../../tsconfig", + "compilerOptions": { + "outDir": "build" + }, + "include": [ + "./src/**/*.ts" + ], + "exclude": [] +} diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/web3api.plugin.yaml b/packages/js/plugins/uri-resolvers/ipfs-resolver/web3api.plugin.yaml new file mode 100644 index 0000000000..42d8ca9981 --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/web3api.plugin.yaml @@ -0,0 +1,10 @@ +format: 0.0.1-prealpha.3 +name: Ipfs +language: plugin/typescript +module: ./src/index.ts +schema: ./src/schema.graphql +import_redirects: + - uri: "ens/uri-resolver.core.web3api.eth" + schema: ../../../../core-interfaces/uri-resolver/src/query.graphql + - uri: "ens/ipfs.web3api.eth" + schema: ../../../../core-interfaces/ipfs/build/schema.graphql diff --git a/yarn.lock b/yarn.lock index a4162c4f96..925b124b01 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3081,10 +3081,10 @@ "@octokit/types" "^6.0.3" universal-user-agent "^6.0.0" -"@octokit/openapi-types@^11.2.0": - version "11.2.0" - resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-11.2.0.tgz#b38d7fc3736d52a1e96b230c1ccd4a58a2f400a6" - integrity sha512-PBsVO+15KSlGmiI8QAzaqvsNlZlrDlyAJYcrXBCvVUxCp7VnXjkwPoFHgjEJXx3WF9BAwkA6nfCUA7i9sODzKA== +"@octokit/openapi-types@^12.1.0": + version "12.1.0" + resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-12.1.0.tgz#a68b60e969f26dee0eb7d127c65a84967f2d3a6e" + integrity sha512-kQzJh3ZUv3lDpi6M+uekMRHULvf9DlWoI1XgKN6nPeGDzkSgtkhVq1MMz3bFKQ6H6GbdC3ZqG/a6VzKhIx0VeA== "@octokit/plugin-enterprise-rest@^6.0.1": version "6.0.1" @@ -3092,11 +3092,11 @@ integrity sha512-93uGjlhUD+iNg1iWhUENAtJata6w5nE+V4urXOAlIXdco6xNZtUSfYY8dzp3Udy74aqO/B5UZL80x/YMa5PKRw== "@octokit/plugin-paginate-rest@^2.16.8": - version "2.17.0" - resolved "https://registry.yarnpkg.com/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.17.0.tgz#32e9c7cab2a374421d3d0de239102287d791bce7" - integrity sha512-tzMbrbnam2Mt4AhuyCHvpRkS0oZ5MvwwcQPYGtMv4tUa5kkzG58SVB0fcsLulOZQeRnOgdkZWkRUiyBlh0Bkyw== + version "2.18.0" + resolved "https://registry.yarnpkg.com/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.18.0.tgz#e412977782690a4134b0a4aa2f536cca7a2ca125" + integrity sha512-n5/AzIoy5Wzp85gqzSbR+dWQDHlyHZrGijnDfLh452547Ynu0hCvszH7EfRE0eqM5ZjfkplO0k+q+P8AAIIJEA== dependencies: - "@octokit/types" "^6.34.0" + "@octokit/types" "^6.35.0" "@octokit/plugin-request-log@^1.0.4": version "1.0.4" @@ -3104,11 +3104,11 @@ integrity sha512-mLUsMkgP7K/cnFEw07kWqXGF5LKrOkD+lhCrKvPHXWDywAwuDUeDwWBpc69XK3pNX0uKiVt8g5z96PJ6z9xCFA== "@octokit/plugin-rest-endpoint-methods@^5.12.0": - version "5.13.0" - resolved "https://registry.yarnpkg.com/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.13.0.tgz#8c46109021a3412233f6f50d28786f8e552427ba" - integrity sha512-uJjMTkN1KaOIgNtUPMtIXDOjx6dGYysdIFhgA52x4xSadQCz3b/zJexvITDVpANnfKPW/+E0xkOvLntqMYpviA== + version "5.14.0" + resolved "https://registry.yarnpkg.com/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.14.0.tgz#758e01ac40998e607feaea7f80220c69990814ae" + integrity sha512-MRnMs4Dcm1OSaz/g/RLr4YY9otgysS7vN5SUkHGd7t+R8323cHsHFoEWHYPSmgUC0BieHRhvnCRWb4i3Pl+Lgg== dependencies: - "@octokit/types" "^6.34.0" + "@octokit/types" "^6.35.0" deprecation "^2.3.1" "@octokit/request-error@^2.0.5", "@octokit/request-error@^2.1.0": @@ -3142,12 +3142,12 @@ "@octokit/plugin-request-log" "^1.0.4" "@octokit/plugin-rest-endpoint-methods" "^5.12.0" -"@octokit/types@^6.0.3", "@octokit/types@^6.16.1", "@octokit/types@^6.34.0": - version "6.34.0" - resolved "https://registry.yarnpkg.com/@octokit/types/-/types-6.34.0.tgz#c6021333334d1ecfb5d370a8798162ddf1ae8218" - integrity sha512-s1zLBjWhdEI2zwaoSgyOFoKSl109CUcVBCc7biPJ3aAf6LGLU6szDvi31JPU7bxfla2lqfhjbbg/5DdFNxOwHw== +"@octokit/types@^6.0.3", "@octokit/types@^6.16.1", "@octokit/types@^6.35.0": + version "6.35.0" + resolved "https://registry.yarnpkg.com/@octokit/types/-/types-6.35.0.tgz#11cd9a679c32b4a6c36459ae2ec3ac4de0104f71" + integrity sha512-DhLfdUuv3H37u6jBDfkwamypx3HflHg29b26nbA6iVFYkAlZ5cMEtu/9pQoihGnQE5M7jJFnNo25Rr1UwQNF8Q== dependencies: - "@octokit/openapi-types" "^11.2.0" + "@octokit/openapi-types" "^12.1.0" "@opentelemetry/api-metrics@0.20.0": version "0.20.0" @@ -3472,14 +3472,14 @@ integrity sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA== "@tsconfig/node12@^1.0.7": - version "1.0.10" - resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.10.tgz#10fecee4a3be17357ce99b370bd81874044d8dbd" - integrity sha512-N+srakvPaYMGkwjNDx3ASx65Zl3QG8dJgVtIB+YMOkucU+zctlv/hdP5250VKdDHSDoW9PFZoCqbqNcAPjCjXA== + version "1.0.11" + resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.11.tgz#ee3def1f27d9ed66dac6e46a295cffb0152e058d" + integrity sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag== "@tsconfig/node14@^1.0.0": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.2.tgz#b09c08de2eb319ca2acab17a1b8028af110b24b3" - integrity sha512-YwrUA5ysDXHFYfL0Xed9x3sNS4P+aKlCOnnbqUa2E5HdQshHFleCJVrj1PlGTb4GgFUCDyte1v3JWLy2sz8Oqg== + version "1.0.3" + resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.3.tgz#e4386316284f00b98435bf40f72f75a09dabf6c1" + integrity sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow== "@tsconfig/node16@^1.0.2": version "1.0.3" @@ -3670,9 +3670,9 @@ integrity sha512-wH6Tu9mbiOt0n5EvdoWy0VGQaJMHfLIxY/6wS0xLC7CV1taM6gESEzcYy0ZlWvxxiiljYvfDIvz4hHbUUDRlhw== "@types/node@*": - version "17.0.42" - resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.42.tgz#d7e8f22700efc94d125103075c074396b5f41f9b" - integrity sha512-Q5BPGyGKcvQgAMbsr7qEGN/kIPN6zZecYYABeTDBizOsau+2NMdSVTar9UQw21A2+JyA2KRNDYaYrPB0Rpk2oQ== + version "18.0.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.0.0.tgz#67c7b724e1bcdd7a8821ce0d5ee184d3b4dd525a" + integrity sha512-cHlGmko4gWLVI27cGJntjs/Sj8th9aYwplmZFwmmgYQQvL5NUsgVJG7OddLvNfLqYS31KFN0s3qlaD9qCaxACA== "@types/node@12.12.26": version "12.12.26" @@ -5651,9 +5651,9 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001035, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001349: - version "1.0.30001352" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001352.tgz#cc6f5da3f983979ad1e2cdbae0505dccaa7c6a12" - integrity sha512-GUgH8w6YergqPQDGWhJGt8GDRnY0L/iJVQcU3eJ46GYf52R8tk0Wxp0PymuFVZboJYXGiCqwozAYZNRjVj6IcA== + version "1.0.30001355" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001355.tgz#e240b7177443ed0198c737a7f609536976701c77" + integrity sha512-Sd6pjJHF27LzCB7pT7qs+kuX2ndurzCzkpJl6Qct7LPSZ9jn0bkOA8mdgMgmqnQAWLVOOGjLpc+66V57eLtb1g== capture-exit@^2.0.0: version "2.0.0" @@ -7331,9 +7331,9 @@ electron-fetch@^1.7.2: encoding "^0.1.13" electron-to-chromium@^1.3.378, electron-to-chromium@^1.4.147: - version "1.4.154" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.154.tgz#d69c60499fc467a6c59591d29183e520afbc78a1" - integrity sha512-GbV9djOkrnj6xmW+YYVVEI3VCQnJ0pnSTu7TW2JyjKd5cakoiSaG5R4RbEtfaD92GsY10DzbU3GYRe+IOA9kqA== + version "1.4.158" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.158.tgz#abbdaaf64676bfa4bc0307522125db34424a0ada" + integrity sha512-gppO3/+Y6sP432HtvwvuU8S+YYYLH4PmAYvQwqUtt9HDOmEsBwQfLnK9T8+1NIKwAS1BEygIjTaATC4H5EzvxQ== elliptic@6.5.4, elliptic@^6.5.3: version "6.5.4" @@ -14768,9 +14768,9 @@ prettier@2.2.1: integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q== prettier@^2.2.0: - version "2.7.0" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.0.tgz#a4fdae07e5596c51c9857ea676cd41a0163879d6" - integrity sha512-nwoX4GMFgxoPC6diHvSwmK/4yU8FFH3V8XWtLQrbj4IBsK2pkYhG4kf/ljF/haaZ/aii+wNJqISrCDPgxGWDVQ== + version "2.7.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64" + integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g== pretty-bytes@^5.1.0: version "5.6.0" @@ -18704,8 +18704,8 @@ zen-observable@^0.8.0: integrity sha512-PQ2PC7R9rslx84ndNBZB/Dkv8V8fZEpk83RLgXtYd0fwUgEjseMn1Dgajh2x6S8QbZAFa9p2qVCEuYZNgve0dQ== zone.js@^0.11.0: - version "0.11.5" - resolved "https://registry.yarnpkg.com/zone.js/-/zone.js-0.11.5.tgz#ab0b449e91fadb5ebb2db189ffe1b7b6048dc8b1" - integrity sha512-D1/7VxEuQ7xk6z/kAROe4SUbd9CzxY4zOwVGnGHerd/SgLIVU5f4esDzQUsOCeArn933BZfWMKydH7l7dPEp0g== + version "0.11.6" + resolved "https://registry.yarnpkg.com/zone.js/-/zone.js-0.11.6.tgz#c7cacfc298fe24bb585329ca04a44d9e2e840e74" + integrity sha512-umJqFtKyZlPli669gB1gOrRE9hxUUGkZr7mo878z+NEBJZZixJkKeVYfnoLa7g25SseUDc92OZrMKKHySyJrFg== dependencies: tslib "^2.3.0" From ff46e3f4e9112c26ad77aadc83bf83c625f5a064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Fri, 17 Jun 2022 22:39:08 +0200 Subject: [PATCH 02/23] fix up new plugins for polywrap rename --- packages/core-interfaces/ipfs/package.json | 18 ++- ...b3api.deploy.yaml => polywrap.deploy.yaml} | 0 .../ipfs/{web3api.yaml => polywrap.yaml} | 2 +- packages/js/plugins/ipfs/package.json | 2 +- .../js/plugins/ipfs/src/wrap-man/index.ts | 9 -- .../js/plugins/ipfs/src/wrap-man/manifest.ts | 11 -- .../js/plugins/ipfs/src/wrap-man/module.ts | 60 -------- .../js/plugins/ipfs/src/wrap-man/schema.ts | 130 ------------------ .../js/plugins/ipfs/src/wrap-man/types.ts | 97 ------------- .../uri-resolvers/ipfs-resolver/package.json | 10 +- ...b3api.plugin.yaml => polywrap.plugin.yaml} | 4 +- .../uri-resolvers/ipfs-resolver/src/index.ts | 4 +- .../ipfs-resolver/src/schema.graphql | 4 +- 13 files changed, 21 insertions(+), 330 deletions(-) rename packages/core-interfaces/ipfs/{web3api.deploy.yaml => polywrap.deploy.yaml} (100%) rename packages/core-interfaces/ipfs/{web3api.yaml => polywrap.yaml} (74%) delete mode 100644 packages/js/plugins/ipfs/src/wrap-man/index.ts delete mode 100644 packages/js/plugins/ipfs/src/wrap-man/manifest.ts delete mode 100644 packages/js/plugins/ipfs/src/wrap-man/module.ts delete mode 100644 packages/js/plugins/ipfs/src/wrap-man/schema.ts delete mode 100644 packages/js/plugins/ipfs/src/wrap-man/types.ts rename packages/js/plugins/uri-resolvers/ipfs-resolver/{web3api.plugin.yaml => polywrap.plugin.yaml} (77%) diff --git a/packages/core-interfaces/ipfs/package.json b/packages/core-interfaces/ipfs/package.json index 855c67fbed..4564c61bbd 100644 --- a/packages/core-interfaces/ipfs/package.json +++ b/packages/core-interfaces/ipfs/package.json @@ -1,18 +1,16 @@ { - "name": "@webapi3/ipfs-interface", - "description": "Web3API Ipfs Interface", + "name": "@polywrap/ipfs-interface", + "description": "Polywrap Ipfs Interface", "private": true, - "version": "0.0.1-prealpha.85", + "version": "0.0.1-prealpha.86", "scripts": { - "build": "rimraf ./build && node ../../../dependencies/node_modules/@web3api/cli/bin/w3 build", - "build:patch": "rimraf ./build && node ../../cli/bin/w3 build", + "build": "npx polywrap build", "lint": "eslint --color -c ../../../.eslintrc.js .", - "test:env:up": "npx w3 test-env up", - "test:env:down": "npx w3 test-env down", - "deploy": "npx w3 deploy" + "test:env:up": "npx polywrap infra up --modules=eth-ens-ipfs", + "test:env:down": "npx polywrap infra down --modules=eth-ens-ipfs", + "deploy": "npx polywrap build --ipfs http://localhost:5001" }, "devDependencies": { - "@web3api/client-js": "0.0.1-prealpha.85", - "rimraf": "3.0.2" + "polywrap": "0.0.1-prealpha.86" } } diff --git a/packages/core-interfaces/ipfs/web3api.deploy.yaml b/packages/core-interfaces/ipfs/polywrap.deploy.yaml similarity index 100% rename from packages/core-interfaces/ipfs/web3api.deploy.yaml rename to packages/core-interfaces/ipfs/polywrap.deploy.yaml diff --git a/packages/core-interfaces/ipfs/web3api.yaml b/packages/core-interfaces/ipfs/polywrap.yaml similarity index 74% rename from packages/core-interfaces/ipfs/web3api.yaml rename to packages/core-interfaces/ipfs/polywrap.yaml index b63e4cdd34..0221dcb6cc 100644 --- a/packages/core-interfaces/ipfs/web3api.yaml +++ b/packages/core-interfaces/ipfs/polywrap.yaml @@ -1,5 +1,5 @@ format: 0.0.1-prealpha.9 name: Filesystem language: interface -deploy: ./web3api.deploy.yaml +deploy: ./polywrap.deploy.yaml schema: ./src/schema.graphql \ No newline at end of file diff --git a/packages/js/plugins/ipfs/package.json b/packages/js/plugins/ipfs/package.json index dda6501f0c..600695ca9b 100644 --- a/packages/js/plugins/ipfs/package.json +++ b/packages/js/plugins/ipfs/package.json @@ -13,7 +13,7 @@ ], "scripts": { "build": "rimraf ./build && tsc --project tsconfig.build.json", - "codegen": "node ../../../../dependencies/node_modules/polywrap/bin/polywrap plugin codegen", + "codegen": "npx polywrap plugin codegen", "codegen:patch": "node ../../../cli/bin/polywrap plugin codegen && rimraf ./src/wrap", "lint": "eslint --color -c ../../../../.eslintrc.js src/", "test": "jest --passWithNoTests --runInBand --verbose", diff --git a/packages/js/plugins/ipfs/src/wrap-man/index.ts b/packages/js/plugins/ipfs/src/wrap-man/index.ts deleted file mode 100644 index f367d143d9..0000000000 --- a/packages/js/plugins/ipfs/src/wrap-man/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -/// NOTE: This is an auto-generated file. -/// All modifications will be overwritten. - -export * from "./schema"; -export * from "./manifest"; -export * from "./module"; -export * from "./types"; - -export { Client } from "@polywrap/core-js"; diff --git a/packages/js/plugins/ipfs/src/wrap-man/manifest.ts b/packages/js/plugins/ipfs/src/wrap-man/manifest.ts deleted file mode 100644 index f7b9e13f5e..0000000000 --- a/packages/js/plugins/ipfs/src/wrap-man/manifest.ts +++ /dev/null @@ -1,11 +0,0 @@ -/// NOTE: This is an auto-generated file. -/// All modifications will be overwritten. - -import { schema } from "./"; - -import { PluginPackageManifest } from "@polywrap/core-js"; - -export const manifest: PluginPackageManifest = { - schema, - implements: [], -}; diff --git a/packages/js/plugins/ipfs/src/wrap-man/module.ts b/packages/js/plugins/ipfs/src/wrap-man/module.ts deleted file mode 100644 index ee6664ef40..0000000000 --- a/packages/js/plugins/ipfs/src/wrap-man/module.ts +++ /dev/null @@ -1,60 +0,0 @@ -/// NOTE: This is an auto-generated file. -/// All modifications will be overwritten. - -/* eslint-disable @typescript-eslint/naming-convention */ - -import * as Types from "./types"; - -import { Client, PluginModule, MaybeAsync } from "@polywrap/core-js"; - -export interface Input_catFile extends Record { - cid: Types.String; - options?: Types.Options | null; -} - -export interface Input_resolve extends Record { - cid: Types.String; - options?: Types.Options | null; -} - -export interface Input_tryResolveUri extends Record { - authority: Types.String; - path: Types.String; -} - -export interface Input_getFile extends Record { - path: Types.String; -} - -export interface Input_addFile extends Record { - data: Types.Bytes; -} - -export abstract class Module< - TConfig extends Record -> extends PluginModule { - abstract catFile( - input: Input_catFile, - client: Client - ): MaybeAsync; - - abstract resolve( - input: Input_resolve, - client: Client - ): MaybeAsync; - - abstract tryResolveUri( - input: Input_tryResolveUri, - client: Client - ): MaybeAsync; - - abstract getFile( - input: Input_getFile, - client: Client - ): MaybeAsync; - - abstract addFile( - input: Input_addFile, - client: Client - ): MaybeAsync; -} diff --git a/packages/js/plugins/ipfs/src/wrap-man/schema.ts b/packages/js/plugins/ipfs/src/wrap-man/schema.ts deleted file mode 100644 index df53cfe010..0000000000 --- a/packages/js/plugins/ipfs/src/wrap-man/schema.ts +++ /dev/null @@ -1,130 +0,0 @@ -/// NOTE: This is an auto-generated file. -/// All modifications will be overwritten. - -export const schema = `### Polywrap Header START ### -scalar UInt -scalar UInt8 -scalar UInt16 -scalar UInt32 -scalar Int -scalar Int8 -scalar Int16 -scalar Int32 -scalar Bytes -scalar BigInt -scalar BigNumber -scalar JSON -scalar Map - -directive @imported( - uri: String! - namespace: String! - nativeType: String! -) on OBJECT | ENUM - -directive @imports( - types: [String!]! -) on OBJECT - -directive @capability( - type: String! - uri: String! - namespace: String! -) repeatable on OBJECT - -directive @enabled_interface on OBJECT - -directive @annotate(type: String!) on FIELD - -### Polywrap Header END ### - -type Module implements UriResolver_Module @imports( - types: [ - "UriResolver_Module", - "UriResolver_MaybeUriOrManifest" - ] -) { - catFile( - cid: String! - options: Options - ): Bytes! - - resolve( - cid: String! - options: Options - ): ResolveResult - - tryResolveUri( - authority: String! - path: String! - ): UriResolver_MaybeUriOrManifest - - getFile( - path: String! - ): Bytes - - addFile( - data: Bytes! - ): String! -} - -type Env { - """ - Disable querying providers in parallel when resolving URIs - """ - disableParallelRequests: Boolean -} - -type ResolveResult { - cid: String! - provider: String! -} - -type Options { - """ - Timeout (in ms) for the operation. -Fallback providers are used if timeout is reached. - """ - timeout: UInt32 - """ - The IPFS provider to be used - """ - provider: String - """ - Disable querying providers in parallel when resolving URIs - """ - disableParallelRequests: Boolean -} - -### Imported Modules START ### - -type UriResolver_Module @imported( - uri: "ens/uri-resolver.core.polywrap.eth", - namespace: "UriResolver", - nativeType: "Module" -) { - tryResolveUri( - authority: String! - path: String! - ): UriResolver_MaybeUriOrManifest - - getFile( - path: String! - ): Bytes -} - -### Imported Modules END ### - -### Imported Objects START ### - -type UriResolver_MaybeUriOrManifest @imported( - uri: "ens/uri-resolver.core.polywrap.eth", - namespace: "UriResolver", - nativeType: "MaybeUriOrManifest" -) { - uri: String - manifest: String -} - -### Imported Objects END ### -`; diff --git a/packages/js/plugins/ipfs/src/wrap-man/types.ts b/packages/js/plugins/ipfs/src/wrap-man/types.ts deleted file mode 100644 index 5995af8e80..0000000000 --- a/packages/js/plugins/ipfs/src/wrap-man/types.ts +++ /dev/null @@ -1,97 +0,0 @@ -/// NOTE: This is an auto-generated file. -/// All modifications will be overwritten. - -/* eslint-disable @typescript-eslint/naming-convention */ - -import * as Types from "./"; - -import { Client, InvokeResult } from "@polywrap/core-js"; - -export type UInt = number; -export type UInt8 = number; -export type UInt16 = number; -export type UInt32 = number; -export type Int = number; -export type Int8 = number; -export type Int16 = number; -export type Int32 = number; -export type Bytes = ArrayBuffer; -export type BigInt = string; -export type BigNumber = string; -export type Json = string; -export type String = string; -export type Boolean = boolean; - -/// Envs START /// -export interface Env extends Record { - disableParallelRequests?: Types.Boolean | null; -} -/// Envs END /// - -/// Objects START /// -export interface ResolveResult { - cid: Types.String; - provider: Types.String; -} - -export interface Options { - timeout?: Types.UInt32 | null; - provider?: Types.String | null; - disableParallelRequests?: Types.Boolean | null; -} - -/// Objects END /// - -/// Enums START /// -/// Enums END /// - -/// Imported Objects START /// - -/* URI: "ens/uri-resolver.core.polywrap.eth" */ -export interface UriResolver_MaybeUriOrManifest { - uri?: Types.String | null; - manifest?: Types.String | null; -} - -/// Imported Objects END /// - -/// Imported Modules START /// - -/* URI: "ens/uri-resolver.core.polywrap.eth" */ -interface UriResolver_Module_Input_tryResolveUri - extends Record { - authority: Types.String; - path: Types.String; -} - -/* URI: "ens/uri-resolver.core.polywrap.eth" */ -interface UriResolver_Module_Input_getFile extends Record { - path: Types.String; -} - -/* URI: "ens/uri-resolver.core.polywrap.eth" */ -export const UriResolver_Module = { - tryResolveUri: async ( - input: UriResolver_Module_Input_tryResolveUri, - client: Client - ): Promise> => { - return client.invoke({ - uri: "ens/uri-resolver.core.polywrap.eth", - method: "tryResolveUri", - input, - }); - }, - - getFile: async ( - input: UriResolver_Module_Input_getFile, - client: Client - ): Promise> => { - return client.invoke({ - uri: "ens/uri-resolver.core.polywrap.eth", - method: "getFile", - input, - }); - }, -}; - -/// Imported Modules END /// diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json b/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json index 96d75673f3..2272435fd8 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json @@ -1,7 +1,7 @@ { - "name": "@web3api/ipfs-resolver-plugin-js", - "description": "Web3API IPFS Javascript Plugin", - "version": "0.0.1-prealpha.85", + "name": "@polywrap/ipfs-resolver-plugin-js", + "description": "Polywrap IPFS Javascript Plugin", + "version": "0.0.1-prealpha.86", "license": "MIT", "repository": { "type": "git", @@ -13,7 +13,7 @@ ], "scripts": { "build": "rimraf ./build && tsc --project tsconfig.build.json", - "codegen": "node ../../../../../dependencies/node_modules/@web3api/cli/bin/w3 plugin codegen", + "codegen": "npx polywrap plugin codegen", "codegen:patch": "node ../../../../cli/bin/w3 plugin codegen", "lint": "eslint --color -c ../../../../.eslintrc.js src/", "test": "jest --passWithNoTests --runInBand --verbose", @@ -22,7 +22,7 @@ }, "dependencies": { "@dorgjelli-test/ipfs-http-client-lite": "0.3.1", - "@web3api/core-js": "0.0.1-prealpha.85", + "@polywrap/core-js": "0.0.1-prealpha.85", "abort-controller": "3.0.0", "cids": "^1.1.4", "is-ipfs": "1.0.3" diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/web3api.plugin.yaml b/packages/js/plugins/uri-resolvers/ipfs-resolver/polywrap.plugin.yaml similarity index 77% rename from packages/js/plugins/uri-resolvers/ipfs-resolver/web3api.plugin.yaml rename to packages/js/plugins/uri-resolvers/ipfs-resolver/polywrap.plugin.yaml index 42d8ca9981..71f3f69881 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/web3api.plugin.yaml +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/polywrap.plugin.yaml @@ -4,7 +4,7 @@ language: plugin/typescript module: ./src/index.ts schema: ./src/schema.graphql import_redirects: - - uri: "ens/uri-resolver.core.web3api.eth" + - uri: "ens/uri-resolver.core.polywrap.eth" schema: ../../../../core-interfaces/uri-resolver/src/query.graphql - - uri: "ens/ipfs.web3api.eth" + - uri: "ens/ipfs.polywrap.eth" schema: ../../../../core-interfaces/ipfs/build/schema.graphql diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts index 3738086773..0385c59287 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts @@ -7,9 +7,9 @@ import { manifest, Ipfs_Module, Client, -} from "./w3"; +} from "./wrap"; -import { PluginFactory } from "@web3api/core-js"; +import { PluginFactory } from "@polywrap/core-js"; // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports const isIPFS = require("is-ipfs"); diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/schema.graphql b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/schema.graphql index 30f70e09a8..dc17a991c0 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/schema.graphql +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/schema.graphql @@ -1,5 +1,5 @@ -#import { Module, MaybeUriOrManifest } into UriResolver from "ens/uri-resolver.core.web3api.eth" -#import { Module } into Ipfs from "ens/ipfs.web3api.eth" +#import { Module, MaybeUriOrManifest } into UriResolver from "ens/uri-resolver.core.polywrap.eth" +#import { Module } into Ipfs from "ens/ipfs.polywrap.eth" type Env { """ From b9db16bbc186b219627a45f7a9db5c9bc5bc85e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Sat, 18 Jun 2022 00:54:31 +0200 Subject: [PATCH 03/23] Fix build issues introduced by new interface --- package.json | 3 ++- packages/core-interfaces/ipfs/package.json | 2 +- packages/js/client/src/default-client-config.ts | 2 +- packages/js/plugins/ipfs/package.json | 4 ++-- .../js/plugins/uri-resolvers/ipfs-resolver/package.json | 8 ++++---- .../js/plugins/uri-resolvers/ipfs-resolver/src/index.ts | 6 +++--- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index df996d957c..6bfdc04bc8 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,9 @@ "reset": "yarn clean && yarn && yarn build", "clean": "npx rimraf ./**/node_modules ./**/yarn.lock ./**/build ./**/coverage ./**/.polywrap", "dependencies:install": "cd dependencies && yarn", - "build": "yarn build:core && yarn build:plugins && yarn build:client && yarn build:test-env && yarn build:cli && yarn build:plugins:patch", + "build": "yarn dependencies:install && yarn build:core && yarn build:interfaces && yarn build:plugins && yarn build:client && yarn build:test-env && yarn build:cli && yarn build:plugins:patch", "build:core": "lerna run build --no-private --ignore @polywrap/*-plugin-js --ignore polywrap --ignore @polywrap/client-js --ignore @polywrap/react --ignore @polywrap/test-env-js", + "build:interfaces": "lerna run build --scope @polywrap/*-interface --concurrency 1", "build:plugins": "lerna run build --scope @polywrap/*-plugin-js --concurrency 1", "build:client": "lerna run build --scope @polywrap/client-js --scope @polywrap/react", "build:test-env": "lerna run build --scope @polywrap/test-env-js", diff --git a/packages/core-interfaces/ipfs/package.json b/packages/core-interfaces/ipfs/package.json index 4564c61bbd..185f71270b 100644 --- a/packages/core-interfaces/ipfs/package.json +++ b/packages/core-interfaces/ipfs/package.json @@ -4,7 +4,7 @@ "private": true, "version": "0.0.1-prealpha.86", "scripts": { - "build": "npx polywrap build", + "build": "node ../../../dependencies/node_modules/polywrap/bin/polywrap build", "lint": "eslint --color -c ../../../.eslintrc.js .", "test:env:up": "npx polywrap infra up --modules=eth-ens-ipfs", "test:env:down": "npx polywrap infra down --modules=eth-ens-ipfs", diff --git a/packages/js/client/src/default-client-config.ts b/packages/js/client/src/default-client-config.ts index cca29ea607..c834aac5af 100644 --- a/packages/js/client/src/default-client-config.ts +++ b/packages/js/client/src/default-client-config.ts @@ -82,7 +82,7 @@ export const getDefaultClientConfig = Tracer.traceFunc( plugin: filesystemPlugin({}), }, { - uri: new Uri("w3://ens/ipfs-resolver.web3api.eth"), + uri: new Uri("wrap://ens/ipfs-resolver.web3api.eth"), plugin: ipfsResolverPlugin({ provider: defaultIpfsProviders[0], fallbackProviders: defaultIpfsProviders.slice(1), diff --git a/packages/js/plugins/ipfs/package.json b/packages/js/plugins/ipfs/package.json index 600695ca9b..93c724a39a 100644 --- a/packages/js/plugins/ipfs/package.json +++ b/packages/js/plugins/ipfs/package.json @@ -12,8 +12,8 @@ "build" ], "scripts": { - "build": "rimraf ./build && tsc --project tsconfig.build.json", - "codegen": "npx polywrap plugin codegen", + "build": "rimraf ./build && yarn codegen && tsc --project tsconfig.build.json", + "codegen": "node ../../../../dependencies/node_modules/polywrap/bin/polywrap plugin codegen", "codegen:patch": "node ../../../cli/bin/polywrap plugin codegen && rimraf ./src/wrap", "lint": "eslint --color -c ../../../../.eslintrc.js src/", "test": "jest --passWithNoTests --runInBand --verbose", diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json b/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json index 2272435fd8..f6f20d9c5d 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json @@ -12,9 +12,9 @@ "build" ], "scripts": { - "build": "rimraf ./build && tsc --project tsconfig.build.json", - "codegen": "npx polywrap plugin codegen", - "codegen:patch": "node ../../../../cli/bin/w3 plugin codegen", + "build": "rimraf ./build && yarn codegen && tsc --project tsconfig.build.json", + "codegen": "node ../../../../../dependencies/node_modules/polywrap/bin/polywrap plugin codegen", + "codegen:patch": "node ../../../../cli/bin/polywrap plugin codegen && rimraf ./src/wrap", "lint": "eslint --color -c ../../../../.eslintrc.js src/", "test": "jest --passWithNoTests --runInBand --verbose", "test:ci": "jest --passWithNoTests --runInBand --verbose", @@ -22,7 +22,7 @@ }, "dependencies": { "@dorgjelli-test/ipfs-http-client-lite": "0.3.1", - "@polywrap/core-js": "0.0.1-prealpha.85", + "@polywrap/core-js": "0.0.1-prealpha.86", "abort-controller": "3.0.0", "cids": "^1.1.4", "is-ipfs": "1.0.3" diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts index 0385c59287..2e2b477ab2 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts @@ -39,9 +39,9 @@ export class IpfsResolverPlugin extends Module { } const manifestSearchPatterns = [ - "web3api.json", - "web3api.yaml", - "web3api.yml", + "polywrap.json", + "polywrap.yaml", + "polywrap.yml", ]; let manifest: string | undefined; From 74d8d03e553f604cfcb7d55c5ae5906c730f854e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Sun, 19 Jun 2022 19:27:00 +0200 Subject: [PATCH 04/23] fix default-client-config --- packages/js/client/src/default-client-config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/client/src/default-client-config.ts b/packages/js/client/src/default-client-config.ts index c834aac5af..d2af686ffa 100644 --- a/packages/js/client/src/default-client-config.ts +++ b/packages/js/client/src/default-client-config.ts @@ -82,7 +82,7 @@ export const getDefaultClientConfig = Tracer.traceFunc( plugin: filesystemPlugin({}), }, { - uri: new Uri("wrap://ens/ipfs-resolver.web3api.eth"), + uri: new Uri("wrap://ens/ipfs-resolver.polywrap.eth"), plugin: ipfsResolverPlugin({ provider: defaultIpfsProviders[0], fallbackProviders: defaultIpfsProviders.slice(1), From 924badb0b7e89b7e69ea801b73f4ceeedda39f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Sun, 19 Jun 2022 19:40:42 +0200 Subject: [PATCH 05/23] fix lint --- packages/js/plugins/uri-resolvers/ipfs-resolver/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json b/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json index f6f20d9c5d..f0201ac960 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json @@ -15,7 +15,7 @@ "build": "rimraf ./build && yarn codegen && tsc --project tsconfig.build.json", "codegen": "node ../../../../../dependencies/node_modules/polywrap/bin/polywrap plugin codegen", "codegen:patch": "node ../../../../cli/bin/polywrap plugin codegen && rimraf ./src/wrap", - "lint": "eslint --color -c ../../../../.eslintrc.js src/", + "lint": "eslint --color -c ../../../../../.eslintrc.js src/", "test": "jest --passWithNoTests --runInBand --verbose", "test:ci": "jest --passWithNoTests --runInBand --verbose", "test:watch": "jest --watch --passWithNoTests --verbose" From e96b5e138d28393f3218f9c1324f1b856a2a433a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Mon, 20 Jun 2022 19:42:02 +0200 Subject: [PATCH 06/23] IPFS plugin basic tests --- packages/js/plugins/ipfs/package.json | 3 +- .../js/plugins/ipfs/src/__tests__/e2e.spec.ts | 117 +++++++++++++++++- 2 files changed, 115 insertions(+), 5 deletions(-) diff --git a/packages/js/plugins/ipfs/package.json b/packages/js/plugins/ipfs/package.json index 93c724a39a..bc2b06f765 100644 --- a/packages/js/plugins/ipfs/package.json +++ b/packages/js/plugins/ipfs/package.json @@ -35,7 +35,8 @@ "rimraf": "3.0.2", "ts-jest": "26.5.4", "ts-node": "8.10.2", - "typescript": "4.0.7" + "typescript": "4.0.7", + "@polywrap/test-env-js": "0.0.1-prealpha.86" }, "gitHead": "7346adaf5adb7e6bbb70d9247583e995650d390a", "publishConfig": { diff --git a/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts b/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts index e9397a2000..cfacf565ce 100644 --- a/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts @@ -1,5 +1,114 @@ -/* eslint-disable @typescript-eslint/no-empty-function */ -// TODO: create client, add plugin, test all the methods -describe("TODO", () => { - it("TODO", () => {}); +import { PolywrapClient } from "@polywrap/client-js"; +import { + initTestEnvironment, + providers, + stopTestEnvironment, +} from "@polywrap/test-env-js"; +import CID from "cids"; +import { ipfsPlugin } from ".."; +import { IpfsClient } from "../utils/IpfsClient"; +import { Ipfs_Module } from "../wrap"; + +const createIpfsClient = require("@dorgjelli-test/ipfs-http-client-lite"); + +jest.setTimeout(30000); + +type IpfsFileInfo = { + name: string; + hash: CID; +}; + +describe("IPFS Plugin", () => { + let client: PolywrapClient; + let ipfs: IpfsClient; + + const sampleFileTextContents = "Hello World!"; + let sampleFileIpfsInfo: IpfsFileInfo; + const sampleFileBuffer = Buffer.from(sampleFileTextContents, "utf-8"); + + beforeAll(async () => { + await initTestEnvironment(); + ipfs = createIpfsClient(providers.ipfs); + + client = new PolywrapClient({ + plugins: [ + { + uri: "wrap://ens/ipfs.polywrap.eth", + plugin: ipfsPlugin({ + provider: providers.ipfs, + }), + }, + ], + }); + + let ipfsAddResult = await ipfs.add(sampleFileBuffer); + sampleFileIpfsInfo = ipfsAddResult[0]; + }); + + afterAll(async () => { + await stopTestEnvironment(); + }); + + it("Should cat a sample file successfully", async () => { + expect(sampleFileIpfsInfo).toBeDefined(); + + let result = await Ipfs_Module.cat( + { cid: sampleFileIpfsInfo.hash.toString() }, + client + ); + + expect(result.error).toBeFalsy(); + + expect(result.data).toEqual(sampleFileBuffer); + }); + + it("Should cat a file to string successfully", async () => { + expect(sampleFileIpfsInfo).toBeDefined(); + + let result = await Ipfs_Module.catToString( + { cid: sampleFileIpfsInfo.hash.toString() }, + client + ); + + expect(result.error).toBeFalsy(); + + expect(result.data).toEqual(sampleFileTextContents); + }); + + it("Should cat a file to buffer successfully", async () => { + expect(sampleFileIpfsInfo).toBeDefined(); + + let result = await Ipfs_Module.cat( + { cid: sampleFileIpfsInfo.hash.toString() }, + client + ); + + expect(result.error).toBeFalsy(); + + expect(result.data).toEqual(sampleFileBuffer); + }); + + it("Should resolve a file successfully", async () => { + expect(sampleFileIpfsInfo).toBeDefined(); + + let result = await Ipfs_Module.resolve( + { cid: sampleFileIpfsInfo.hash.toString() }, + client + ); + + expect(result.error).toBeFalsy(); + + expect(result.data).toEqual({ + cid: `/ipfs/${sampleFileIpfsInfo.hash.toString()}`, + provider: providers.ipfs, + }); + }); + + it("Should add a file successfully", async () => { + let result = await Ipfs_Module.addFile({ data: sampleFileBuffer }, client); + + expect(result.error).toBeFalsy(); + + expect(result.data).toEqual(sampleFileIpfsInfo.hash.toString()); + }); }); From 5e04429b01c3c5c1e2a54b6320f1437802322d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Mon, 20 Jun 2022 19:58:02 +0200 Subject: [PATCH 07/23] Remove redundant method in ipfs plugin, refactor --- .../core-interfaces/ipfs/src/schema.graphql | 2 -- .../js/plugins/ipfs/src/__tests__/e2e.spec.ts | 22 ++----------------- packages/js/plugins/ipfs/src/index.ts | 8 ------- .../js/plugins/ipfs/src/utils/IpfsClient.ts | 15 +++++-------- 4 files changed, 8 insertions(+), 39 deletions(-) diff --git a/packages/core-interfaces/ipfs/src/schema.graphql b/packages/core-interfaces/ipfs/src/schema.graphql index 10c01b694a..9f91f411f7 100644 --- a/packages/core-interfaces/ipfs/src/schema.graphql +++ b/packages/core-interfaces/ipfs/src/schema.graphql @@ -1,8 +1,6 @@ type Module { cat(cid: String!, options: Options): Bytes! - catFile(cid: String!, options: Options): Bytes! - catToString(cid: String!, options: Options): String! resolve(cid: String!, options: Options): ResolveResult diff --git a/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts b/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts index cfacf565ce..6cba75f5ce 100644 --- a/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts @@ -4,20 +4,15 @@ import { providers, stopTestEnvironment, } from "@polywrap/test-env-js"; -import CID from "cids"; + import { ipfsPlugin } from ".."; -import { IpfsClient } from "../utils/IpfsClient"; +import { IpfsClient, IpfsFileInfo } from "../utils/IpfsClient"; import { Ipfs_Module } from "../wrap"; const createIpfsClient = require("@dorgjelli-test/ipfs-http-client-lite"); jest.setTimeout(30000); -type IpfsFileInfo = { - name: string; - hash: CID; -}; - describe("IPFS Plugin", () => { let client: PolywrapClient; let ipfs: IpfsClient; @@ -49,19 +44,6 @@ describe("IPFS Plugin", () => { await stopTestEnvironment(); }); - it("Should cat a sample file successfully", async () => { - expect(sampleFileIpfsInfo).toBeDefined(); - - let result = await Ipfs_Module.cat( - { cid: sampleFileIpfsInfo.hash.toString() }, - client - ); - - expect(result.error).toBeFalsy(); - - expect(result.data).toEqual(sampleFileBuffer); - }); - it("Should cat a file to string successfully", async () => { expect(sampleFileIpfsInfo).toBeDefined(); diff --git a/packages/js/plugins/ipfs/src/index.ts b/packages/js/plugins/ipfs/src/index.ts index e817ae4ecc..9d08cb6a1b 100644 --- a/packages/js/plugins/ipfs/src/index.ts +++ b/packages/js/plugins/ipfs/src/index.ts @@ -1,9 +1,7 @@ import { Module, - Input_catFile, Input_resolve, Input_addFile, - Bytes, Ipfs_Options, Ipfs_ResolveResult, Env, @@ -74,12 +72,6 @@ export class IpfsPlugin extends Module { return buffer.toString("utf-8"); } - public async catFile(input: Input_catFile, client: Client): Promise { - // TODO: Pull env into options? - // const options = getOptions(input.options, this.env); - return await this.cat(input, client); - } - public async resolve( input: Input_resolve, _client: Client diff --git a/packages/js/plugins/ipfs/src/utils/IpfsClient.ts b/packages/js/plugins/ipfs/src/utils/IpfsClient.ts index 1f8e827541..43063a9974 100644 --- a/packages/js/plugins/ipfs/src/utils/IpfsClient.ts +++ b/packages/js/plugins/ipfs/src/utils/IpfsClient.ts @@ -1,15 +1,7 @@ import CID from "cids"; export interface IpfsClient { - add( - data: Uint8Array, - options?: unknown - ): Promise< - { - name: string; - hash: CID; - }[] - >; + add(data: Uint8Array, options?: unknown): Promise; cat(cid: string, options?: unknown): Promise; @@ -20,3 +12,8 @@ export interface IpfsClient { path: string; }>; } + +export type IpfsFileInfo = { + name: string; + hash: CID; +}; From 1d76be31657a284fac043f025edc3532da4e004d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Mon, 20 Jun 2022 20:25:17 +0200 Subject: [PATCH 08/23] fix test breaking in CI --- packages/js/plugins/ipfs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/plugins/ipfs/package.json b/packages/js/plugins/ipfs/package.json index bc2b06f765..bae7c5fa0b 100644 --- a/packages/js/plugins/ipfs/package.json +++ b/packages/js/plugins/ipfs/package.json @@ -17,7 +17,7 @@ "codegen:patch": "node ../../../cli/bin/polywrap plugin codegen && rimraf ./src/wrap", "lint": "eslint --color -c ../../../../.eslintrc.js src/", "test": "jest --passWithNoTests --runInBand --verbose", - "test:ci": "jest --passWithNoTests --runInBand --verbose", + "test:ci": "yarn codegen && yarn test", "test:watch": "jest --watch --passWithNoTests --verbose" }, "dependencies": { From 9378615fddd47e23cc868dd0ad1f403a8b2913df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Mon, 20 Jun 2022 20:39:13 +0200 Subject: [PATCH 09/23] Increase jest timeout for CI --- packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts b/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts index 6cba75f5ce..bb1dc249b1 100644 --- a/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts @@ -11,7 +11,7 @@ import { Ipfs_Module } from "../wrap"; const createIpfsClient = require("@dorgjelli-test/ipfs-http-client-lite"); -jest.setTimeout(30000); +jest.setTimeout(300000); describe("IPFS Plugin", () => { let client: PolywrapClient; From ecaf297e345ba4e60861411ea3e5c06bc1c0da5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Mon, 20 Jun 2022 23:08:25 +0200 Subject: [PATCH 10/23] IPFS URI Resolver basic test --- .../ipfs-resolver/src/__tests__/e2e.spec.ts | 77 ++++++++++++++++++- 1 file changed, 73 insertions(+), 4 deletions(-) diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts index e9397a2000..b10816c81a 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts @@ -1,5 +1,74 @@ -/* eslint-disable @typescript-eslint/no-empty-function */ -// TODO: create client, add plugin, test all the methods -describe("TODO", () => { - it("TODO", () => {}); +import { PolywrapClient } from "@polywrap/client-js"; +import { GetPathToTestWrappers } from "@polywrap/test-cases"; +import { + initTestEnvironment, + providers, + stopTestEnvironment, + buildAndDeployWrapper, +} from "@polywrap/test-env-js"; + +import { ipfsResolverPlugin } from ".."; +import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; + +import { IpfsClient } from "../../../../ipfs/src/utils/IpfsClient"; + +const createIpfsClient = require("@dorgjelli-test/ipfs-http-client-lite"); + +jest.setTimeout(30000); + +describe("IPFS Plugin", () => { + let client: PolywrapClient; + let ipfs: IpfsClient; + + let wrapperIpfsCid: string; + + beforeAll(async () => { + await initTestEnvironment(); + + ipfs = createIpfsClient(providers.ipfs); + + let { ipfsCid } = await buildAndDeployWrapper({ + wrapperAbsPath: `${GetPathToTestWrappers()}/wasm-as/simple-storage`, + ipfsProvider: providers.ipfs, + ethereumProvider: providers.ethereum, + ensName: "simple-storage.eth", + }); + + wrapperIpfsCid = ipfsCid; + console.log("wrapperIpfsCid", wrapperIpfsCid); + client = new PolywrapClient({ + plugins: [ + { + uri: "wrap://ens/ipfs.polywrap.eth", + plugin: ipfsPlugin({ + provider: providers.ipfs, + }), + }, + { + uri: "wrap://ens/ipfs-uri-resolver.polywrap.eth", + plugin: ipfsResolverPlugin({ + provider: providers.ipfs, + }), + }, + ], + }); + }); + + afterAll(async () => { + await stopTestEnvironment(); + }); + + it("Should successfully resolve a deployed wrapper", async () => { + const wrapperUri = `ipfs/${wrapperIpfsCid}`; + + const resolution = await client.resolveUri(wrapperUri); + + expect(resolution.wrapper).toBeTruthy(); + + const expectedSchema = ( + await ipfs.cat(`${wrapperIpfsCid}/schema.graphql`) + ).toString("utf-8"); + + expect(await resolution.wrapper?.getSchema(client)).toEqual(expectedSchema); + }); }); From 52643e1c8dc56a9cee92080cbc2ed06356b28a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Tue, 21 Jun 2022 11:16:08 +0200 Subject: [PATCH 11/23] add e2e test for ipfs-resolver-plugin-js --- .../js/plugins/uri-resolvers/ipfs-resolver/package.json | 2 +- .../uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts | 8 +++++--- .../js/plugins/uri-resolvers/ipfs-resolver/src/index.ts | 2 -- .../uri-resolvers/ipfs-resolver/src/schema.graphql | 7 ------- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json b/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json index f0201ac960..8bd3c06b66 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json @@ -17,7 +17,7 @@ "codegen:patch": "node ../../../../cli/bin/polywrap plugin codegen && rimraf ./src/wrap", "lint": "eslint --color -c ../../../../../.eslintrc.js src/", "test": "jest --passWithNoTests --runInBand --verbose", - "test:ci": "jest --passWithNoTests --runInBand --verbose", + "test:ci": "yarn codegen && yarn test", "test:watch": "jest --watch --passWithNoTests --verbose" }, "dependencies": { diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts index b10816c81a..05c6596bf4 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts @@ -35,7 +35,7 @@ describe("IPFS Plugin", () => { }); wrapperIpfsCid = ipfsCid; - console.log("wrapperIpfsCid", wrapperIpfsCid); + client = new PolywrapClient({ plugins: [ { @@ -58,7 +58,7 @@ describe("IPFS Plugin", () => { await stopTestEnvironment(); }); - it("Should successfully resolve a deployed wrapper", async () => { + it("Should successfully resolve a deployed wrapper - e2e", async () => { const wrapperUri = `ipfs/${wrapperIpfsCid}`; const resolution = await client.resolveUri(wrapperUri); @@ -69,6 +69,8 @@ describe("IPFS Plugin", () => { await ipfs.cat(`${wrapperIpfsCid}/schema.graphql`) ).toString("utf-8"); - expect(await resolution.wrapper?.getSchema(client)).toEqual(expectedSchema); + const schema = await resolution.wrapper?.getSchema(client); + + expect(schema).toEqual(expectedSchema); }); }); diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts index 2e2b477ab2..0021f0b6ac 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts @@ -53,7 +53,6 @@ export class IpfsResolverPlugin extends Module { cid: `${input.path}/${manifestSearchPattern}`, options: { timeout: 5000, - disableParallelRequests: this.env.disableParallelRequests, }, }, _client @@ -88,7 +87,6 @@ export class IpfsResolverPlugin extends Module { cid: input.path, options: { timeout: 5000, - disableParallelRequests: this.env.disableParallelRequests, }, }, client diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/schema.graphql b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/schema.graphql index dc17a991c0..2ba8f5de0f 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/schema.graphql +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/schema.graphql @@ -1,12 +1,5 @@ #import { Module, MaybeUriOrManifest } into UriResolver from "ens/uri-resolver.core.polywrap.eth" #import { Module } into Ipfs from "ens/ipfs.polywrap.eth" -type Env { - """ - Disable querying providers in parallel when resolving URIs - """ - disableParallelRequests: Boolean -} - type Module implements UriResolver_Module { } \ No newline at end of file From fd936b3ae240400f384ac16ec79871eda017f56d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Tue, 21 Jun 2022 11:25:30 +0200 Subject: [PATCH 12/23] increase timeout for ipfs-resolver tests --- .../uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts index 05c6596bf4..35b1589378 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts @@ -14,7 +14,7 @@ import { IpfsClient } from "../../../../ipfs/src/utils/IpfsClient"; const createIpfsClient = require("@dorgjelli-test/ipfs-http-client-lite"); -jest.setTimeout(30000); +jest.setTimeout(300000); describe("IPFS Plugin", () => { let client: PolywrapClient; From 459cc2e22ae20b31c0e5d4f2fdb0b8ce3d73c6a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Wed, 22 Jun 2022 13:49:43 +0200 Subject: [PATCH 13/23] fix package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ad67c5e091..9de044dfd0 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "clean": "npx rimraf ./**/node_modules ./**/yarn.lock ./**/build ./**/coverage ./**/.polywrap", "dependencies:install": "cd dependencies && yarn", "preinstall": "yarn dependencies:install", - "build": "yarn build:core && && yarn build:interfaces && yarn build:plugins && yarn build:client && yarn build:test-env && yarn build:cli", + "build": "yarn build:core && yarn build:interfaces && yarn build:plugins && yarn build:client && yarn build:test-env && yarn build:cli", "build:core": "lerna run build --no-private --ignore @polywrap/*-plugin-js --ignore polywrap --ignore @polywrap/client-js --ignore @polywrap/react --ignore @polywrap/test-env-js", "build:interfaces": "lerna run build --scope @polywrap/*-interface --concurrency 1", "build:plugins": "lerna run build --scope @polywrap/*-plugin-js --concurrency 1", From 11a2e9d13c12cb478735a3e3d2fe1b8a05f6ac12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Wed, 22 Jun 2022 14:05:40 +0200 Subject: [PATCH 14/23] remove catToString from IPFS interface and plugin --- packages/core-interfaces/ipfs/src/schema.graphql | 2 -- .../js/plugins/ipfs/src/__tests__/e2e.spec.ts | 15 +-------------- packages/js/plugins/ipfs/src/index.ts | 9 --------- .../uri-resolvers/ipfs-resolver/src/index.ts | 4 ++-- 4 files changed, 3 insertions(+), 27 deletions(-) diff --git a/packages/core-interfaces/ipfs/src/schema.graphql b/packages/core-interfaces/ipfs/src/schema.graphql index 9f91f411f7..faa5fc9c9e 100644 --- a/packages/core-interfaces/ipfs/src/schema.graphql +++ b/packages/core-interfaces/ipfs/src/schema.graphql @@ -1,8 +1,6 @@ type Module { cat(cid: String!, options: Options): Bytes! - catToString(cid: String!, options: Options): String! - resolve(cid: String!, options: Options): ResolveResult addFile(data: Bytes!): String! diff --git a/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts b/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts index bb1dc249b1..713f4692ae 100644 --- a/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts @@ -44,20 +44,7 @@ describe("IPFS Plugin", () => { await stopTestEnvironment(); }); - it("Should cat a file to string successfully", async () => { - expect(sampleFileIpfsInfo).toBeDefined(); - - let result = await Ipfs_Module.catToString( - { cid: sampleFileIpfsInfo.hash.toString() }, - client - ); - - expect(result.error).toBeFalsy(); - - expect(result.data).toEqual(sampleFileTextContents); - }); - - it("Should cat a file to buffer successfully", async () => { + it("Should cat a file successfully", async () => { expect(sampleFileIpfsInfo).toBeDefined(); let result = await Ipfs_Module.cat( diff --git a/packages/js/plugins/ipfs/src/index.ts b/packages/js/plugins/ipfs/src/index.ts index 9d08cb6a1b..a14f6168cb 100644 --- a/packages/js/plugins/ipfs/src/index.ts +++ b/packages/js/plugins/ipfs/src/index.ts @@ -6,7 +6,6 @@ import { Ipfs_ResolveResult, Env, manifest, - Input_catToString, Input_cat, } from "./wrap"; import { IpfsClient } from "./utils/IpfsClient"; @@ -64,14 +63,6 @@ export class IpfsPlugin extends Module { ); } - public async catToString( - input: Input_catToString, - _client: Client - ): Promise { - const buffer = await this.cat(input, _client); - return buffer.toString("utf-8"); - } - public async resolve( input: Input_resolve, _client: Client diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts index 0021f0b6ac..2944bc4cdd 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts @@ -48,7 +48,7 @@ export class IpfsResolverPlugin extends Module { for (const manifestSearchPattern of manifestSearchPatterns) { try { - const manifestResult = await Ipfs_Module.catToString( + const manifestResult = await Ipfs_Module.cat( { cid: `${input.path}/${manifestSearchPattern}`, options: { @@ -59,7 +59,7 @@ export class IpfsResolverPlugin extends Module { ); if (manifestResult.data) { - manifest = manifestResult.data; + manifest = Buffer.from(manifestResult.data).toString("utf-8"); } else { throw manifestResult.error; } From 289a72fb0edd2130c09518573bf401e14a5a0b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Thu, 23 Jun 2022 09:31:30 +0200 Subject: [PATCH 15/23] resolve PR comments --- packages/core-interfaces/ipfs/.gitignore | 2 +- packages/core-interfaces/ipfs/package.json | 2 +- packages/core-interfaces/ipfs/polywrap.yaml | 2 +- packages/js/plugins/ipfs/package.json | 2 +- .../js/plugins/ipfs/src/__tests__/e2e.spec.ts | 11 +- packages/js/plugins/ipfs/src/index.ts | 6 - .../ipfs-resolver/src/__tests__/e2e.spec.ts | 2 +- .../uri-resolvers/ipfs-resolver/src/index.ts | 14 +- .../ipfs-resolver/src/utils/IpfsClient.ts | 19 ++ .../ipfs-resolver/src/utils/IpfsConfig.ts | 4 + .../ipfs-resolver/src/utils/exec/abortable.ts | 97 +++++++++ .../ipfs-resolver/src/utils/exec/fallbacks.ts | 206 ++++++++++++++++++ .../ipfs-resolver/src/utils/exec/index.ts | 2 + .../ipfs-resolver/src/utils/exec/simple.ts | 33 +++ 14 files changed, 380 insertions(+), 22 deletions(-) create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsClient.ts create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsConfig.ts create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/abortable.ts create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/fallbacks.ts create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/index.ts create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/simple.ts diff --git a/packages/core-interfaces/ipfs/.gitignore b/packages/core-interfaces/ipfs/.gitignore index 1e8f0fdefe..edd2cc9ab1 100644 --- a/packages/core-interfaces/ipfs/.gitignore +++ b/packages/core-interfaces/ipfs/.gitignore @@ -1,3 +1,3 @@ build node_modules -w3 +wrap \ No newline at end of file diff --git a/packages/core-interfaces/ipfs/package.json b/packages/core-interfaces/ipfs/package.json index de8e790daa..037b2274c6 100644 --- a/packages/core-interfaces/ipfs/package.json +++ b/packages/core-interfaces/ipfs/package.json @@ -8,7 +8,7 @@ "lint": "eslint --color -c ../../../.eslintrc.js .", "test:env:up": "npx polywrap infra up --modules=eth-ens-ipfs", "test:env:down": "npx polywrap infra down --modules=eth-ens-ipfs", - "deploy": "npx polywrap build --ipfs http://localhost:5001" + "deploy": "node ../../../dependencies/node_modules/polywrap/bin/polywrap deploy" }, "devDependencies": { "polywrap": "0.0.1-prealpha.88" diff --git a/packages/core-interfaces/ipfs/polywrap.yaml b/packages/core-interfaces/ipfs/polywrap.yaml index 0221dcb6cc..5a25555adb 100644 --- a/packages/core-interfaces/ipfs/polywrap.yaml +++ b/packages/core-interfaces/ipfs/polywrap.yaml @@ -1,5 +1,5 @@ format: 0.0.1-prealpha.9 -name: Filesystem +name: IPFS language: interface deploy: ./polywrap.deploy.yaml schema: ./src/schema.graphql \ No newline at end of file diff --git a/packages/js/plugins/ipfs/package.json b/packages/js/plugins/ipfs/package.json index fab218e1ec..e4c241fe91 100644 --- a/packages/js/plugins/ipfs/package.json +++ b/packages/js/plugins/ipfs/package.json @@ -16,7 +16,7 @@ "codegen": "node ../../../../dependencies/node_modules/polywrap/bin/polywrap plugin codegen", "lint": "eslint --color -c ../../../../.eslintrc.js src/", "test": "jest --passWithNoTests --runInBand --verbose", - "test:ci": "yarn codegen && yarn test", + "test:ci": "jest --passWithNoTests --runInBand --verbose", "test:watch": "jest --watch --passWithNoTests --verbose" }, "dependencies": { diff --git a/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts b/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts index 713f4692ae..f732bc6955 100644 --- a/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/ipfs/src/__tests__/e2e.spec.ts @@ -74,10 +74,17 @@ describe("IPFS Plugin", () => { }); it("Should add a file successfully", async () => { - let result = await Ipfs_Module.addFile({ data: sampleFileBuffer }, client); + const expectedContents = "A new sample file"; + const contentsBuffer = Buffer.from(expectedContents, "utf-8"); + + let result = await Ipfs_Module.addFile({ data: contentsBuffer }, client); expect(result.error).toBeFalsy(); - expect(result.data).toEqual(sampleFileIpfsInfo.hash.toString()); + expect(result.data).toBeTruthy(); + + const addedFileBuffer = await ipfs.cat(result.data as string); + + expect(contentsBuffer).toEqual(addedFileBuffer); }); }); diff --git a/packages/js/plugins/ipfs/src/index.ts b/packages/js/plugins/ipfs/src/index.ts index a14f6168cb..418c24d17f 100644 --- a/packages/js/plugins/ipfs/src/index.ts +++ b/packages/js/plugins/ipfs/src/index.ts @@ -13,8 +13,6 @@ import { execSimple, execFallbacks } from "./utils/exec"; import { Client, PluginFactory } from "@polywrap/core-js"; -// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports -const isIPFS = require("is-ipfs"); // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, @typescript-eslint/naming-convention const createIpfsClient = require("@dorgjelli-test/ipfs-http-client-lite"); @@ -49,10 +47,6 @@ export class IpfsPlugin extends Module { this._ipfs = createIpfsClient(this.config.provider); } - public static isCID(cid: string): boolean { - return isIPFS.cid(cid) || isIPFS.cidPath(cid) || isIPFS.ipfsPath(cid); - } - public async cat(input: Input_cat, _client: Client): Promise { return await this._execWithOptions( "cat", diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts index 35b1589378..2c87e2416d 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts @@ -10,7 +10,7 @@ import { import { ipfsResolverPlugin } from ".."; import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; -import { IpfsClient } from "../../../../ipfs/src/utils/IpfsClient"; +import { IpfsClient } from "../utils/IpfsClient"; const createIpfsClient = require("@dorgjelli-test/ipfs-http-client-lite"); diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts index 2944bc4cdd..a09c3af27d 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts @@ -20,10 +20,6 @@ export interface IpfsResolverPluginConfig extends Record { } export class IpfsResolverPlugin extends Module { - public static isCID(cid: string): boolean { - return isIPFS.cid(cid) || isIPFS.cidPath(cid) || isIPFS.ipfsPath(cid); - } - // uri-resolver.core.web3api.eth public async tryResolveUri( input: Input_tryResolveUri, @@ -38,11 +34,7 @@ export class IpfsResolverPlugin extends Module { return { manifest: null, uri: null }; } - const manifestSearchPatterns = [ - "polywrap.json", - "polywrap.yaml", - "polywrap.yml", - ]; + const manifestSearchPatterns = ["polywrap.json"]; let manifest: string | undefined; @@ -119,6 +111,10 @@ export class IpfsResolverPlugin extends Module { return null; } } + + private static isCID(cid: string): boolean { + return isIPFS.cid(cid) || isIPFS.cidPath(cid) || isIPFS.ipfsPath(cid); + } } export const ipfsResolverPlugin: PluginFactory = ( diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsClient.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsClient.ts new file mode 100644 index 0000000000..43063a9974 --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsClient.ts @@ -0,0 +1,19 @@ +import CID from "cids"; + +export interface IpfsClient { + add(data: Uint8Array, options?: unknown): Promise; + + cat(cid: string, options?: unknown): Promise; + + resolve( + cid: string, + options?: unknown + ): Promise<{ + path: string; + }>; +} + +export type IpfsFileInfo = { + name: string; + hash: CID; +}; diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsConfig.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsConfig.ts new file mode 100644 index 0000000000..bb55fd34e0 --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsConfig.ts @@ -0,0 +1,4 @@ +export interface IpfsConfig { + provider: string; + fallbackProviders?: string[]; +} diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/abortable.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/abortable.ts new file mode 100644 index 0000000000..47d276c310 --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/abortable.ts @@ -0,0 +1,97 @@ +import { IpfsClient } from "../IpfsClient"; + +import AbortController from "abort-controller"; + +const abortErrorMessage = "The user aborted a request."; + +export interface AbortablePromise { + promise: Promise<[error: Error | undefined, result: TReturn | undefined]>; + abort: () => void; + provider: string; +} + +// Returns a promise, provider and callback that can be used to cancel the request +export const execAbortable = ( + operation: string, + ipfs: IpfsClient, + provider: string, + timeout: number, + func: ( + ipfs: IpfsClient, + provider: string, + options: unknown + ) => Promise +): AbortablePromise => { + const controller = new AbortController(); + let error: Error | undefined = undefined; + + // If timer is not 0 then set a timeout to abort the execution + const timer = timeout + ? setTimeout(() => { + error = buildExecError( + operation, + provider, + timeout, + new Error("Timeout has been reached") + ); + controller.abort(); + }, timeout) + : undefined; + + const promise = new Promise< + [error: Error | undefined, result: TReturn | undefined] + >((resolve) => { + func(ipfs, provider, { + signal: controller.signal, + }).then( + (result) => { + // Clear timeout if exists + timer && clearTimeout(timer); + + if (result === undefined && !error) { + error = buildExecError( + operation, + provider, + timeout, + new Error("The provider returned an empty response") + ); + } + + resolve([error, result]); + }, + (e) => { + // Clear timeout if exists + timer && clearTimeout(timer); + + if (!e.message || e.message !== abortErrorMessage) { + error = buildExecError(operation, provider, timeout, e); + } + + resolve([error, undefined]); + } + ); + }); + + return { + promise, + provider, + abort: () => { + controller.abort(); + timer && clearTimeout(); + }, + }; +}; + +const buildExecError = ( + operation: string, + provider: string, + timeout: number, + error: Error +) => { + return new Error( + `An error occurred\nOperation: ${operation}\nProvider: ${provider}\nTimeout: ${timeout}\nError: ${JSON.stringify( + error, + Object.getOwnPropertyNames(error) + )}` + ); +}; diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/fallbacks.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/fallbacks.ts new file mode 100644 index 0000000000..78606a312c --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/fallbacks.ts @@ -0,0 +1,206 @@ +import { IpfsClient } from "../IpfsClient"; +import { execAbortable, AbortablePromise } from "./abortable"; + +// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, @typescript-eslint/naming-convention +const createIpfsClient = require("@dorgjelli-test/ipfs-http-client-lite"); + +export const execFallbacks = async ( + operation: string, + defaultIpfs: IpfsClient, + defaultProvider: string, + providers: string[], + timeout: number, + func: ( + ipfs: IpfsClient, + provider: string, + options: unknown + ) => Promise, + options?: { parallel?: boolean } +): Promise => { + const parallel = !!options?.parallel; + + return parallel + ? await execParallel( + operation, + defaultIpfs, + defaultProvider, + providers, + timeout, + func + ) + : await execSerial( + operation, + defaultIpfs, + defaultProvider, + providers, + timeout, + func + ); +}; + +const execSerial = async ( + operation: string, + defaultIpfs: IpfsClient, + defaultProvider: string, + providers: string[], + timeout: number, + func: ( + ipfs: IpfsClient, + provider: string, + options: unknown + ) => Promise +): Promise => { + const errors: Error[] = []; + + // Gather all requests from all providers + for (const provider of providers) { + let ipfs: IpfsClient; + + if (provider === defaultProvider) { + // If the provider is the default, we use the existing ipfs client + ipfs = defaultIpfs; + } else { + // Otherwise we create a new ipfs client from the provider + ipfs = createIpfsClient(provider); + } + + const { promise } = execAbortable(operation, ipfs, provider, timeout, func); + + const [error, result] = await promise; + + if (error) { + errors.push(error); + } else { + return result as TReturn; + } + } + + // Throw all aggregated errors + throw new Error(errors.map((x) => x.message).join("\n")); +}; + +const execParallel = async ( + operation: string, + defaultIpfs: IpfsClient, + defaultProvider: string, + providers: string[], + timeout: number, + func: ( + ipfs: IpfsClient, + provider: string, + options: unknown + ) => Promise +): Promise => { + const errors: Error[] = []; + const requests: AbortablePromise[] = []; + + // Gather all requests from all providers + for (const provider of providers) { + let ipfs: IpfsClient; + + if (provider === defaultProvider) { + // If the provider is the default, we use the existing ipfs client + ipfs = defaultIpfs; + } else { + // Otherwise we create a new ipfs client from the provider + ipfs = createIpfsClient(provider); + } + + const request = execAbortable(operation, ipfs, provider, timeout, func); + + requests.push(request); + } + + const successPromise = gatherSuccessPromises(requests); + const allPromises = gatherAllPromisesAndTrackErrors(requests, errors); + + // Wait for either the first successful request to finish + // Or for all requests to finish (they all failed) + const response = await Promise.race([successPromise, allPromises]); + + if (response.success) { + abortAllRequests(requests); + } else { + // Throw all aggregated errors + throw new Error(errors.map((x) => x.message).join("\n")); + } + + return response.result as TReturn; +}; + +const gatherSuccessPromises = async ( + requests: AbortablePromise[] +): Promise<{ + success: boolean; + result: TReturn | undefined; + provider: string | undefined; +}> => { + const successPromises: Promise<{ + success: boolean; + result: TReturn | undefined; + provider: string | undefined; + }>[] = []; + + for (const request of requests) { + successPromises.push( + new Promise<{ + success: boolean; + result: TReturn | undefined; + provider: string | undefined; + }>((resolve, reject) => { + request.promise.then((response) => { + const [error, result] = response; + + if (!error && result !== undefined) { + resolve({ + success: true, + result: result, + provider: request.provider, + }); + } + }, reject); + }) + ); + } + + return Promise.race(successPromises); +}; + +const gatherAllPromisesAndTrackErrors = ( + requests: AbortablePromise[], + errors: Error[] +): Promise<{ + success: boolean; + result: TReturn | undefined; + provider: string | undefined; +}> => { + return new Promise<{ + success: boolean; + result: TReturn | undefined; + provider: string | undefined; + }>((resolve, reject) => { + Promise.all( + requests.map(async (request) => { + const [error] = await request.promise; + + if (error) { + errors.push(error); + } + }) + ).then(() => { + resolve({ + success: false, + result: undefined, + provider: undefined, + }); + }, reject); + }); +}; + +const abortAllRequests = ( + requests: AbortablePromise[] +): void => { + for (const request of requests) { + request.abort(); + } +}; diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/index.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/index.ts new file mode 100644 index 0000000000..6faaf4441a --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/index.ts @@ -0,0 +1,2 @@ +export * from "./simple"; +export * from "./fallbacks"; diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/simple.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/simple.ts new file mode 100644 index 0000000000..086bc6fba7 --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/simple.ts @@ -0,0 +1,33 @@ +import { IpfsClient } from "../IpfsClient"; +import { execAbortable } from "./abortable"; + +// Executes function in a try catch and returns error (if any) and result +// If timeout is reached, it will return an error +// If timeout is 0 then it will wait until the operation is complete +export const execSimple = async ( + operation: string, + ipfs: IpfsClient, + provider: string, + timeout: number, + func: ( + ipfs: IpfsClient, + provider: string, + options: unknown + ) => Promise +): Promise => { + const { promise } = await execAbortable( + operation, + ipfs, + provider, + timeout, + func + ); + + const [error, result] = await promise; + + if (error) { + throw error; + } + + return result as TReturn; +}; From 28c5bc046323f866c13f44483edd94c0559cd19f Mon Sep 17 00:00:00 2001 From: Jure Bogunovic Date: Thu, 23 Jun 2022 16:55:30 +0200 Subject: [PATCH 16/23] removed unused functions and types --- .../ipfs-resolver/src/utils/IpfsClient.ts | 19 -- .../ipfs-resolver/src/utils/IpfsConfig.ts | 4 - .../ipfs-resolver/src/utils/exec/abortable.ts | 97 --------- .../ipfs-resolver/src/utils/exec/fallbacks.ts | 206 ------------------ .../ipfs-resolver/src/utils/exec/index.ts | 2 - .../ipfs-resolver/src/utils/exec/simple.ts | 33 --- 6 files changed, 361 deletions(-) delete mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsClient.ts delete mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsConfig.ts delete mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/abortable.ts delete mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/fallbacks.ts delete mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/index.ts delete mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/simple.ts diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsClient.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsClient.ts deleted file mode 100644 index 43063a9974..0000000000 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsClient.ts +++ /dev/null @@ -1,19 +0,0 @@ -import CID from "cids"; - -export interface IpfsClient { - add(data: Uint8Array, options?: unknown): Promise; - - cat(cid: string, options?: unknown): Promise; - - resolve( - cid: string, - options?: unknown - ): Promise<{ - path: string; - }>; -} - -export type IpfsFileInfo = { - name: string; - hash: CID; -}; diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsConfig.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsConfig.ts deleted file mode 100644 index bb55fd34e0..0000000000 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/IpfsConfig.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface IpfsConfig { - provider: string; - fallbackProviders?: string[]; -} diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/abortable.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/abortable.ts deleted file mode 100644 index 47d276c310..0000000000 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/abortable.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { IpfsClient } from "../IpfsClient"; - -import AbortController from "abort-controller"; - -const abortErrorMessage = "The user aborted a request."; - -export interface AbortablePromise { - promise: Promise<[error: Error | undefined, result: TReturn | undefined]>; - abort: () => void; - provider: string; -} - -// Returns a promise, provider and callback that can be used to cancel the request -export const execAbortable = ( - operation: string, - ipfs: IpfsClient, - provider: string, - timeout: number, - func: ( - ipfs: IpfsClient, - provider: string, - options: unknown - ) => Promise -): AbortablePromise => { - const controller = new AbortController(); - let error: Error | undefined = undefined; - - // If timer is not 0 then set a timeout to abort the execution - const timer = timeout - ? setTimeout(() => { - error = buildExecError( - operation, - provider, - timeout, - new Error("Timeout has been reached") - ); - controller.abort(); - }, timeout) - : undefined; - - const promise = new Promise< - [error: Error | undefined, result: TReturn | undefined] - >((resolve) => { - func(ipfs, provider, { - signal: controller.signal, - }).then( - (result) => { - // Clear timeout if exists - timer && clearTimeout(timer); - - if (result === undefined && !error) { - error = buildExecError( - operation, - provider, - timeout, - new Error("The provider returned an empty response") - ); - } - - resolve([error, result]); - }, - (e) => { - // Clear timeout if exists - timer && clearTimeout(timer); - - if (!e.message || e.message !== abortErrorMessage) { - error = buildExecError(operation, provider, timeout, e); - } - - resolve([error, undefined]); - } - ); - }); - - return { - promise, - provider, - abort: () => { - controller.abort(); - timer && clearTimeout(); - }, - }; -}; - -const buildExecError = ( - operation: string, - provider: string, - timeout: number, - error: Error -) => { - return new Error( - `An error occurred\nOperation: ${operation}\nProvider: ${provider}\nTimeout: ${timeout}\nError: ${JSON.stringify( - error, - Object.getOwnPropertyNames(error) - )}` - ); -}; diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/fallbacks.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/fallbacks.ts deleted file mode 100644 index 78606a312c..0000000000 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/fallbacks.ts +++ /dev/null @@ -1,206 +0,0 @@ -import { IpfsClient } from "../IpfsClient"; -import { execAbortable, AbortablePromise } from "./abortable"; - -// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, @typescript-eslint/naming-convention -const createIpfsClient = require("@dorgjelli-test/ipfs-http-client-lite"); - -export const execFallbacks = async ( - operation: string, - defaultIpfs: IpfsClient, - defaultProvider: string, - providers: string[], - timeout: number, - func: ( - ipfs: IpfsClient, - provider: string, - options: unknown - ) => Promise, - options?: { parallel?: boolean } -): Promise => { - const parallel = !!options?.parallel; - - return parallel - ? await execParallel( - operation, - defaultIpfs, - defaultProvider, - providers, - timeout, - func - ) - : await execSerial( - operation, - defaultIpfs, - defaultProvider, - providers, - timeout, - func - ); -}; - -const execSerial = async ( - operation: string, - defaultIpfs: IpfsClient, - defaultProvider: string, - providers: string[], - timeout: number, - func: ( - ipfs: IpfsClient, - provider: string, - options: unknown - ) => Promise -): Promise => { - const errors: Error[] = []; - - // Gather all requests from all providers - for (const provider of providers) { - let ipfs: IpfsClient; - - if (provider === defaultProvider) { - // If the provider is the default, we use the existing ipfs client - ipfs = defaultIpfs; - } else { - // Otherwise we create a new ipfs client from the provider - ipfs = createIpfsClient(provider); - } - - const { promise } = execAbortable(operation, ipfs, provider, timeout, func); - - const [error, result] = await promise; - - if (error) { - errors.push(error); - } else { - return result as TReturn; - } - } - - // Throw all aggregated errors - throw new Error(errors.map((x) => x.message).join("\n")); -}; - -const execParallel = async ( - operation: string, - defaultIpfs: IpfsClient, - defaultProvider: string, - providers: string[], - timeout: number, - func: ( - ipfs: IpfsClient, - provider: string, - options: unknown - ) => Promise -): Promise => { - const errors: Error[] = []; - const requests: AbortablePromise[] = []; - - // Gather all requests from all providers - for (const provider of providers) { - let ipfs: IpfsClient; - - if (provider === defaultProvider) { - // If the provider is the default, we use the existing ipfs client - ipfs = defaultIpfs; - } else { - // Otherwise we create a new ipfs client from the provider - ipfs = createIpfsClient(provider); - } - - const request = execAbortable(operation, ipfs, provider, timeout, func); - - requests.push(request); - } - - const successPromise = gatherSuccessPromises(requests); - const allPromises = gatherAllPromisesAndTrackErrors(requests, errors); - - // Wait for either the first successful request to finish - // Or for all requests to finish (they all failed) - const response = await Promise.race([successPromise, allPromises]); - - if (response.success) { - abortAllRequests(requests); - } else { - // Throw all aggregated errors - throw new Error(errors.map((x) => x.message).join("\n")); - } - - return response.result as TReturn; -}; - -const gatherSuccessPromises = async ( - requests: AbortablePromise[] -): Promise<{ - success: boolean; - result: TReturn | undefined; - provider: string | undefined; -}> => { - const successPromises: Promise<{ - success: boolean; - result: TReturn | undefined; - provider: string | undefined; - }>[] = []; - - for (const request of requests) { - successPromises.push( - new Promise<{ - success: boolean; - result: TReturn | undefined; - provider: string | undefined; - }>((resolve, reject) => { - request.promise.then((response) => { - const [error, result] = response; - - if (!error && result !== undefined) { - resolve({ - success: true, - result: result, - provider: request.provider, - }); - } - }, reject); - }) - ); - } - - return Promise.race(successPromises); -}; - -const gatherAllPromisesAndTrackErrors = ( - requests: AbortablePromise[], - errors: Error[] -): Promise<{ - success: boolean; - result: TReturn | undefined; - provider: string | undefined; -}> => { - return new Promise<{ - success: boolean; - result: TReturn | undefined; - provider: string | undefined; - }>((resolve, reject) => { - Promise.all( - requests.map(async (request) => { - const [error] = await request.promise; - - if (error) { - errors.push(error); - } - }) - ).then(() => { - resolve({ - success: false, - result: undefined, - provider: undefined, - }); - }, reject); - }); -}; - -const abortAllRequests = ( - requests: AbortablePromise[] -): void => { - for (const request of requests) { - request.abort(); - } -}; diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/index.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/index.ts deleted file mode 100644 index 6faaf4441a..0000000000 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./simple"; -export * from "./fallbacks"; diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/simple.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/simple.ts deleted file mode 100644 index 086bc6fba7..0000000000 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/utils/exec/simple.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { IpfsClient } from "../IpfsClient"; -import { execAbortable } from "./abortable"; - -// Executes function in a try catch and returns error (if any) and result -// If timeout is reached, it will return an error -// If timeout is 0 then it will wait until the operation is complete -export const execSimple = async ( - operation: string, - ipfs: IpfsClient, - provider: string, - timeout: number, - func: ( - ipfs: IpfsClient, - provider: string, - options: unknown - ) => Promise -): Promise => { - const { promise } = await execAbortable( - operation, - ipfs, - provider, - timeout, - func - ); - - const [error, result] = await promise; - - if (error) { - throw error; - } - - return result as TReturn; -}; From d1751ebc255f41162fdc21483cf73624ea4d943e Mon Sep 17 00:00:00 2001 From: Jure Bogunovic Date: Thu, 23 Jun 2022 16:55:47 +0200 Subject: [PATCH 17/23] refactored ipfs client handling in tests --- .../ipfs-resolver/jest.config.js | 21 ++++++++-------- .../ipfs-resolver/src/__tests__/e2e.spec.ts | 6 ++--- .../src/__tests__/helpers/IpfsClient.ts | 19 +++++++++++++++ .../src/__tests__/helpers/createIpfsClient.ts | 5 ++++ yarn.lock | 24 +++++++++---------- 5 files changed, 48 insertions(+), 27 deletions(-) create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/IpfsClient.ts create mode 100644 packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/createIpfsClient.ts diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/jest.config.js b/packages/js/plugins/uri-resolvers/ipfs-resolver/jest.config.js index 38888109ca..12adcff325 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/jest.config.js +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/jest.config.js @@ -1,13 +1,12 @@ module.exports = { - "roots": [ - "/src" - ], - "testMatch": [ - "**/__tests__/**/*.+(ts|tsx|js)", - "**/?(*.)+(spec|test).+(ts|tsx|js)" - ], - "transform": { - "^.+\\.(ts|tsx)$": "ts-jest" + preset: "ts-jest", + testEnvironment: "node", + testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"], + modulePathIgnorePatterns: [], + roots: ["./src/__tests__"], + globals: { + "ts-jest": { + diagnostics: false, + }, }, - testEnvironment: 'node' -} +}; diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts index 2c87e2416d..3b11236ee6 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/e2e.spec.ts @@ -9,10 +9,8 @@ import { import { ipfsResolverPlugin } from ".."; import { ipfsPlugin } from "@polywrap/ipfs-plugin-js"; - -import { IpfsClient } from "../utils/IpfsClient"; - -const createIpfsClient = require("@dorgjelli-test/ipfs-http-client-lite"); +import { IpfsClient } from "./helpers/IpfsClient"; +import { createIpfsClient } from "./helpers/createIpfsClient"; jest.setTimeout(300000); diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/IpfsClient.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/IpfsClient.ts new file mode 100644 index 0000000000..43063a9974 --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/IpfsClient.ts @@ -0,0 +1,19 @@ +import CID from "cids"; + +export interface IpfsClient { + add(data: Uint8Array, options?: unknown): Promise; + + cat(cid: string, options?: unknown): Promise; + + resolve( + cid: string, + options?: unknown + ): Promise<{ + path: string; + }>; +} + +export type IpfsFileInfo = { + name: string; + hash: CID; +}; diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/createIpfsClient.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/createIpfsClient.ts new file mode 100644 index 0000000000..d4bccf83d6 --- /dev/null +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/createIpfsClient.ts @@ -0,0 +1,5 @@ +import { IpfsClient } from "./IpfsClient"; + +export const createIpfsClient: ( + ipfsProvider: string +) => IpfsClient = require("@dorgjelli-test/ipfs-http-client-lite"); diff --git a/yarn.lock b/yarn.lock index c4327bce52..340596b44c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7285,9 +7285,9 @@ electron-fetch@^1.7.2: encoding "^0.1.13" electron-to-chromium@^1.3.378, electron-to-chromium@^1.4.164: - version "1.4.164" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.164.tgz#3d0f5c83557d8ec8a7faa531e498f198c3bd974a" - integrity sha512-K7iy5y6XyP9Pzh3uaDti0KC4JUNT6T1tLG5RTOmesqq2YgAJpYYYJ32m+anvZYjCV35llPTEh87kvEV/uSsiyQ== + version "1.4.167" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.167.tgz#72424aebc85df12c5331d37b1bcfd1ae01322c55" + integrity sha512-lPHuHXBwpkr4RcfaZBKm6TKOWG/1N9mVggUpP4fY3l1JIUU2x4fkM8928smYdZ5lF+6KCTAxo1aK9JmqT+X71Q== elliptic@6.5.4, elliptic@^6.5.3: version "6.5.4" @@ -9311,9 +9311,9 @@ http-errors@~1.6.2: statuses ">= 1.4.0 < 2" http-parser-js@>=0.5.1: - version "0.5.6" - resolved "https://registry.yarnpkg.com/http-parser-js/-/http-parser-js-0.5.6.tgz#2e02406ab2df8af8a7abfba62e0da01c62b95afd" - integrity sha512-vDlkRPDJn93swjcjqMSaGSPABbIarsr1TLAui/gLDXzV5VsJNdXNzMYDyNBLQkjWQCJ1uizu8T2oDMhmGt0PRA== + version "0.5.7" + resolved "https://registry.yarnpkg.com/http-parser-js/-/http-parser-js-0.5.7.tgz#39bde369fb8a57235121bb69d05f079fa1b598f4" + integrity sha512-8gQM8ZcewlONQLnik2AKzS13euQhaZcu4rK5QBSYOszW0T1upLW9VA2MdWvTvMmRo42HjXp7igFmdROoBCCrfg== http-proxy-agent@^4.0.1: version "4.0.1" @@ -12740,9 +12740,9 @@ multicodec@^3.0.1: varint "^6.0.0" multiformats@^9.4.2: - version "9.6.5" - resolved "https://registry.yarnpkg.com/multiformats/-/multiformats-9.6.5.tgz#f2d894a26664b454a90abf5a8911b7e39195db80" - integrity sha512-vMwf/FUO+qAPvl3vlSZEgEVFY/AxeZq5yg761ScF3CZsXgmTi/HGkicUiNN0CI4PW8FiY2P0OLklOcmQjdQJhw== + version "9.7.0" + resolved "https://registry.yarnpkg.com/multiformats/-/multiformats-9.7.0.tgz#845799e8df70fbb6b15922500e45cb87cf12f7e5" + integrity sha512-uv/tcgwk0yN4DStopnBN4GTgvaAlYdy6KnZpuzEPFOYQd71DYFJjs0MN1ERElAflrZaYyGBWXyGxL5GgrxIx0Q== multihashes@^0.4.15, multihashes@~0.4.15, multihashes@~0.4.19: version "0.4.21" @@ -17626,9 +17626,9 @@ upath@^2.0.1: integrity sha512-1uEe95xksV1O0CYKXo8vQvN1JEbtJp7lb7C5U9HMsIp6IVwntkH/oNUzyVNQSd4S1sYk2FpSSW44FqMc8qee5w== update-browserslist-db@^1.0.0: - version "1.0.3" - resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.3.tgz#6c47cb996f34afb363e924748e2f6e4d983c6fc1" - integrity sha512-ufSazemeh9Gty0qiWtoRpJ9F5Q5W3xdIPm1UZQqYQv/q0Nyb9EMHUB2lu+O9x1re9WsorpMAUu4Y6Lxcs5n+XQ== + version "1.0.4" + resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.4.tgz#dbfc5a789caa26b1db8990796c2c8ebbce304824" + integrity sha512-jnmO2BEGUjsMOe/Fg9u0oczOe/ppIDZPebzccl1yDWGLFP16Pa1/RM5wEoKYPG2zstNcDuAStejyxsOuKINdGA== dependencies: escalade "^3.1.1" picocolors "^1.0.0" From e1aead083cf20dee123a58031e99b32db8a6a76a Mon Sep 17 00:00:00 2001 From: Jure Bogunovic Date: Thu, 23 Jun 2022 19:19:37 +0200 Subject: [PATCH 18/23] locked dependencies and replaced the deprecated cids package with the multiformats package --- packages/js/plugins/ipfs/package.json | 4 +-- .../js/plugins/ipfs/src/utils/IpfsClient.ts | 2 +- .../uri-resolvers/ipfs-resolver/package.json | 4 +-- .../src/__tests__/helpers/IpfsClient.ts | 2 +- packages/js/react/package.json | 2 +- yarn.lock | 30 +++++++++++++------ 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/packages/js/plugins/ipfs/package.json b/packages/js/plugins/ipfs/package.json index e4c241fe91..a5feaade67 100644 --- a/packages/js/plugins/ipfs/package.json +++ b/packages/js/plugins/ipfs/package.json @@ -23,8 +23,8 @@ "@dorgjelli-test/ipfs-http-client-lite": "0.3.1", "@polywrap/core-js": "0.0.1-prealpha.88", "abort-controller": "3.0.0", - "cids": "^1.1.4", - "is-ipfs": "1.0.3" + "is-ipfs": "1.0.3", + "multiformats": "9.7.0" }, "devDependencies": { "@types/jest": "26.0.8", diff --git a/packages/js/plugins/ipfs/src/utils/IpfsClient.ts b/packages/js/plugins/ipfs/src/utils/IpfsClient.ts index 43063a9974..80d63207b4 100644 --- a/packages/js/plugins/ipfs/src/utils/IpfsClient.ts +++ b/packages/js/plugins/ipfs/src/utils/IpfsClient.ts @@ -1,4 +1,4 @@ -import CID from "cids"; +import { CID } from "multiformats"; export interface IpfsClient { add(data: Uint8Array, options?: unknown): Promise; diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json b/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json index b18eda42a4..2c719aff2d 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/package.json @@ -24,7 +24,6 @@ "@dorgjelli-test/ipfs-http-client-lite": "0.3.1", "@polywrap/core-js": "0.0.1-prealpha.88", "abort-controller": "3.0.0", - "cids": "^1.1.4", "is-ipfs": "1.0.3" }, "devDependencies": { @@ -35,7 +34,8 @@ "rimraf": "3.0.2", "ts-jest": "26.5.4", "ts-node": "8.10.2", - "typescript": "4.0.7" + "typescript": "4.0.7", + "multiformats": "9.7.0" }, "gitHead": "7346adaf5adb7e6bbb70d9247583e995650d390a", "publishConfig": { diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/IpfsClient.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/IpfsClient.ts index 43063a9974..80d63207b4 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/IpfsClient.ts +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/__tests__/helpers/IpfsClient.ts @@ -1,4 +1,4 @@ -import CID from "cids"; +import { CID } from "multiformats"; export interface IpfsClient { add(data: Uint8Array, options?: unknown): Promise; diff --git a/packages/js/react/package.json b/packages/js/react/package.json index 6b2af6f7fa..a32b69d4d7 100644 --- a/packages/js/react/package.json +++ b/packages/js/react/package.json @@ -35,7 +35,7 @@ "@types/react": "16.9.0", "@types/react-dom": "16.9.0", "jest": "26.6.3", - "jest-environment-jsdom": "^26.0.1", + "jest-environment-jsdom": "26.0.1", "polywrap": "0.0.1-prealpha.88", "rimraf": "3.0.2", "typescript": "4.0.7" diff --git a/yarn.lock b/yarn.lock index 340596b44c..e88cf9b92d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1988,7 +1988,7 @@ "@jest/types" "^24.9.0" jest-mock "^24.9.0" -"@jest/environment@^26.6.2": +"@jest/environment@^26.0.1", "@jest/environment@^26.6.2": version "26.6.2" resolved "https://registry.yarnpkg.com/@jest/environment/-/environment-26.6.2.tgz#ba364cc72e221e79cc8f0a99555bf5d7577cf92c" integrity sha512-nFy+fHl28zUrRsCeMB61VDThV1pVTtlEokBRgqPrcT1JNq4yRNIyTHfyht6PqtUvY9IsuLGTrbG8kPXjSZIZwA== @@ -2007,7 +2007,7 @@ jest-message-util "^24.9.0" jest-mock "^24.9.0" -"@jest/fake-timers@^26.6.2": +"@jest/fake-timers@^26.0.1", "@jest/fake-timers@^26.6.2": version "26.6.2" resolved "https://registry.yarnpkg.com/@jest/fake-timers/-/fake-timers-26.6.2.tgz#459c329bcf70cee4af4d7e3f3e67848123535aad" integrity sha512-14Uleatt7jdzefLPYM3KLcnUl1ZNikaKq34enpb5XG9i81JpppDb5muZvonvKyrl7ftEHkKS5L5/eB/kxJ+bvA== @@ -2207,7 +2207,7 @@ "@types/yargs" "^15.0.0" chalk "^3.0.0" -"@jest/types@^26.6.2": +"@jest/types@^26.0.1", "@jest/types@^26.6.2": version "26.6.2" resolved "https://registry.yarnpkg.com/@jest/types/-/types-26.6.2.tgz#bef5a532030e1d88a2f5a6d933f84e97226ed48e" integrity sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ== @@ -5760,7 +5760,7 @@ cids@^0.7.1: multicodec "^1.0.0" multihashes "~0.4.15" -cids@^1.0.0, cids@^1.1.4: +cids@^1.0.0: version "1.1.9" resolved "https://registry.yarnpkg.com/cids/-/cids-1.1.9.tgz#402c26db5c07059377bcd6fb82f2a24e7f2f4a4f" integrity sha512-l11hWRfugIcbGuTZwAM5PwpjPPjyb6UZOGwlHSnOBV5o07XhQ4gNpBN67FbODvpjyHtd+0Xs6KNvUcGBiDRsdg== @@ -10699,6 +10699,18 @@ jest-environment-jsdom-fourteen@1.0.1: jest-util "^24.0.0" jsdom "^14.1.0" +jest-environment-jsdom@26.0.1: + version "26.0.1" + resolved "https://registry.yarnpkg.com/jest-environment-jsdom/-/jest-environment-jsdom-26.0.1.tgz#217690852e5bdd7c846a4e3b50c8ffd441dfd249" + integrity sha512-u88NJa3aptz2Xix2pFhihRBAatwZHWwSiRLBDBQE1cdJvDjPvv7ZGA0NQBxWwDDn7D0g1uHqxM8aGgfA9Bx49g== + dependencies: + "@jest/environment" "^26.0.1" + "@jest/fake-timers" "^26.0.1" + "@jest/types" "^26.0.1" + jest-mock "^26.0.1" + jest-util "^26.0.1" + jsdom "^16.2.2" + jest-environment-jsdom@^24.9.0: version "24.9.0" resolved "https://registry.yarnpkg.com/jest-environment-jsdom/-/jest-environment-jsdom-24.9.0.tgz#4b0806c7fc94f95edb369a69cc2778eec2b7375b" @@ -10711,7 +10723,7 @@ jest-environment-jsdom@^24.9.0: jest-util "^24.9.0" jsdom "^11.5.1" -jest-environment-jsdom@^26.0.1, jest-environment-jsdom@^26.6.2: +jest-environment-jsdom@^26.6.2: version "26.6.2" resolved "https://registry.yarnpkg.com/jest-environment-jsdom/-/jest-environment-jsdom-26.6.2.tgz#78d09fe9cf019a357009b9b7e1f101d23bd1da3e" integrity sha512-jgPqCruTlt3Kwqg5/WVFyHIOJHsiAvhcp2qiR2QQstuG9yWox5+iHpU3ZrcBxW14T4fe5Z68jAfLRh7joCSP2Q== @@ -10925,7 +10937,7 @@ jest-mock@^24.0.0, jest-mock@^24.9.0: dependencies: "@jest/types" "^24.9.0" -jest-mock@^26.6.2: +jest-mock@^26.0.1, jest-mock@^26.6.2: version "26.6.2" resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-26.6.2.tgz#d6cb712b041ed47fe0d9b6fc3474bc6543feb302" integrity sha512-YyFjePHHp1LzpzYcmgqkJ0nm0gg/lJx2aZFzFy1S6eUqNjXsOqTK10zNRff2dNfssgokjkG65OlWNcIlgd3zew== @@ -11158,7 +11170,7 @@ jest-snapshot@^26.6.2: pretty-format "^26.6.2" semver "^7.3.2" -jest-util@26.x, jest-util@^26.1.0, jest-util@^26.6.2: +jest-util@26.x, jest-util@^26.0.1, jest-util@^26.1.0, jest-util@^26.6.2: version "26.6.2" resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-26.6.2.tgz#907535dbe4d5a6cb4c47ac9b926f6af29576cbc1" integrity sha512-MDW0fKfsn0OI7MS7Euz6h8HNDXVQ0gaM9uW6RjfDmd1DAFcaxX9OqIakHIqhbnmF08Cf2DLDG+ulq8YQQ0Lp0Q== @@ -11414,7 +11426,7 @@ jsdom@^14.1.0: ws "^6.1.2" xml-name-validator "^3.0.0" -jsdom@^16.4.0: +jsdom@^16.2.2, jsdom@^16.4.0: version "16.7.0" resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-16.7.0.tgz#918ae71965424b197c819f8183a754e18977b710" integrity sha512-u9Smc2G1USStM+s/x1ru5Sxrl6mPYCbByG1U/hUmqaVsm4tbNyS7CicOSRyuGQYZhTu0h84qkZZQ/I+dzizSVw== @@ -12739,7 +12751,7 @@ multicodec@^3.0.1: uint8arrays "^3.0.0" varint "^6.0.0" -multiformats@^9.4.2: +multiformats@9.7.0, multiformats@^9.4.2: version "9.7.0" resolved "https://registry.yarnpkg.com/multiformats/-/multiformats-9.7.0.tgz#845799e8df70fbb6b15922500e45cb87cf12f7e5" integrity sha512-uv/tcgwk0yN4DStopnBN4GTgvaAlYdy6KnZpuzEPFOYQd71DYFJjs0MN1ERElAflrZaYyGBWXyGxL5GgrxIx0Q== From fc355e236bd234efe80a908ce6664c7252d0ed61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Thu, 23 Jun 2022 22:10:32 +0200 Subject: [PATCH 19/23] Code style changes --- .../uri-resolvers/ipfs-resolver/src/index.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts index a09c3af27d..c18b91cb24 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/src/index.ts @@ -61,12 +61,7 @@ export class IpfsResolverPlugin extends Module { } } - if (manifest) { - return { uri: null, manifest }; - } else { - // Nothing found - return { uri: null, manifest: null }; - } + return { uri: null, manifest: manifest ?? null }; } public async getFile( @@ -102,11 +97,7 @@ export class IpfsResolverPlugin extends Module { client ); - if (catResult.data) { - return catResult.data; - } else { - return null; - } + return catResult.data ?? null; } catch (e) { return null; } From 85f03adff3175536c5e3ddcbd629a78cd2caa47c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Thu, 23 Jun 2022 22:20:21 +0200 Subject: [PATCH 20/23] update yarn.lock --- yarn.lock | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/yarn.lock b/yarn.lock index 07e3e5fc0b..e88cf9b92d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5604,12 +5604,7 @@ caniuse-api@^3.0.0: lodash.memoize "^4.1.2" lodash.uniq "^4.5.0" -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001035, caniuse-lite@^1.0.30001109: - version "1.0.30001357" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001357.tgz#dec7fc4158ef6ad24690d0eec7b91f32b8cb1b5d" - integrity sha512-b+KbWHdHePp+ZpNj+RDHFChZmuN+J5EvuQUlee9jOQIUAdhv9uvAZeEtUeLAknXbkiu1uxjQ9NLp1ie894CuWg== - -caniuse-lite@^1.0.30001358: +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001035, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001358: version "1.0.30001358" resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001358.tgz#473d35dabf5e448b463095cab7924e96ccfb8c00" integrity sha512-hvp8PSRymk85R20bsDra7ZTCpSVGN/PAz9pSAjPSjKC+rNmnUk5vCRgJwiTT/O4feQ/yu/drvZYpKxxhbFuChw== @@ -7289,12 +7284,7 @@ electron-fetch@^1.7.2: dependencies: encoding "^0.1.13" -electron-to-chromium@^1.3.378: - version "1.4.161" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.161.tgz#49cb5b35385bfee6cc439d0a04fbba7a7a7f08a1" - integrity sha512-sTjBRhqh6wFodzZtc5Iu8/R95OkwaPNn7tj/TaDU5nu/5EFiQDtADGAXdR4tJcTEHlYfJpHqigzJqHvPgehP8A== - -electron-to-chromium@^1.4.164: +electron-to-chromium@^1.3.378, electron-to-chromium@^1.4.164: version "1.4.167" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.167.tgz#72424aebc85df12c5331d37b1bcfd1ae01322c55" integrity sha512-lPHuHXBwpkr4RcfaZBKm6TKOWG/1N9mVggUpP4fY3l1JIUU2x4fkM8928smYdZ5lF+6KCTAxo1aK9JmqT+X71Q== @@ -12761,7 +12751,7 @@ multicodec@^3.0.1: uint8arrays "^3.0.0" varint "^6.0.0" -multiformats@^9.4.2: +multiformats@9.7.0, multiformats@^9.4.2: version "9.7.0" resolved "https://registry.yarnpkg.com/multiformats/-/multiformats-9.7.0.tgz#845799e8df70fbb6b15922500e45cb87cf12f7e5" integrity sha512-uv/tcgwk0yN4DStopnBN4GTgvaAlYdy6KnZpuzEPFOYQd71DYFJjs0MN1ERElAflrZaYyGBWXyGxL5GgrxIx0Q== From 098b5d04a576f1375a0af62c30723ba0946b9f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Sat, 25 Jun 2022 04:07:31 +0200 Subject: [PATCH 21/23] fix IPFS plugin manifest import redirect --- .../js/plugins/uri-resolvers/ipfs-resolver/polywrap.plugin.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/polywrap.plugin.yaml b/packages/js/plugins/uri-resolvers/ipfs-resolver/polywrap.plugin.yaml index 71f3f69881..412bf5e965 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/polywrap.plugin.yaml +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/polywrap.plugin.yaml @@ -5,6 +5,6 @@ module: ./src/index.ts schema: ./src/schema.graphql import_redirects: - uri: "ens/uri-resolver.core.polywrap.eth" - schema: ../../../../core-interfaces/uri-resolver/src/query.graphql + schema: ../../../../core-interfaces/uri-resolver/src/schema.graphql - uri: "ens/ipfs.polywrap.eth" schema: ../../../../core-interfaces/ipfs/build/schema.graphql From 3b3d37de9f2e7ad6eb8f903be1fdd1cf5bd1deae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CPileks=E2=80=9D?= Date: Sat, 25 Jun 2022 04:09:20 +0200 Subject: [PATCH 22/23] IPFS Resolver manifest correct name --- .../js/plugins/uri-resolvers/ipfs-resolver/polywrap.plugin.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/plugins/uri-resolvers/ipfs-resolver/polywrap.plugin.yaml b/packages/js/plugins/uri-resolvers/ipfs-resolver/polywrap.plugin.yaml index 412bf5e965..fbf84d2214 100644 --- a/packages/js/plugins/uri-resolvers/ipfs-resolver/polywrap.plugin.yaml +++ b/packages/js/plugins/uri-resolvers/ipfs-resolver/polywrap.plugin.yaml @@ -1,5 +1,5 @@ format: 0.0.1-prealpha.3 -name: Ipfs +name: IpfsResolver language: plugin/typescript module: ./src/index.ts schema: ./src/schema.graphql From b056f871a740a7b853f5c7b8e7acf1878e8c4349 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Mon, 27 Jun 2022 12:51:10 -0700 Subject: [PATCH 23/23] remove unnecessary .gitignore + .nvmrc files --- packages/core-interfaces/file-system/.gitignore | 3 --- packages/core-interfaces/ipfs/.gitignore | 3 --- packages/core-interfaces/ipfs/.nvmrc | 1 - packages/core-interfaces/logger/.gitignore | 2 -- packages/core-interfaces/uri-resolver/.gitignore | 2 -- .../js/plugins/uri-resolvers/file-system-resolver/.gitignore | 2 -- packages/js/react/.gitignore | 1 - 7 files changed, 14 deletions(-) delete mode 100644 packages/core-interfaces/file-system/.gitignore delete mode 100644 packages/core-interfaces/ipfs/.gitignore delete mode 100644 packages/core-interfaces/ipfs/.nvmrc delete mode 100644 packages/core-interfaces/logger/.gitignore delete mode 100644 packages/core-interfaces/uri-resolver/.gitignore delete mode 100644 packages/js/plugins/uri-resolvers/file-system-resolver/.gitignore delete mode 100644 packages/js/react/.gitignore diff --git a/packages/core-interfaces/file-system/.gitignore b/packages/core-interfaces/file-system/.gitignore deleted file mode 100644 index edd2cc9ab1..0000000000 --- a/packages/core-interfaces/file-system/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -build -node_modules -wrap \ No newline at end of file diff --git a/packages/core-interfaces/ipfs/.gitignore b/packages/core-interfaces/ipfs/.gitignore deleted file mode 100644 index edd2cc9ab1..0000000000 --- a/packages/core-interfaces/ipfs/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -build -node_modules -wrap \ No newline at end of file diff --git a/packages/core-interfaces/ipfs/.nvmrc b/packages/core-interfaces/ipfs/.nvmrc deleted file mode 100644 index 5dbac1ed0f..0000000000 --- a/packages/core-interfaces/ipfs/.nvmrc +++ /dev/null @@ -1 +0,0 @@ -v16.13.0 \ No newline at end of file diff --git a/packages/core-interfaces/logger/.gitignore b/packages/core-interfaces/logger/.gitignore deleted file mode 100644 index e3fbd98336..0000000000 --- a/packages/core-interfaces/logger/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -build -node_modules diff --git a/packages/core-interfaces/uri-resolver/.gitignore b/packages/core-interfaces/uri-resolver/.gitignore deleted file mode 100644 index e3fbd98336..0000000000 --- a/packages/core-interfaces/uri-resolver/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -build -node_modules diff --git a/packages/js/plugins/uri-resolvers/file-system-resolver/.gitignore b/packages/js/plugins/uri-resolvers/file-system-resolver/.gitignore deleted file mode 100644 index 563ba71918..0000000000 --- a/packages/js/plugins/uri-resolvers/file-system-resolver/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/node_modules -/build \ No newline at end of file diff --git a/packages/js/react/.gitignore b/packages/js/react/.gitignore deleted file mode 100644 index 41b5d9ec55..0000000000 --- a/packages/js/react/.gitignore +++ /dev/null @@ -1 +0,0 @@ -thread.js \ No newline at end of file