UNPKG

api

Version:

Magical SDK generation from an OpenAPI definition 🪄

106 lines (105 loc) • 3.94 kB
import type { OASDocument } from 'oas/dist/rmoas.types'; import Fetcher from '../fetcher'; export default class Storage { static dir: string; static lockfile: false | Lockfile; /** * This is the original source that the file came from (relative/absolute file path, URL, ReadMe * registry UUID, etc.). */ source: string; identifier: string; fetcher: Fetcher; constructor(source: string, identifier?: string); static getLockfilePath(): string; static getAPIsDir(): string; static setStorageDir(dir?: string): void; /** * Reset the state of the entire storage system. * * This will completely destroy the contents of the `.api/` directory! */ static reset(): Promise<void>; static getDefaultLockfile(): Lockfile; static generateIntegrityHash(definition: OASDocument): string; static getLockfile(): Lockfile; static isIdentifierValid(identifier: string, prefixWithAPINamespace?: boolean): boolean; static isInLockFile(search: { identifier?: string; source?: string; }): false | LockfileAPI; setIdentifier(identifier: string): void; /** * Determine if the current spec + identifier we're working with is already in the lockfile. */ isInLockfile(): boolean; /** * Retrieve the lockfile record for the current spec + identifier if it exists in the lockfile. */ getFromLockfile(): LockfileAPI; getIdentifierStorageDir(): string; getAPIDefinition(): any; saveSourceFiles(files: Record<string, string>): Promise<unknown>; load(): Promise<OASDocument>; /** * @example <caption>Storage directory structure</caption> * .api/ * ├── api.json // The `package-lock.json` equivalent that records everything that's * | // installed, when it was installed, what the original source was, * | // and what version of `api` was used. * └── apis/ * ├── readme/ * | ├── node_modules/ * │ ├── index.js // We may offer the option to export a raw TS file for folks who want * | | // that, but for now it'll be a compiled JS file. * │ ├── index.d.ts // All types for their SDK, ready to use in an IDE. * │ |── openapi.json * │ └── package.json * └── petstore/ * ├── node_modules/ * ├── index.js * ├── index.d.ts * ├── openapi.json * └── package.json * */ save(spec: OASDocument): OASDocument; } export interface Lockfile { apis: LockfileAPI[]; /** * The `api.json` schema version. This will only ever change if we introduce breaking changes to * this store. */ version: '1.0'; } export interface LockfileAPI { /** * A unique identifier of the API. This'll be used to do requires on `@api/<identifier>` and also * where the SDK code will be located in `.api/apis/<identifier>`. * * @example petstore */ identifier: string; /** * The version of `api` that was used to install this SDK. * * @example 5.0.0 */ installerVersion: string; /** * An integrity hash that will be used to determine on `npx api update` calls if the API has * changed since the SDK was last generated. * * @example sha512-ld+djZk8uRWmzXC+JYla1PTBScg0NjP/8x9vOOKRW+DuJ3NNMRjrpfbY7T77Jgnc87dZZsU49robbQfYe3ukug== */ integrity: string; /** * The original source that was used to generate the SDK with. * * @example https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore-simple.json * @example ./petstore.json * @example @developers/v2.0#nysezql0wwo236 */ source: string; }