Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions apis/server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type * as cds from './cds'
import { Application, RequestHandler } from 'express'
import { XOR } from './internal/util'



type _cds = typeof cds
// interface instead of type so users can insert their actual Services via module augmentation
interface cds_services {
Expand All @@ -26,6 +28,13 @@ export const connect: {
*/
to(datasource: 'db', options?: cds_connect_options): Promise<cds.DatabaseService>,

/**
* Connects to a specific datasource via options.
* @example cds.connect.to ({ kind:..., impl:... })
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
*/
to(options: cds_connect_options): Promise<Service>,

/**
* Connects to a specific datasource via a Service subclass
* @example cds.connect.to (ServiceClass)
Expand All @@ -34,11 +43,11 @@ export const connect: {
to<S extends Service>(datasource: {new(): S}, options?: cds_connect_options): Promise<S>,

/**
* Connects to a specific datasource via options.
* @example cds.connect.to ({ kind:..., impl:... })
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
*/
to(options: cds_connect_options): Promise<Service>,
* Connects to a specific datasource via a Service subclass
* @example cds.connect.to (ServiceClass)
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
*/
to<S>(datasource: S, options?: cds_connect_options): Promise<cds.CdsFunctions<S> & Service>,

/**
* Connects the primary datasource.
Expand Down
3 changes: 3 additions & 0 deletions apis/services.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ type CdsFunction = {
__returns: any,
}

// extracts all properties of type CdsFunction from T
type CdsFunctions<T> = Pick<T, { [K in keyof T]: T[K] extends CdsFunction ? K : never }[keyof T]>

type TypedRequest<T> = Omit<Request, 'data'> & { data: T }

// https://cap.cloud.sap/docs/node.js/core-services#srv-on-before-after
Expand Down