Skip to content

Commit

Permalink
Add service connect to overload
Browse files Browse the repository at this point in the history
  • Loading branch information
daogrady committed Dec 3, 2024
1 parent e5b8490 commit 0cf25de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
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'



Check failure on line 9 in apis/server.d.ts

View workflow job for this annotation

GitHub Actions / lint

More than 2 blank lines not allowed
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

0 comments on commit 0cf25de

Please sign in to comment.