@cap-js/cds-types 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cds-types.d.ts +87 -16
- package/package.json +5 -3
package/dist/cds-types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare module '@sap/cds' {
|
|
2
2
|
export * from "@sap/cds-dk";
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
|
|
5
5
|
export type __any_ = classes.any_
|
|
6
6
|
|
|
@@ -178,7 +178,27 @@ type Awaitable<T, I> = T & Promise<I>
|
|
|
178
178
|
|
|
179
179
|
class Axios {
|
|
180
180
|
|
|
181
|
+
/**
|
|
182
|
+
* @deprecated Used to provide access to an `axios` instance used as HTTP client. From `@cap-js/cds-test` >=1 onwards, it no longer points to
|
|
183
|
+
* the real `axios` library, but to an emulated lookalike, mostly for backward compatibility.
|
|
184
|
+
* Install `axios` explicitly as a project dependency if you need the full feature set of it. In that case, the HTTP shortcuts will automatically
|
|
185
|
+
* use the installed `axios` instead of the emulated version.
|
|
186
|
+
*/
|
|
181
187
|
get axios (): import('axios').AxiosInstance
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Provides default values for HTTP requests. To stay portable across different HTTP clients, it's recommended to only use these options,
|
|
191
|
+
* which cds.test supports across all clients:
|
|
192
|
+
* - `baseURL` as defined in Axios
|
|
193
|
+
* - `auth` as defined in Axios
|
|
194
|
+
* - `headers` as defined in Fetch API and Axios
|
|
195
|
+
* - `validateStatus` as defined in Axios (default: status >= 200 && status < 300)
|
|
196
|
+
*
|
|
197
|
+
* In addition, you can use all of the config options understood by the underlying HTTP client, that is, for Fetch API,
|
|
198
|
+
* its RequestInit options, and for Axios, its request config options.
|
|
199
|
+
*/
|
|
200
|
+
get defaults (): import('axios').AxiosRequestConfig & RequestInit
|
|
201
|
+
|
|
182
202
|
get: import('axios').AxiosInstance['get'] & TaggedTemplateRequest
|
|
183
203
|
|
|
184
204
|
put: import('axios').AxiosInstance['put'] & TaggedTemplateRequest
|
|
@@ -1040,7 +1060,7 @@ class Decimal extends Float {
|
|
|
1040
1060
|
}
|
|
1041
1061
|
|
|
1042
1062
|
/**
|
|
1043
|
-
* @beta helper
|
|
1063
|
+
* @beta helper
|
|
1044
1064
|
*/
|
|
1045
1065
|
type DeepPartial<T> = T extends object
|
|
1046
1066
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
@@ -1352,7 +1372,11 @@ export class EventContext {
|
|
|
1352
1372
|
|
|
1353
1373
|
id: string
|
|
1354
1374
|
|
|
1355
|
-
|
|
1375
|
+
/**
|
|
1376
|
+
* ISO 639-1 language code, optionally followed by an underscore and ISO 3166-1 alpha-2 country code, e.g. "en" or "en_US".
|
|
1377
|
+
* May be `undefined` if the `AcceptLanguage` header is not set in the incoming request.
|
|
1378
|
+
*/
|
|
1379
|
+
locale?: string
|
|
1356
1380
|
|
|
1357
1381
|
timestamp: Date
|
|
1358
1382
|
|
|
@@ -1362,9 +1386,9 @@ export class EventContext {
|
|
|
1362
1386
|
|
|
1363
1387
|
}
|
|
1364
1388
|
|
|
1365
|
-
export interface EventHandler {
|
|
1389
|
+
export interface EventHandler<E = any> {
|
|
1366
1390
|
// (msg : types.EventMessage) : Promise<any> | any | void
|
|
1367
|
-
(req: Request_2): Promise<any> | any | void
|
|
1391
|
+
(req: Request_2<E>): Promise<any> | any | void
|
|
1368
1392
|
}
|
|
1369
1393
|
|
|
1370
1394
|
/**
|
|
@@ -1379,8 +1403,8 @@ export type expr_literal = { '=': string }
|
|
|
1379
1403
|
|
|
1380
1404
|
type Expression<E extends string | number | bigint | boolean> = `${E}${WS}${Op}${WS}`
|
|
1381
1405
|
|
|
1382
|
-
type Expressions<L,E> = KVPairs<L, Expression<Exclude<keyof E, symbol>>, ColumnValue> extends true
|
|
1383
|
-
? L
|
|
1406
|
+
type Expressions<L,E> = KVPairs<L, Expression<Exclude<keyof E, symbol>>, ColumnValue> extends true
|
|
1407
|
+
? L
|
|
1384
1408
|
// fallback: allow for any string. Important for when user renamed properties
|
|
1385
1409
|
: KVPairs<L, Expression<string>, ColumnValue> extends true
|
|
1386
1410
|
? L
|
|
@@ -1492,7 +1516,7 @@ interface Having<T> {
|
|
|
1492
1516
|
having: HavingWhere<this, T>
|
|
1493
1517
|
}
|
|
1494
1518
|
|
|
1495
|
-
type HavingWhere<This, E> =
|
|
1519
|
+
type HavingWhere<This, E> =
|
|
1496
1520
|
/**
|
|
1497
1521
|
* @param predicate - An object with keys that are valid fields of the target entity and values that are compared to the respective fields.
|
|
1498
1522
|
* @example
|
|
@@ -1502,6 +1526,7 @@ type HavingWhere<This, E> =
|
|
|
1502
1526
|
* ```
|
|
1503
1527
|
*/
|
|
1504
1528
|
((predicate: Partial<{[column in KeyOfTarget<This extends ConstructedQuery<infer E> ? E : never, never>]: any}>) => This)
|
|
1529
|
+
|
|
1505
1530
|
/**
|
|
1506
1531
|
* @param expr - An array of expressions, where every odd element is a valid field of the target entity and every even element is a value that is compared to the respective field.
|
|
1507
1532
|
* @example
|
|
@@ -2213,6 +2238,10 @@ export function on (event: 'listening', listener: (args: { server: import('http'
|
|
|
2213
2238
|
*/
|
|
2214
2239
|
export function on (event: 'shutdown', listener: () => void): _cds
|
|
2215
2240
|
|
|
2241
|
+
export function once (event: 'loaded', listener: (model: CSN) => void): _cds
|
|
2242
|
+
|
|
2243
|
+
export function once (event: 'connect', listener: (srv: Service) => void): _cds
|
|
2244
|
+
|
|
2216
2245
|
export function once (event: 'bootstrap', listener: (app: import('express').Application) => void): _cds
|
|
2217
2246
|
|
|
2218
2247
|
export function once (event: 'compile.for.runtime', listener: (model: CSN) => void): _cds
|
|
@@ -2221,6 +2250,8 @@ export function once (event: 'compile.to.dbx', listener: (model: CSN) => void):
|
|
|
2221
2250
|
|
|
2222
2251
|
export function once (event: 'compile.to.edmx', listener: (model: CSN) => void): _cds
|
|
2223
2252
|
|
|
2253
|
+
export function once (event: 'serving', listener: (srv: Service) => void): _cds
|
|
2254
|
+
|
|
2224
2255
|
export function once (event: 'served', listener: (all: cds_services) => void): _cds
|
|
2225
2256
|
|
|
2226
2257
|
export function once (event: 'listening', listener: (args: { server: import('http').Server, url: string }) => void): _cds
|
|
@@ -2291,6 +2322,31 @@ P extends Record<string, any>[] = Record<string, any>[]
|
|
|
2291
2322
|
|
|
2292
2323
|
export type predicate = _xpr
|
|
2293
2324
|
|
|
2325
|
+
/**
|
|
2326
|
+
* @beta helper
|
|
2327
|
+
* @example
|
|
2328
|
+
* ```js
|
|
2329
|
+
* const predicate: PredicateMap<Books> = {
|
|
2330
|
+
* title: 'foo',
|
|
2331
|
+
* or: {
|
|
2332
|
+
* price: { '>': 42 }
|
|
2333
|
+
* }
|
|
2334
|
+
* }
|
|
2335
|
+
* const result = await SELECT.from(Books).where(predicate)
|
|
2336
|
+
* ```
|
|
2337
|
+
* Note that you _have to_ explicitly type the predicate variable with `PredicateMap<T>`,
|
|
2338
|
+
* as we can not offer this type as overload to `.where()` or `.having()`.
|
|
2339
|
+
*/
|
|
2340
|
+
type PredicateMap<T> = _PredicateMap<UnwrappedInstanceType<T>>
|
|
2341
|
+
|
|
2342
|
+
/** @internal */
|
|
2343
|
+
type _PredicateMap<T> = {
|
|
2344
|
+
[k in keyof Partial<T>]: (T[k] | Partial<{ [op in Op]: T[k] }>)
|
|
2345
|
+
}
|
|
2346
|
+
& { or?: _PredicateMap<T>, and?: _PredicateMap<T> }
|
|
2347
|
+
// disallow non-existing properties
|
|
2348
|
+
& { [key: string]: never }
|
|
2349
|
+
|
|
2294
2350
|
type Primitive = string | number | boolean | Date
|
|
2295
2351
|
|
|
2296
2352
|
/** @private */
|
|
@@ -2347,6 +2403,7 @@ namespace ql {
|
|
|
2347
2403
|
export {
|
|
2348
2404
|
Query_2 as Query,
|
|
2349
2405
|
QLExtensions,
|
|
2406
|
+
PredicateMap,
|
|
2350
2407
|
ConstructedQuery,
|
|
2351
2408
|
StaticSELECT,
|
|
2352
2409
|
QL,
|
|
@@ -2458,9 +2515,9 @@ export class QueryAPI {
|
|
|
2458
2515
|
transaction: QueryAPI['tx']
|
|
2459
2516
|
|
|
2460
2517
|
tx: {
|
|
2461
|
-
(fn: (tx: Transaction) =>
|
|
2518
|
+
<T>(fn: (tx: Transaction) => T): Promise<Awaited<T>>,
|
|
2462
2519
|
(context?: object): Transaction,
|
|
2463
|
-
(context: object, fn: (tx: Transaction) =>
|
|
2520
|
+
<T>(context: object, fn: (tx: Transaction) => T): Promise<Awaited<T>>,
|
|
2464
2521
|
}
|
|
2465
2522
|
|
|
2466
2523
|
}
|
|
@@ -2591,8 +2648,8 @@ export function resolve (files: '*' | filename | filename[]): filename[] | undef
|
|
|
2591
2648
|
export interface ResultSet extends Array<object> {}
|
|
2592
2649
|
|
|
2593
2650
|
export interface ResultsHandler {
|
|
2594
|
-
(results: any[], req: Request_2):
|
|
2595
|
-
(each: any, req: Request_2):
|
|
2651
|
+
(results: any[], req: Request_2): unknown
|
|
2652
|
+
(each: any, req: Request_2): unknown
|
|
2596
2653
|
}
|
|
2597
2654
|
|
|
2598
2655
|
export const root: string;
|
|
@@ -2928,6 +2985,8 @@ export class Service extends QueryAPI {
|
|
|
2928
2985
|
on<T extends Constructable>(eve: types.event, entity: T | T[], handler: CRUDEventHandler.On<InstanceType<T>>): this
|
|
2929
2986
|
on<F extends CdsFunction>(boundAction: F, service: string, handler: ActionEventHandler<F['__self'], F['__parameters'], void | Error | F['__returns']>): this
|
|
2930
2987
|
on<F extends CdsFunction>(unboundAction: F, handler: ActionEventHandler<F['__self'], F['__parameters'], void | Error | F['__returns']>): this
|
|
2988
|
+
// event classes, generated by cds-typer
|
|
2989
|
+
on<E extends {new (...args: any): any, kind: 'event'}>(eve: E, handler: EventHandler<InstanceType<E>>): this
|
|
2931
2990
|
on (eve: types.event, entity: types.target, handler: OnEventHandler): this
|
|
2932
2991
|
on (eve: types.event, handler: OnEventHandler): this
|
|
2933
2992
|
on (eve: 'error', handler: OnErrorHandler): this
|
|
@@ -3164,12 +3223,24 @@ class Test extends Axios {
|
|
|
3164
3223
|
*/
|
|
3165
3224
|
verbose (v: boolean): this
|
|
3166
3225
|
|
|
3226
|
+
/**
|
|
3227
|
+
* @deprecated Either use the {@link expect} property here or import `chai` in your test file.
|
|
3228
|
+
*/
|
|
3167
3229
|
get chai (): typeof import('chai')
|
|
3168
3230
|
|
|
3169
|
-
|
|
3170
|
-
|
|
3231
|
+
/**
|
|
3232
|
+
* @deprecated Either use the {@link expect} property here or import `chai.assert` in your test file.
|
|
3233
|
+
*/
|
|
3171
3234
|
get assert (): typeof import('chai').assert
|
|
3172
3235
|
|
|
3236
|
+
/**
|
|
3237
|
+
* The `expect` assertion from the `chai` assertion library.
|
|
3238
|
+
*
|
|
3239
|
+
* For Jest, this returns a built-in implementation that covers the most common matchers with the standard `chai` API.
|
|
3240
|
+
* If your tests need more matchers, move to a different test runner such as Vitest, which supports ESM-only modules like `chai`.
|
|
3241
|
+
*/
|
|
3242
|
+
get expect (): typeof import('chai').expect
|
|
3243
|
+
|
|
3173
3244
|
get data (): DataUtil
|
|
3174
3245
|
|
|
3175
3246
|
get cds (): _cds_2
|
|
@@ -3234,9 +3305,9 @@ export const transaction: Service['transaction'];
|
|
|
3234
3305
|
* @see [docs](https://cap.cloud.sap/docs/node.js/cds-tx)
|
|
3235
3306
|
*/
|
|
3236
3307
|
export const tx: {
|
|
3237
|
-
(fn: (tx: Transaction) =>
|
|
3308
|
+
<T>(fn: (tx: Transaction) => T): Promise<T>,
|
|
3238
3309
|
(context?: object): Transaction,
|
|
3239
|
-
(context: object, fn: (tx: Transaction) =>
|
|
3310
|
+
<T>(context: object, fn: (tx: Transaction) => T): Promise<T>,
|
|
3240
3311
|
};
|
|
3241
3312
|
|
|
3242
3313
|
export interface type extends Omit<csn.type, 'items'> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js/cds-types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Type definitions for main packages of CAP, like `@sap/cds`",
|
|
5
5
|
"repository": "github:cap-js/cds-types",
|
|
6
6
|
"homepage": "https://cap.cloud.sap/",
|
|
@@ -50,14 +50,16 @@
|
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@cap-js/cds-test": "^0",
|
|
53
|
+
"@cap-js/cds-test": "^0 || ^1",
|
|
54
54
|
"@cap-js/db-service": "^2.3.0",
|
|
55
55
|
"@microsoft/api-extractor": "^7.52.8",
|
|
56
56
|
"@sap/cds-dk": "^9",
|
|
57
57
|
"@stylistic/eslint-plugin-js": "^4.0.1",
|
|
58
58
|
"@stylistic/eslint-plugin-ts": "^4.0.1",
|
|
59
|
+
"@types/chai": "^5.2.3",
|
|
59
60
|
"axios": "^1.6.2",
|
|
60
|
-
"eslint": "^
|
|
61
|
+
"eslint": "^10",
|
|
62
|
+
"globals": "^17.5.0",
|
|
61
63
|
"typescript": "^5.4.5",
|
|
62
64
|
"typescript-eslint": "^8.0.0-alpha.51"
|
|
63
65
|
}
|