/// import type { Readable } from "stream"; import { EventContext, Request } from "./context"; import { CSN, Definition, EntityDefinition, EventDefinition, ServiceDefinition } from "./csn"; import { QueryObject } from "./ql"; import { CQN, Linked, LinkedCSN, LinkedEntityDefinition, VarLinkedDefinitions } from "./reflect"; import { TransactionMix } from "./transaction"; export type EventHook = "before" | "on" | "after"; export type EventNames = T | T[]; /** * event with extended event */ export type ExtendEventName = EventName | T; /** * standard events */ export type EventName = (CRUD | TX | HTTP | DRAFT | AnyEvent); export type CRUD = "CREATE" | "READ" | "UPDATE" | "DELETE"; export type DRAFT = "NEW" | "EDIT" | "PATCH" | "SAVE"; export type HTTP = "GET" | "PUT" | "POST" | "PATCH" | "DELETE"; export type TX = "COMMIT" | "ROLLBACK"; export type AnyEvent = "*"; export type NextFunction = () => Promise; export interface OnEventHandler { (this: THIS, req: Request, next: NextFunction): Promise | any | void; } export interface BeforeEventHandler { (this: THIS, req: Request): Promise | any | void; } export interface AfterEventHandler { (this: THIS, data: DATA_TYPE, req: Request): Promise | any | void; } type DefinitionContext = { [entityName: string]: T; } & Iterable; type DefinitionProperty = DefinitionContext & ((namespace?: string) => DefinitionContext); export interface ServiceImplFunc { (this: Service, srv: Service): any; } export interface DefaultServiceOptions { kind: String; impl: String | ServiceImplFunc; } export type DefaultMixinMethod = (...args: any[]) => Promise; export type MixinMethods = { [key in E]: M; }; /** * service with wrapped functions */ export type MixedService = S & MixinMethods; /** * cds service */ export declare class Service { constructor(name?: String, model?: CSN, options?: O); kind: string; options: O; /** * The service’s name, that means, the definition’s name for services constructed with cds.serve, or the name of required services as passed to cds.connect. */ name: string; /** * The linked model from which this service’s definition was loaded. * This is === cds.model by default, that is, unless you created services yourself with cds.serve, specifying alternative models to load and construct new services from. */ model: LinkedCSN; get definition(): Linked; get namespace(): string; /** * The init() method acts like a parameter-less constructor. * Ensure to call await super.init() as in the previous example, to have the base class’s handlers added. */ init(): Promise; get entities(): DefinitionProperty; get events(): DefinitionProperty>; get operations(): DefinitionProperty; /** * Use srv.prepend in order to register handlers, which shall be executed before already registered handlers. In particular, this can be used to override handlers from reused services as in cap/samples/bookstore/srv/mashup.js: * For example, the following would register a handler for inserting Orders that runs instead of the default handlers of the connected database service. * * @see [srv.prepend](https://cap.cloud.sap/docs/node.js/services#srv-prepend) * @param cb */ prepend(cb: (srv: this) => void): void; emit(payload: { event: string; data?: any; headers?: any; }): Promise; emit(event: string, data?: any, headers?: any): Promise; send(method: string, path: string, data?: any, headers?: any): Promise; send(param: { method?: string; path?: string; query?: QueryObject; event?: string; data?: any; headers?: any; }): Promise; get(entityOrPath: Definition | string, data: any): Promise; post(entityOrPath: Definition | string, data: any): Promise; delete(entityOrPath: Definition | string, data: any): Promise; patch(entityOrPath: Definition | string, data: any): Promise; put(entityOrPath: Definition | string, data: any): Promise; tx(cb?: (tx: this & TransactionMix) => Promise): this & TransactionMix & Promise; tx(context: Partial, cb?: (tx: this & TransactionMix) => Promise): this & TransactionMix & Promise; run(query: CQN | QueryObject | string | Array): Promise; run(query: any): Promise; read(entity: EntityDefinition | string, key?: any, projection?: any): QueryObject; insert(data: any): { into: (entity: EntityDefinition | string) => QueryObject; }; create(entity: EntityDefinition | string, key?: any): QueryObject; update(entity: EntityDefinition | string, key?: any): QueryObject; delete(entity: EntityDefinition | string, key?: any): QueryObject; stream(cqn: CQN): Promise; stream(column: string): { from: (entity: EntityDefinition | string) => { where: (filter: any) => Readable; }; }; foreach(entityOrQuery: EntityDefinition | string | QueryObject | CQN, cb: (each: ITEM_TYPE) => void): Promise; foreach(entityOrQuery: EntityDefinition | string | QueryObject | CQN, args: Array, cb: (each: ITEM_TYPE) => void): Promise; before(event: EventNames, handler: BeforeEventHandler): void; before(event: EventNames, entity: Entities, handler: BeforeEventHandler): void; on(event: EventNames, handler: OnEventHandler): void; on(event: EventNames, entity: Entities, handler: OnEventHandler): void; after(event: EventNames, handler: AfterEventHandler): void; after(event: EventNames, entity: Entities, handler: AfterEventHandler): void; /** * Registers a generic handler that automatically rejects incoming request with a standard error message. * You can specify multiple events and entities. * * @param event * @param entity */ reject(event: EventNames, entity: Entities): void; } export type Entities = string | Definition | Array; /** * cds application service */ export declare class ApplicationService extends Service { kind: "app-service"; with(serviceImpl: any): any; impl(serviceImpl: any): any; } /** * cds database service */ export declare class DatabaseService extends Service { begin(): Promise; commit(): Promise; rollback(): Promise; stream(query: any): any; } export declare class RemoteService extends Service { } export declare class OutboxService extends Service { } export declare class AuditLogService extends OutboxService { } export declare class MessagingService extends OutboxService { } export type ModelProviderServiceEvents = ExtendEventName<"getCsn" | "getEdmx" | "isExtended" | "getExtensions" | "getResources">; export declare class cds_xt_ModelProviderService extends ApplicationService { } export type ExtensibilityServiceEvents = ExtendEventName<"add" | "promote" | "base" | "push">; export declare class cds_xt_ExtensibilityService extends ApplicationService { } export type DeploymentServiceEvents = ExtendEventName<"subscribe" | "upgrade" | "unsubscribe" | "deploy" | "upgrade" | "extend" | "getTables" | "getColumns" | "getTenants" | "getContainers">; export declare class cds_xt_DeploymentService extends ApplicationService { } export type SaasProvisioningServiceEvents = ExtendEventName<"upgrade">; export declare class cds_xt_SaasProvisioningService extends ApplicationService { } export interface BuiltInServices { db: DatabaseService; "cds.xt.SaasProvisioningService": MixedService, cds_xt_SaasProvisioningService>; "cds.xt.DeploymentService": MixedService, cds_xt_DeploymentService>; "cds.xt.ExtensibilityService": MixedService, cds_xt_ExtensibilityService>; "cds.xt.ModelProviderService": MixedService, cds_xt_ModelProviderService>; "messaging": MessagingService; "audit-log-service": AuditLogService; } export {};