diff --git a/package.json b/package.json index b11160c283..b1ecc3e4f3 100644 --- a/package.json +++ b/package.json @@ -70,5 +70,9 @@ "lerna": "4.0.0", "prettier": "2.2.1", "rimraf": "3.0.2" + }, + "resolutions": { + "@types/react": "16.9.0", + "@types/react-dom": "16.9.0" } } diff --git a/packages/js/client/src/__tests__/core/wasm-wrapper.spec.ts b/packages/js/client/src/__tests__/core/wasm-wrapper.spec.ts index faeefb88ac..e3ce638d3c 100644 --- a/packages/js/client/src/__tests__/core/wasm-wrapper.spec.ts +++ b/packages/js/client/src/__tests__/core/wasm-wrapper.spec.ts @@ -2,9 +2,8 @@ import { buildWrapper } from "@polywrap/test-env-js"; import { msgpackDecode } from "@polywrap/msgpack-js"; import { GetPathToTestWrappers } from "@polywrap/test-cases"; import fs from "fs"; -import { Uri, Subscription, PolywrapClient, IWrapPackage } from "../.."; +import { Uri, PolywrapClient, IWrapPackage } from "../.."; import { WrapManifest } from "@polywrap/wrap-manifest-types-js"; -import { makeMemoryStoragePlugin } from "../e2e/memory-storage"; import { PluginModule, PluginPackage } from "@polywrap/plugin-js"; import { UriResolver } from "@polywrap/uri-resolvers-js"; import { ErrResult } from "../utils/resultTypes"; @@ -16,15 +15,9 @@ jest.setTimeout(200000); const simpleWrapperPath = `${GetPathToTestWrappers()}/wasm-as/simple`; const simpleWrapperUri = new Uri(`fs/${simpleWrapperPath}/build`); -const memoryStoragePluginUri = "wrap://ens/memory-storage.polywrap.eth"; - -const simpleMemoryWrapperPath = `${GetPathToTestWrappers()}/wasm-as/simple-memory`; -const simpleMemoryWrapperUri = new Uri(`fs/${simpleMemoryWrapperPath}/build`); - describe("wasm-wrapper", () => { beforeAll(async () => { await buildWrapper(simpleWrapperPath); - await buildWrapper(simpleMemoryWrapperPath); }); const mockPlugin = (): IWrapPackage => { @@ -229,104 +222,4 @@ describe("wasm-wrapper", () => { "client.getFile(...) is not implemented for Plugins." ); }); - - test("subscribe", async () => { - const client = new PolywrapClient({ - resolvers: [ - { - uri: memoryStoragePluginUri, - package: makeMemoryStoragePlugin({}), - }, - ], - }); - - // test subscription - let expectedResults: number[] = []; - let results: number[] = []; - let value = 0; - - const setter = setInterval(async () => { - expectedResults.push(value); - - await client.invoke({ - uri: simpleMemoryWrapperUri.uri, - method: "setData", - args: { - value: value++, - }, - }); - }, 500); - - const getSubscription: Subscription = client.subscribe({ - uri: simpleMemoryWrapperUri.uri, - method: "getData", - frequency: { ms: 650 }, - }); - - for await (let result of getSubscription) { - if (!result.ok) fail(result.error); - const val = result.value; - - if (val !== undefined) { - results.push(val); - if (results.length >= 2) { - break; - } - } - } - clearInterval(setter); - - expect(results).toStrictEqual(expectedResults); - }); - - test("subscription early stop", async () => { - const client = new PolywrapClient({ - resolvers: [ - { - uri: memoryStoragePluginUri, - package: makeMemoryStoragePlugin({}), - }, - ], - }); - - // test subscription - let results: number[] = []; - let value = 0; - - const setter = setInterval(async () => { - await client.invoke({ - uri: simpleMemoryWrapperUri.uri, - method: "setData", - args: { - value: value++, - }, - }); - }, 500); - - const getSubscription: Subscription = client.subscribe({ - uri: simpleMemoryWrapperUri.uri, - method: "getData", - frequency: { ms: 550 }, - }); - - new Promise(async () => { - for await (let result of getSubscription) { - if (!result.ok) fail(result.error); - const val = result.value; - - if (val !== undefined) { - results.push(val); - if (val >= 2) { - break; - } - } - } - }); - await new Promise((r) => setTimeout(r, 1000)); - getSubscription.stop(); - clearInterval(setter); - - expect(results).toContain(0); - expect(results).not.toContain(2); - }); }); diff --git a/packages/js/core-client/src/PolywrapCoreClient.ts b/packages/js/core-client/src/PolywrapCoreClient.ts index b08e57d4fe..1fcd2b8db7 100644 --- a/packages/js/core-client/src/PolywrapCoreClient.ts +++ b/packages/js/core-client/src/PolywrapCoreClient.ts @@ -10,20 +10,14 @@ import { InterfaceImplementations, InvokeOptions, InvokerOptions, - QueryOptions, - SubscribeOptions, - Subscription, Uri, - createQueryDocument, getImplementations, - parseQuery, TryResolveUriOptions, IUriResolver, IUriResolutionContext, UriPackageOrWrapper, UriResolutionContext, getEnvFromUriHistory, - QueryResult, InvokeResult, ValidateOptions, buildCleanUriHistory, @@ -226,106 +220,6 @@ export class PolywrapCoreClient implements CoreClient { return ResultOk(uris); } - /** - * Invoke a wrapper using GraphQL query syntax - * - * @remarks - * This method behaves similar to the invoke method and allows parallel requests, - * but the syntax is more verbose. If the query is successful, data will be returned - * and the `error` value of the returned object will be undefined. If the query fails, - * the data property will be undefined and the error property will be populated. - * - * @param options - { - * // The Wrapper's URI - * uri: TUri; - * - * // The GraphQL query to parse and execute, leading to one or more Wrapper invocations. - * query: string | QueryDocument; - * - * // Variables referenced within the query string via GraphQL's '$variable' syntax. - * variables?: TVariables; - * } - * - * @returns A Promise containing an object with either the data or an error - */ - @Tracer.traceMethod("PolywrapClient: query", TracingLevel.High) - public async query< - TData extends Record = Record, - TVariables extends Record = Record, - TUri extends Uri | string = string - >(options: QueryOptions): Promise> { - let result: QueryResult; - - err: try { - const typedOptions: QueryOptions = { - ...options, - uri: Uri.from(options.uri), - }; - - const { uri, query, variables } = typedOptions; - - // Convert the query string into a query document - const queryDocument = - typeof query === "string" ? createQueryDocument(query) : query; - - // Parse the query to understand what's being invoked - const parseResult = parseQuery(uri, queryDocument, variables); - if (!parseResult.ok) { - result = { errors: [parseResult.error as Error] }; - break err; - } - const queryInvocations = parseResult.value; - - // Execute all invocations in parallel - const parallelInvocations: Promise<{ - name: string; - result: InvokeResult; - }>[] = []; - - for (const invocationName of Object.keys(queryInvocations)) { - parallelInvocations.push( - this.invoke({ - ...queryInvocations[invocationName], - uri: queryInvocations[invocationName].uri, - }).then((result) => ({ - name: invocationName, - result, - })) - ); - } - - // Await the invocations - const invocationResults = await Promise.all(parallelInvocations); - - Tracer.addEvent("invocationResults", invocationResults); - - // Aggregate all invocation results - const data: Record = {}; - const errors: Error[] = []; - - for (const invocation of invocationResults) { - if (invocation.result.ok) { - data[invocation.name] = invocation.result.value; - } else { - errors.push(invocation.result.error as Error); - } - } - - result = { - data: data as TData, - errors: errors.length === 0 ? undefined : errors, - }; - } catch (error: unknown) { - if (Array.isArray(error)) { - result = { errors: error }; - } else { - result = { errors: [error as Error] }; - } - } - - return result; - } - /** * Invoke a wrapper using standard syntax and an instance of the wrapper * @@ -456,117 +350,6 @@ export class PolywrapCoreClient implements CoreClient { } } - /** - * Invoke a wrapper at a regular frequency (within ~16ms) - * - * @param options - { - * // The Wrapper's URI - * uri: TUri; - * - * // Method to be executed. - * method: string; - * - * //Arguments for the method, structured as a map, removing the chance of incorrectly ordering arguments. - * args?: Record | Uint8Array; - * - * // Env variables for the wrapper invocation. - * env?: Record; - * - * resolutionContext?: IUriResolutionContext; - * - * // if true, return value is a msgpack-encoded byte array - * encodeResult?: boolean; - * - * // the frequency at which to perform the invocation - * frequency?: { - * ms?: number; - * sec?: number; - * min?: number; - * hours?: number; - * } - * } - * - * @returns A Promise with a Result containing the return value or an error - */ - @Tracer.traceMethod("PolywrapClient: subscribe") - public subscribe( - options: SubscribeOptions - ): Subscription { - // eslint-disable-next-line @typescript-eslint/no-this-alias - const thisClient: PolywrapCoreClient = this; - - const typedOptions: SubscribeOptions = { - ...options, - uri: Uri.from(options.uri), - }; - const { uri, method, args, frequency: freq } = typedOptions; - - // calculate interval between invokes, in milliseconds, 1 min default value - /* eslint-disable prettier/prettier */ - let frequency: number; - if (freq && (freq.ms || freq.sec || freq.min || freq.hours)) { - frequency = - (freq.ms ?? 0) + - ((freq.hours ?? 0) * 3600 + (freq.min ?? 0) * 60 + (freq.sec ?? 0)) * - 1000; - } else { - frequency = 60000; - } - /* eslint-enable prettier/prettier */ - - const subscription: Subscription = { - frequency: frequency, - isActive: false, - stop(): void { - subscription.isActive = false; - }, - async *[Symbol.asyncIterator](): AsyncGenerator> { - let timeout: NodeJS.Timeout | undefined = undefined; - subscription.isActive = true; - - try { - let readyVals = 0; - let sleep: ((value?: unknown) => void) | undefined; - - timeout = setInterval(() => { - readyVals++; - if (sleep) { - sleep(); - sleep = undefined; - } - }, frequency); - - while (subscription.isActive) { - if (readyVals === 0) { - await new Promise((r) => (sleep = r)); - } - - for (; readyVals > 0; readyVals--) { - if (!subscription.isActive) { - break; - } - - const result = await thisClient.invoke({ - uri: uri, - method: method, - args: args, - }); - - yield result; - } - } - } finally { - if (timeout) { - clearInterval(timeout); - } - subscription.isActive = false; - } - }, - }; - - return subscription; - } - /** * Resolve a URI to a wrap package, a wrapper, or a uri * diff --git a/packages/js/core/package.json b/packages/js/core/package.json index cbbceabb5f..7e3d509374 100644 --- a/packages/js/core/package.json +++ b/packages/js/core/package.json @@ -21,9 +21,7 @@ "dependencies": { "@polywrap/result": "0.10.0-pre.6", "@polywrap/tracing-js": "0.10.0-pre.6", - "@polywrap/wrap-manifest-types-js": "0.10.0-pre.6", - "graphql": "15.5.0", - "graphql-tag": "2.10.4" + "@polywrap/wrap-manifest-types-js": "0.10.0-pre.6" }, "devDependencies": { "@types/jest": "26.0.8", diff --git a/packages/js/core/src/__tests__/MaybeAsync.spec.ts b/packages/js/core/src/__tests__/MaybeAsync.spec.ts index f23280de65..f9a297991d 100644 --- a/packages/js/core/src/__tests__/MaybeAsync.spec.ts +++ b/packages/js/core/src/__tests__/MaybeAsync.spec.ts @@ -1,4 +1,4 @@ -import { MaybeAsync, isPromise } from ".."; +import { MaybeAsync } from ".."; interface IClassInterface { normalMethod(arg: string): MaybeAsync; diff --git a/packages/js/core/src/__tests__/parse-query.spec.ts b/packages/js/core/src/__tests__/parse-query.spec.ts deleted file mode 100644 index 55506b17ff..0000000000 --- a/packages/js/core/src/__tests__/parse-query.spec.ts +++ /dev/null @@ -1,357 +0,0 @@ -import { createQueryDocument, parseQuery, QueryInvocations, Uri } from "../"; -import { ResultOk } from "@polywrap/result"; - -describe("parseQuery", () => { - const dummy = new Uri("wrap://dumb/dummy"); - - it("works in the typical case", () => { - const doc = createQueryDocument(` - mutation { - someMethod( - arg1: "hey" - arg2: 4 - arg3: true - arg4: null - arg5: ["hey", "there", [5.5]] - arg6: { - prop: "hey" - obj: { - prop: 5 - var: $varOne - } - } - var1: $varOne - var2: $varTwo - ) { - someResult { - prop1 - prop2 - } - } - } - `); - - const result = parseQuery(dummy, doc, { - varOne: "var 1", - // eslint-disable-next-line @typescript-eslint/naming-convention - varTwo: 55, - }); - - const expected: QueryInvocations = { - someMethod: { - uri: dummy, - method: "someMethod", - args: { - arg1: "hey", - arg2: 4, - arg3: true, - arg4: null, - arg5: ["hey", "there", [5.5]], - arg6: { - prop: "hey", - obj: { - prop: 5, - var: "var 1" - }, - }, - var1: "var 1", - var2: 55, - }, - } - }; - - expect(result).toMatchObject(ResultOk(expected)); - }); - - it("works with multiple queries", () => { - const moduleMethods = ` - someMethod( - arg1: 4 - arg2: ["hey", "there", [5.5]] - arg3: { - prop: "hey" - obj: { - prop: 5 - } - } - var1: $varOne - var2: $varTwo - ) { - someResult { - prop1 - prop2 - } - } - - anotherMethod( - arg: "hey" - var: $varOne - ) { - resultOne - resultTwo { - prop - } - } - `; - const mutationMethods = ` - mutationSomeMethod: someMethod( - arg1: 4 - arg2: ["hey", "there", [5.5]] - arg3: { - prop: "hey" - obj: { - prop: 5 - } - } - var1: $varOne - var2: $varTwo - ) { - someResult { - prop1 - prop2 - } - } - - mutationAnotherMethod: anotherMethod( - arg: "hey" - var: $varOne - ) { - resultOne - resultTwo { - prop - } - } - `; - const doc = createQueryDocument(` - mutation { - ${mutationMethods} - } - query { - ${moduleMethods} - } - `); - - const result = parseQuery(dummy, doc, { - varOne: "var 1", - varTwo: 55, - }); - - const method1: QueryInvocations = { - someMethod: { - uri: dummy, - method: "someMethod", - args: { - arg1: 4, - arg2: ["hey", "there", [5.5]], - arg3: { - prop: "hey", - obj: { - prop: 5, - }, - }, - var1: "var 1", - var2: 55, - }, - } - }; - const method2: QueryInvocations = { - anotherMethod: { - uri: dummy, - method: "anotherMethod", - args: { - arg: "hey", - var: "var 1", - }, - } - }; - - const expected: QueryInvocations = { - ...method1, - ...method2, - mutationSomeMethod: method1.someMethod, - mutationAnotherMethod: method2.anotherMethod, - }; - - expect(result).toMatchObject(ResultOk(expected)); - }); - - it("fails when given an empty document", () => { - const doc = createQueryDocument("{ prop }"); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (doc.definitions as any) = []; - const result = parseQuery(dummy, doc); - - expect (result.ok).toBeFalsy(); - if (result.ok) { - throw Error("This should never happen"); - } - - const error = result.error?.message; - expect(error).toContain("Empty query document found"); - }); - - it("fails when a query operations isn't specified", () => { - const doc = createQueryDocument("fragment Something on Type { something }"); - const result = parseQuery(dummy, doc); - - expect (result.ok).toBeFalsy(); - if (result.ok) { - throw Error("This should never happen"); - } - - const error = result.error?.message; - expect(error).toContain("Unrecognized root level definition type"); - }); - - it("fails when method is missing", () => { - const doc = createQueryDocument(`query { something }`); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (doc.definitions[0] as any).selectionSet.selections = []; - const result = parseQuery(dummy, doc); - - expect (result.ok).toBeFalsy(); - if (result.ok) { - throw Error("This should never happen"); - } - - const error = result.error?.message; - expect(error).toContain("Empty selection set found"); - }); - - it("fails when a fragment spread is used within an operations", () => { - const doc = createQueryDocument(`query { ...NamedFragment }`); - const result = parseQuery(dummy, doc); - - expect (result.ok).toBeFalsy(); - if (result.ok) { - throw Error("This should never happen"); - } - - const error = result.error?.message; - expect(error).toContain("Unsupported selection type found: FragmentSpread"); - }); - - it("fails when variables were not specified", () => { - const doc = createQueryDocument(` - mutation { - someMethod( - arg1: $arg_1 - ) - } - `); - const result = parseQuery(dummy, doc); - - expect (result.ok).toBeFalsy(); - if (result.ok) { - throw Error("This should never happen"); - } - - const error = result.error?.message; - expect(error).toContain("Variables were not specified"); - }); - - it("fails when variables is missing", () => { - const doc = createQueryDocument(` - mutation { - someMethod( - arg1: $arg_1 - ) - } - `); - const result = parseQuery(dummy, doc, { arg2: "not arg1" }); - - expect (result.ok).toBeFalsy(); - if (result.ok) { - throw Error("This should never happen"); - } - - const error = result.error?.message; - expect(error).toContain("Missing variable"); - }); - - it("succeeds when variables is defined by falsy", () => { - const doc = createQueryDocument(` - mutation { - someMethod( - arg1: $arg_1 - ) - } - `); - const result = parseQuery(dummy, doc, { arg_1: 0 }); - expect (result.ok).toBeTruthy(); - }); - - it("fails when duplicate args arguments are provided", () => { - const doc = createQueryDocument(` - mutation { - someMethod( - arg1: 5 - arg1: "hey" - ) - } - `); - const result = parseQuery(dummy, doc); - - expect (result.ok).toBeFalsy(); - if (result.ok) { - throw Error("This should never happen"); - } - - const error = result.error?.message; - expect(error).toContain("Duplicate arguments found"); - }); - - it("fails when duplicate aliases found", () => { - const doc = createQueryDocument(` - mutation { - alias: method( - arg: "hey" - ) { - result - } - - alias: method2( - arg: "hey" - ) { - result - } - } - `); - const result = parseQuery(dummy, doc); - - expect (result.ok).toBeFalsy(); - if (result.ok) { - throw Error("This should never happen"); - } - - const error = result.error?.message; - expect(error).toContain(`Duplicate query name found "alias"`); - }); - - it("fails when duplicate methods without alias found", () => { - const doc = createQueryDocument(` - mutation { - method( - arg: "hey" - ) { - result - } - - method( - arg: "hey" - ) { - result - } - } - `); - const result = parseQuery(dummy, doc); - - expect (result.ok).toBeFalsy(); - if (result.ok) { - throw Error("This should never happen"); - } - - const error = result.error?.message; - expect(error).toContain(`Duplicate query name found "method"`); - }); -}); diff --git a/packages/js/core/src/algorithms/index.ts b/packages/js/core/src/algorithms/index.ts index bcf5cd1317..7d9e2ed2f1 100644 --- a/packages/js/core/src/algorithms/index.ts +++ b/packages/js/core/src/algorithms/index.ts @@ -1,5 +1,4 @@ export * from "./GetImplementationsError"; export * from "./applyResolution"; export * from "./get-implementations"; -export * from "./parse-query"; export * from "./clean-uri-history"; diff --git a/packages/js/core/src/algorithms/parse-query.ts b/packages/js/core/src/algorithms/parse-query.ts deleted file mode 100644 index db52f75990..0000000000 --- a/packages/js/core/src/algorithms/parse-query.ts +++ /dev/null @@ -1,188 +0,0 @@ -import { QueryInvocations, QueryDocument, Uri } from "../types"; - -import { SelectionSetNode, ValueNode } from "graphql"; -import { Tracer } from "@polywrap/tracing-js"; -import { Result, ResultErr, ResultOk } from "@polywrap/result"; - -export const parseQuery = Tracer.traceFunc( - "core: parseQuery", - ( - uri: Uri, - doc: QueryDocument, - variables?: Record - ): Result, Error> => { - if (doc.definitions.length === 0) { - return ResultErr(Error("Empty query document found.")); - } - - const queryInvocations: QueryInvocations = {}; - - for (const def of doc.definitions) { - if (def.kind !== "OperationDefinition") { - const error = Error( - `Unrecognized root level definition type: ${def.kind}\n` + - "Please use a 'query' or 'mutation' operations." - ); - return ResultErr(error); - } - - // Get the method name - const selectionSet = def.selectionSet; - const selections = selectionSet.selections; - - if (selections.length === 0) { - const error = Error( - "Empty selection set found. Please include the name of a method you'd like to query." - ); - return ResultErr(error); - } - - for (const selection of selections) { - if (selection.kind !== "Field") { - const error = Error( - `Unsupported selection type found: ${selection.kind}\n` + - "Please query a method." - ); - return ResultErr(error); - } - - const method = selection.name.value; - const invocationName = selection.alias ? selection.alias.value : method; - - if (queryInvocations[invocationName]) { - const error = Error( - `Duplicate query name found "${invocationName}". Please use GraphQL aliases that each have unique names.` - ); - return ResultErr(error); - } - - // Get all arguments - const selectionArgs = selection.arguments; - const args: Record = {}; - - if (selectionArgs) { - for (const arg of selectionArgs) { - const name = arg.name.value; - - if (args[name]) { - return ResultErr(Error(`Duplicate arguments found: ${name}`)); - } - - const extractionResult = extractValue(arg.value, variables); - if (!extractionResult.ok) { - return extractionResult; - } - args[name] = extractionResult.value; - } - } - - queryInvocations[invocationName] = { - uri, - method, - args, - }; - } - } - - return ResultOk(queryInvocations); - } -); - -const extractValue = Tracer.traceFunc( - "core: extractValue", - ( - node: ValueNode, - variables?: Record - ): Result => { - if (node.kind === "Variable") { - // Get the argument's value from the variables object - if (!variables) { - const error = Error( - `Variables were not specified, tried to resolve variable from query. Name: ${node.name.value}\n` - ); - return ResultErr(error); - } - - if (variables[node.name.value] === undefined) { - return ResultErr(Error(`Missing variable: ${node.name.value}`)); - } - - return ResultOk(variables[node.name.value]); - } else if ( - node.kind === "StringValue" || - node.kind === "EnumValue" || - node.kind === "BooleanValue" - ) { - return ResultOk(node.value); - } else if (node.kind === "IntValue") { - return ResultOk(Number.parseInt(node.value)); - } else if (node.kind === "FloatValue") { - return ResultOk(Number.parseFloat(node.value)); - } else if (node.kind === "NullValue") { - return ResultOk(null); - } else if (node.kind === "ListValue") { - const length = node.values.length; - const list = []; - - for (let i = 0; i < length; ++i) { - const extractionResult = extractValue(node.values[i], variables); - if (!extractionResult.ok) { - return extractionResult; - } - list.push(extractionResult.value); - } - - return ResultOk(list); - } else if (node.kind === "ObjectValue") { - const length = node.fields.length; - const object: Record = {}; - - for (let i = 0; i < length; ++i) { - const field = node.fields[i]; - const extractionResult = extractValue(field.value, variables); - if (!extractionResult.ok) { - return extractionResult; - } - object[field.name.value] = extractionResult.value; - } - - return ResultOk(object); - } else { - return ResultErr(Error(`Unsupported value node: ${node}`)); - } - } -); - -export const extractSelections = Tracer.traceFunc( - "core: extractSelections", - (node: SelectionSetNode): Result, Error> => { - const result: Record = {}; - - for (const selection of node.selections) { - if (selection.kind !== "Field") { - const error = Error( - `Unsupported result selection type found: ${selection.kind}` - ); - return ResultErr(error); - } - - const name = selection.name.value; - - if (result[name]) { - return ResultErr(Error(`Duplicate result selections found: ${name}`)); - } - - if (selection.selectionSet) { - const selectionsResult = extractSelections(selection.selectionSet); - if (!selectionsResult.ok) { - return selectionsResult; - } - result[name] = selectionsResult.value; - } else { - result[name] = true; - } - } - - return ResultOk(result); - } -); diff --git a/packages/js/core/src/types/CoreClient.ts b/packages/js/core/src/types/CoreClient.ts index 1b6904eaed..a81768fdc3 100644 --- a/packages/js/core/src/types/CoreClient.ts +++ b/packages/js/core/src/types/CoreClient.ts @@ -1,11 +1,4 @@ -import { - QueryHandler, - Invoker, - SubscriptionHandler, - Uri, - InterfaceImplementations, - Env, -} from "."; +import { Invoker, Uri, InterfaceImplementations, Env } from "."; import { IUriResolutionContext, IUriResolver } from "../uri-resolution"; import { UriResolverHandler } from "./UriResolver"; @@ -37,11 +30,7 @@ export interface ValidateOptions { recursive?: boolean; } -export interface CoreClient - extends Invoker, - QueryHandler, - SubscriptionHandler, - UriResolverHandler { +export interface CoreClient extends Invoker, UriResolverHandler { getConfig(): CoreClientConfig; getInterfaces(): readonly InterfaceImplementations[] | undefined; diff --git a/packages/js/core/src/types/Query.ts b/packages/js/core/src/types/Query.ts deleted file mode 100644 index 5bcd019e82..0000000000 --- a/packages/js/core/src/types/Query.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { Uri, InvokeOptions } from "./"; - -import { Tracer } from "@polywrap/tracing-js"; -import { DocumentNode } from "graphql"; -import gql from "graphql-tag"; - -/** GraphQL QueryDocument */ -export type QueryDocument = DocumentNode; - -/** Create a GraphQL QueryDocument by parsing a string */ -export const createQueryDocument = Tracer.traceFunc( - "core: createQueryDocument", - (query: string): QueryDocument => { - return gql(query); - } -); - -/** Options required for an Wrapper query. */ -export interface QueryOptions< - TVariables extends Record = Record, - TUri extends Uri | string = string -> { - /** The Wrapper's URI */ - uri: TUri; - - /** - * The GraphQL query to parse and execute, leading to one or more - * Wrapper invocations. - */ - query: string | QueryDocument; - - /** - * Variables referenced within the query string via GraphQL's '$variable' syntax. - */ - variables?: TVariables; -} - -/** - * The result of an Wrapper query, which is the aggregate - * of one or more [[InvokeResult | invocation results]]. - * - * @template TData Type of the query result data. - */ -export interface QueryResult< - TData extends Record = Record -> { - /** - * Query result data. The type of this value is a named map, - * where the key is the method's name, and value is the [[InvokeResult]]'s data. - * This is done to allow for parallel invocations within a - * single query document. In case of method name collisions, - * a postfix of `_0` will be applied, where 0 will be incremented for - * each occurrence. If undefined, it means something went wrong. - * Errors should be populated with information as to what happened. - * Null is used to represent an intentionally null result. - */ - data?: TData; - - /** Errors encountered during the query. */ - errors?: Error[]; -} - -export interface QueryInvocations { - [methodOrAlias: string]: InvokeOptions; -} - -/** A type that can parse & execute a given query */ -export interface QueryHandler { - query< - TData extends Record = Record, - TVariables extends Record = Record, - TUri extends Uri | string = string - >( - options: QueryOptions - ): Promise>; -} diff --git a/packages/js/core/src/types/Subscription.ts b/packages/js/core/src/types/Subscription.ts deleted file mode 100644 index 6559620b9d..0000000000 --- a/packages/js/core/src/types/Subscription.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { Uri } from "./Uri"; -import { InvokeOptions, InvokeResult } from "./Invoke"; - -/** Defines the frequency of Wrapper invocations for an Wrapper subscription */ -export interface SubscriptionFrequency { - ms?: number; - sec?: number; - min?: number; - hours?: number; -} - -/** Options required for an Wrapper subscription. */ -export interface SubscribeOptions - extends InvokeOptions { - /** - * The frequency of Wrapper invocations. Defaults to one query per minute. - */ - frequency?: SubscriptionFrequency; -} - -/** - * An Wrapper subscription, which implements the AsyncIterator protocol, is an - * AsyncIterable that yields query results at a specified frequency. - * @template TData Type of the query result. - */ -export interface Subscription { - /** - * The frequency of Wrapper invocations. - */ - frequency: number; - /** - * Indicates whether the subscription is currently active. - */ - isActive: boolean; - /** - * Stops subscription. If a query has been called but has not yet returned, - * that query will be completed and its result will be yielded. - */ - stop(): void; - /** - * Implementation of AsyncIterator protocol makes the Subscription an - * AsyncIterable, allowing use in for await...of loops. - */ - [Symbol.asyncIterator](): AsyncGenerator>; -} - -export interface SubscriptionHandler { - subscribe( - options: SubscribeOptions - ): Subscription; -} diff --git a/packages/js/core/src/types/index.ts b/packages/js/core/src/types/index.ts index 462080bc83..b387559098 100644 --- a/packages/js/core/src/types/index.ts +++ b/packages/js/core/src/types/index.ts @@ -2,8 +2,6 @@ export * from "./Wrapper"; export * from "./CoreClient"; export * from "./Invoke"; export * from "./MaybeAsync"; -export * from "./Query"; -export * from "./Subscription"; export * from "./Uri"; export * from "./Env"; export * from "./InterfaceImplementations"; diff --git a/yarn.lock b/yarn.lock index 2695bdfa84..f0b7604aae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3751,16 +3751,7 @@ dependencies: "@types/react" "*" -"@types/react@*": - version "18.0.26" - resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.26.tgz#8ad59fc01fef8eaf5c74f4ea392621749f0b7917" - integrity sha512-hCR3PJQsAIXyxhTNSiDFY//LhnMZWpNNr5etoCqx/iUfGc5gXWtQR2Phl908jVR6uPXacojQWTg4qRpkxTuGug== - dependencies: - "@types/prop-types" "*" - "@types/scheduler" "*" - csstype "^3.0.2" - -"@types/react@16.9.0": +"@types/react@*", "@types/react@16.9.0": version "16.9.0" resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.0.tgz#27434f16d889a335eb4626d1f1e67eda54039e5b" integrity sha512-eOct1hyZI9YZf/eqNlYu7jxA9qyTw1EGXruAJhHhBDBpc00W0C1vwlnh+hkOf7UFZkNK+UxnFBpwAZe3d7XJhQ== @@ -3776,11 +3767,6 @@ "@types/glob" "*" "@types/node" "*" -"@types/scheduler@*": - version "0.16.2" - resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39" - integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew== - "@types/semver@7.3.8": version "7.3.8" resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.8.tgz#508a27995498d7586dcecd77c25e289bfaf90c59" @@ -6625,11 +6611,6 @@ csstype@^2.2.0: resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.21.tgz#2efb85b7cc55c80017c66a5ad7cbd931fda3a90e" integrity sha512-Z1PhmomIfypOpoMjRQB70jfvy/wxT50qW08YXO5lMIJkrdq4yOTR+AW7FqutScmB9NkLwxo+jU+kZLbofZZq/w== -csstype@^3.0.2: - version "3.1.1" - resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.1.tgz#841b532c45c758ee546a11d5bd7b7b473c8c30b9" - integrity sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw== - csv-stringify@^5.6.2: version "5.6.5" resolved "https://registry.yarnpkg.com/csv-stringify/-/csv-stringify-5.6.5.tgz#c6d74badda4b49a79bf4e72f91cce1e33b94de00"