UNPKG

api-core

Version:

Model-based dynamic multi-level APIs for any provider, plus multiple consumption channels

106 lines (105 loc) 5.38 kB
import { ApiEdgeRelation } from "../relations/ApiEdgeRelation"; import { ApiEdgeQueryContext } from "./ApiEdgeQueryContext"; import { ApiEdgeQueryResponse } from "./ApiEdgeQueryResponse"; import { ApiQueryScope } from "../query/ApiQuery"; import { ApiEdgeMethod, ApiEdgeMethodOptions, ApiEdgeMethodScope } from "./ApiEdgeMethod"; import { ApiRequestType } from "../request/ApiRequest"; import { ApiEdgeAction, ApiEdgeActionTrigger, ApiEdgeActionTriggerKind } from "./ApiEdgeAction"; import { ApiEdgeQueryType } from "./ApiEdgeQueryType"; import { ApiEdgeSchema } from "./ApiEdgeSchema"; import { Api } from "../Api"; import { ApiEdgeQuery } from "./ApiEdgeQuery"; import { ApiEdgeMetadata } from "./ApiEdgeMetadata"; export interface ApiEdgeDefinition { name: string; pluralName: string; idField: string; api: Api; schema: ApiEdgeSchema; methods: ApiEdgeMethod[]; relations: ApiEdgeRelation[]; actions: ApiEdgeAction[]; allowGet: boolean; allowList: boolean; allowCreate: boolean; allowUpdate: boolean; allowPatch: boolean; allowRemove: boolean; allowExists: boolean; external: boolean; getEntry: (context: ApiEdgeQueryContext) => Promise<ApiEdgeQueryResponse>; listEntries: (context: ApiEdgeQueryContext) => Promise<ApiEdgeQueryResponse>; createEntry: (context: ApiEdgeQueryContext, entryFields: any) => Promise<ApiEdgeQueryResponse>; updateEntry: (context: ApiEdgeQueryContext, entryFields: any) => Promise<ApiEdgeQueryResponse>; patchEntry: (context: ApiEdgeQueryContext, entryFields: any) => Promise<ApiEdgeQueryResponse>; removeEntry: (context: ApiEdgeQueryContext, entryFields: any) => Promise<ApiEdgeQueryResponse>; exists: (context: ApiEdgeQueryContext) => Promise<ApiEdgeQueryResponse>; prepare: (api: Api) => Promise<void>; resolve: () => Promise<boolean>; metadata: () => ApiEdgeMetadata; relation: (name: string) => Promise<ApiEdgeRelation | undefined>; get(key: string): any; set(key: string, value: any): any; } export declare abstract class ApiEdge implements ApiEdgeDefinition { name: string; pluralName: string; idField: string; api: Api; schema: ApiEdgeSchema; methods: ApiEdgeMethod[]; relations: ApiEdgeRelation[]; actions: ApiEdgeAction[]; allowGet: boolean; allowList: boolean; allowCreate: boolean; allowUpdate: boolean; allowPatch: boolean; allowRemove: boolean; allowExists: boolean; external: boolean; getEntry: (context: ApiEdgeQueryContext) => Promise<ApiEdgeQueryResponse>; listEntries: (context: ApiEdgeQueryContext) => Promise<ApiEdgeQueryResponse>; createEntry: (context: ApiEdgeQueryContext, entryFields: any) => Promise<ApiEdgeQueryResponse>; updateEntry: (context: ApiEdgeQueryContext, entryFields: any) => Promise<ApiEdgeQueryResponse>; patchEntry: (context: ApiEdgeQueryContext, entryFields: any) => Promise<ApiEdgeQueryResponse>; removeEntry: (context: ApiEdgeQueryContext, entryFields: any) => Promise<ApiEdgeQueryResponse>; exists: (context: ApiEdgeQueryContext) => Promise<ApiEdgeQueryResponse>; prepare: (api: Api) => Promise<void>; resolve: () => Promise<boolean>; metadata: () => { name: string; pluralName: string; idField: string; fields: string[]; methods: { name: string; type: ApiRequestType; scope: ApiEdgeMethodScope; parameters: string[]; }[]; typings: any; allowGet: boolean; allowList: boolean; allowCreate: boolean; allowUpdate: boolean; allowPatch: boolean; allowRemove: boolean; allowExists: boolean; external: boolean; }; use: (action: ApiEdgeAction) => this; action: (name: string, execute: (scope: ApiQueryScope) => Promise<ApiQueryScope>, targetTypes?: ApiEdgeQueryType, triggerKind?: ApiEdgeActionTriggerKind, triggers?: ApiEdgeActionTrigger, triggerNames?: string[]) => ApiEdge; relation: (name: string) => Promise<ApiEdgeRelation | undefined>; edgeMethod(name: string, execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>, acceptedTypes?: ApiRequestType, requiresData?: boolean): ApiEdge; edgeMethod(name: string, execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>, acceptedTypes?: ApiRequestType, parameters?: string[], requiresData?: boolean): ApiEdge; collectionMethod(name: string, execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>, acceptedTypes?: ApiRequestType, requiresData?: boolean): ApiEdge; collectionMethod(name: string, execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>, acceptedTypes?: ApiRequestType, parameters?: string[], requiresData?: boolean): ApiEdge; entryMethod(name: string, execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>, acceptedTypes?: ApiRequestType, requiresData?: boolean): ApiEdge; entryMethod(name: string, execute: (scope: ApiQueryScope) => Promise<ApiEdgeQueryResponse>, acceptedTypes?: ApiRequestType, parameters?: string[], requiresData?: boolean): ApiEdge; method(options: ApiEdgeMethodOptions): this; private extension; get: (key: string) => any; set: (key: string, value: any) => any; buildQuery(type?: ApiEdgeQueryType, body?: any): ApiEdgeQuery; }