@resin/pinejs
Version:
Pine.js is a sophisticated rules-driven API engine that enables you to define rules in a structured subset of English. Those rules are used in order for Pine.js to generate a database schema and the associated [OData](http://www.odata.org/) API. This make
51 lines (50 loc) • 3.44 kB
TypeScript
/// <reference types="qs" />
import type * as Express from 'express';
import type { ApiKey, HookReq, User } from '../sbvr-api/sbvr-utils';
import * as Bluebird from 'bluebird';
import * as sbvrUtils from '../sbvr-api/sbvr-utils';
import { PermissionError, PermissionParsingError } from './errors';
import { ODataRequest } from './uri-parser';
export { PermissionError, PermissionParsingError };
export interface PermissionReq {
user?: User;
apiKey?: ApiKey;
}
export declare const root: PermissionReq;
export declare const rootRead: PermissionReq;
interface NestedCheckOr<T> {
or: NestedCheckArray<T>;
}
interface NestedCheckAnd<T> {
and: NestedCheckArray<T>;
}
interface NestedCheckArray<T> extends Array<NestedCheck<T>> {
}
declare type NestedCheck<T> = NestedCheckOr<T> | NestedCheckAnd<T> | NestedCheckArray<T> | T;
declare type PermissionCheck = NestedCheck<string>;
declare type MappedType<I, O> = O extends NestedCheck<infer T> ? Exclude<Exclude<I, string> | T, boolean> : Exclude<Exclude<I, string> | O, boolean>;
declare type MappedNestedCheck<T extends NestedCheck<I>, I, O> = T extends NestedCheckOr<I> ? NestedCheckOr<MappedType<I, O>> : T extends NestedCheckAnd<I> ? NestedCheckAnd<MappedType<I, O>> : T extends NestedCheckArray<I> ? NestedCheckArray<MappedType<I, O>> : Exclude<I, string> | O;
export declare function nestedCheck<I, O>(check: string, stringCallback: (s: string) => O): O;
export declare function nestedCheck<I, O>(check: boolean, stringCallback: (s: string) => O): boolean;
export declare function nestedCheck<I, O>(check: NestedCheck<I>, stringCallback: (s: string) => O): Exclude<I, string> | O | MappedNestedCheck<typeof check, I, O>;
export declare const checkPassword: (arg1: string, arg2: string) => Bluebird<{
id: number;
actor: number;
username: string;
permissions: string[];
}>;
export declare const getUserPermissions: (arg1: number) => Bluebird<string[]>;
export declare const getApiKeyPermissions: (arg1: string) => Bluebird<string[]>;
export declare const customAuthorizationMiddleware: (expectedScheme?: string) => (arg1: Express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs>) => Bluebird<void>;
export declare const authorizationMiddleware: (arg1: Express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs>) => Bluebird<void>;
export declare const customApiKeyMiddleware: (paramName?: string) => (arg1: Express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs> | HookReq) => Bluebird<void>;
export declare const apiKeyMiddleware: (arg1: Express.Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs> | HookReq) => Bluebird<void>;
export declare const checkPermissions: (arg1: sbvrUtils.PermissionReq, arg2: NestedCheck<string>) => Bluebird<string | boolean | NestedCheckOr<string> | NestedCheckAnd<string> | NestedCheckArray<string>>;
export declare const checkPermissionsMiddleware: (action: PermissionCheck) => Express.RequestHandler;
export declare const addPermissions: (arg1: sbvrUtils.PermissionReq, arg2: ODataRequest & {
permissionType?: string | NestedCheckOr<string> | NestedCheckAnd<string> | NestedCheckArray<string> | undefined;
}) => Bluebird<void>;
export declare const config: {
models: sbvrUtils.ExecutableModel[];
};
export declare const setup: () => void;