From eb2d441670536c8a865e1a49a8ed11b1823ea072 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 28 Aug 2022 22:01:51 -0400 Subject: [PATCH] *Initial version extracted from @lumeweb/relay --- LICENSE | 2 +- package.json | 9 +++++++ src/index.ts | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 24 +++++++++++++++++++ 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 package.json create mode 100644 src/index.ts create mode 100644 tsconfig.json diff --git a/LICENSE b/LICENSE index 13a5b6e..f161a44 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Lume Web +Copyright (c) 2022 Hammmer Technologies LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/package.json b/package.json new file mode 100644 index 0000000..8490d5f --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "name": "@lumeweb/resolver-types", + "version": "0.1.0", + "main": "dist", + "type": "module", + "devDependencies": { + "ajv": "^8.11.0" + } +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..28ffc08 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,66 @@ +import type { JSONSchemaType } from "ajv"; +export interface RPCRequest { + bypassCache?: boolean; + module: string; + method: string; + data: any; +} + +export interface RPCResponse { + updated?: number; + data?: any; + error?: string; +} + +export interface RPCMethod { + cacheable: boolean; + handler: ( + request: RPCRequest, + sendStream: (stream: AsyncIterable) => void + ) => Promise; +} + +// @ts-ignore +export const RPC_REQUEST_SCHEMA: JSONSchemaType = { + type: "object", + properties: { + module: { + type: "string", + }, + method: { + type: "string", + }, + data: { + type: ["number", "string", "boolean", "object", "array"], + }, + bypassCache: { + type: "boolean", + nullable: true, + }, + }, +}; + +export interface StreamFileResponse { + data?: Uint8Array; + done: boolean; +} + +export interface PluginAPI { + config: any; + registerMethod: (methodName: string, method: RPCMethod) => void; + loadPlugin: (moduleName: string) => Promise; + getMethods: () => string[]; +} + +export type PluginFunction = (api: PluginAPI) => Promise; + +export interface Plugin { + name: string; + plugin: PluginFunction; + exports?: any; + default?: Plugin; +} + +export type RPCStreamHandler = ( + stream: AsyncIterable +) => Promise; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..eb61177 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "declaration": true, + "strict": true, + "module": "esnext", + "target": "esnext", + "esModuleInterop": true, + "sourceMap": false, + "rootDir": "src", + "outDir": "dist", + "typeRoots": [ + "node_modules/@types" + ], + "moduleResolution": "node", + "declarationMap": true, + "declarationDir": "dist", + "emitDeclarationOnly": false, + "allowJs": true, + "noImplicitAny": false + }, + "include": [ + "src" + ] +}