@cap-js/cds-types 0.7.0 → 0.9.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.
Files changed (2) hide show
  1. package/dist/cds-types.d.ts +154 -75
  2. package/package.json +3 -5
@@ -76,6 +76,17 @@ interface And {
76
76
  & ((...expr: any[]) => this)
77
77
  }
78
78
 
79
+ /**
80
+ * Subclass representing unauthenticated users.
81
+ */
82
+ export class Anonymous extends User {
83
+
84
+ constructor ()
85
+
86
+ is (): boolean
87
+
88
+ }
89
+
79
90
  const any: typeof any_;
80
91
 
81
92
  interface any_ extends csn.any_ {}
@@ -239,7 +250,7 @@ namespace cds {
239
250
  service,
240
251
  cds_serve_fluent,
241
252
  cds_connect_options,
242
- Middleswares,
253
+ Middlewares,
243
254
  middlewares,
244
255
  app,
245
256
  env,
@@ -247,6 +258,7 @@ namespace cds {
247
258
  get,
248
259
  load,
249
260
  resolve,
261
+ minify,
250
262
  reflect,
251
263
  _flavor,
252
264
  _odata_options,
@@ -311,7 +323,8 @@ namespace cds {
311
323
  Partial_2 as Partial,
312
324
  OneOrMany,
313
325
  CdsFunction,
314
- TypedRequest,
326
+ CdsFunctions,
327
+ HandlerFunction,
315
328
  CRUDEventHandler,
316
329
  ActionEventHandler,
317
330
  ResultsHandler,
@@ -337,6 +350,7 @@ namespace cds {
337
350
  Event_2 as Event,
338
351
  Request_2 as Request,
339
352
  User,
353
+ Anonymous,
340
354
  Privileged,
341
355
  utils,
342
356
  Query,
@@ -364,8 +378,7 @@ namespace cds {
364
378
  operator,
365
379
  function_call,
366
380
  enum_literal,
367
- expr_literal,
368
- minify
381
+ expr_literal
369
382
  }
370
383
  }
371
384
 
@@ -390,14 +403,24 @@ export interface cds_serve_fluent {
390
403
  // (req,res) : void
391
404
  }
392
405
 
393
- export type cds_services = { [name: string]: Service }
406
+ export interface cds_services {
407
+ [name: string]: Service
408
+ }
394
409
 
410
+ /**
411
+ * @beta helper
412
+ */
395
413
  export type CdsFunction = {
396
414
  (...args: any[]): any,
397
415
  __parameters: object,
398
416
  __returns: any,
399
417
  }
400
418
 
419
+ /**
420
+ * @beta helper
421
+ */
422
+ export type CdsFunctions<T> = Pick<T, { [K in keyof T]: T[K] extends CdsFunction ? K : never }[keyof T]>
423
+
401
424
  namespace classes {
402
425
  export {
403
426
  mixin,
@@ -570,24 +593,33 @@ export const connect: {
570
593
 
571
594
  /**
572
595
  * Connects to a specific datasource.
573
- * @example cds.connect.to ('service')
596
+ * @example await cds.connect.to ('service')
574
597
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
575
598
  */
576
599
  to(datasource: string, options?: cds_connect_options): Promise<Service>,
577
600
 
578
601
  /**
579
602
  * Shortcut for 'db' as the primary database returning `cds.DatabaseService`
580
- * @example cds.connect.to ('db')
603
+ * @example await cds.connect.to ('db')
581
604
  */
582
605
  to(datasource: 'db', options?: cds_connect_options): Promise<cds.DatabaseService>,
583
606
 
584
607
  /**
585
608
  * Connects to a specific datasource via a Service subclass
586
- * @example cds.connect.to (ServiceClass)
609
+ * @example await cds.connect.to (ServiceClass)
587
610
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
588
611
  */
589
612
  to<S extends Service>(datasource: {new(): S}, options?: cds_connect_options): Promise<S>,
590
613
 
614
+ /**
615
+ * Connects to a specific datasource via a Service class from cds-typer
616
+ * @example
617
+ * import ServiceClass from '#cds-models/SomeService'
618
+ * await cds.connect.to (ServiceClass)
619
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
620
+ */
621
+ to<S>(datasource: S, options?: cds_connect_options): Promise<cds.CdsFunctions<S> & Service>,
622
+
591
623
  /**
592
624
  * Connects to a specific datasource via options.
593
625
  * @example cds.connect.to ({ kind:..., impl:... })
@@ -675,9 +707,9 @@ class CREATE_3<T> extends ConstructedQuery<T> {
675
707
  }
676
708
 
677
709
  export namespace CRUDEventHandler {
678
- export type Before<P, R = P | void | Error> = (req: TypedRequest<P>) => Promise<R> | R
679
- export type On<P, R = P | void | Error> = (req: TypedRequest<P>, next: (...args: any[]) => Promise<R> | R) => Promise<R> | R
680
- export type After<P, R = P | void | Error> = (data: undefined | P, req: TypedRequest<P>) => Promise<R> | R
710
+ export type Before<P, R = P | void | Error> = (req: Request_2<P>) => Promise<R> | R
711
+ export type On<P, R = P | void | Error> = (req: Request_2<P>, next: (...args: any[]) => Promise<R> | R) => Promise<R> | R
712
+ export type After<P, R = P | void | Error> = (data: undefined | P, req: Request_2<P>) => Promise<R> | R
681
713
  }
682
714
 
683
715
  /**
@@ -785,13 +817,6 @@ class Decimal extends Float {
785
817
  scale?: number
786
818
  }
787
819
 
788
- /**
789
- * Recursively excludes nullability from all properties of T.
790
- */
791
- type DeepRequired<T> = {
792
- [K in keyof T]: DeepRequired<T[K]>
793
- } & Exclude<Required<T>, null>
794
-
795
820
  export namespace default_2 {
796
821
  export {
797
822
  log,
@@ -829,7 +854,7 @@ export namespace default_2 {
829
854
  service,
830
855
  cds_serve_fluent,
831
856
  cds_connect_options,
832
- Middleswares,
857
+ Middlewares,
833
858
  middlewares,
834
859
  app,
835
860
  env,
@@ -837,6 +862,7 @@ export namespace default_2 {
837
862
  get,
838
863
  load,
839
864
  resolve,
865
+ minify,
840
866
  reflect,
841
867
  _flavor,
842
868
  _odata_options,
@@ -901,7 +927,8 @@ export namespace default_2 {
901
927
  Partial_2 as Partial,
902
928
  OneOrMany,
903
929
  CdsFunction,
904
- TypedRequest,
930
+ CdsFunctions,
931
+ HandlerFunction,
905
932
  CRUDEventHandler,
906
933
  ActionEventHandler,
907
934
  ResultsHandler,
@@ -927,6 +954,7 @@ export namespace default_2 {
927
954
  Event_2 as Event,
928
955
  Request_2 as Request,
929
956
  User,
957
+ Anonymous,
930
958
  Privileged,
931
959
  utils,
932
960
  Query,
@@ -954,8 +982,7 @@ export namespace default_2 {
954
982
  operator,
955
983
  function_call,
956
984
  enum_literal,
957
- expr_literal,
958
- minify
985
+ expr_literal
959
986
  }
960
987
  }
961
988
 
@@ -1091,6 +1118,12 @@ export const env: {
1091
1118
  [key: string]: any,
1092
1119
  },
1093
1120
  profiles: string[],
1121
+ log: {
1122
+ user: boolean,
1123
+ levels: Record<string, Lowercase<keyof typeof levels>>,
1124
+ als_custom_fields: Record<string, number>,
1125
+ cls_custom_fields: string[],
1126
+ },
1094
1127
  requires: env.Requires,
1095
1128
  folders: {
1096
1129
  app: string,
@@ -1214,14 +1247,18 @@ export class event extends aspect<'event'> {}
1214
1247
  /**
1215
1248
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
1216
1249
  */
1217
- class Event_2 extends EventContext {
1250
+ class Event_2<T = unknown> extends EventContext {
1218
1251
 
1219
1252
  event: string
1220
1253
 
1221
- data: any
1254
+ data: T
1222
1255
 
1223
1256
  headers: any
1224
1257
 
1258
+ before(phase: 'commit', handler: () => void)
1259
+
1260
+ on(phase: 'succeeded' | 'failed' | 'done', handler: () => void)
1261
+
1225
1262
  }
1226
1263
  export { Event_2 as Event }
1227
1264
 
@@ -1345,6 +1382,28 @@ interface GroupBy {
1345
1382
  // columns currently not being auto-completed due to complexity
1346
1383
  }
1347
1384
 
1385
+ /**
1386
+ * Types herein can be used to type handler functions that are not declared in line:
1387
+ * @example
1388
+ * ```ts
1389
+ * import { myAction } from '#cds-models/myService'
1390
+ *
1391
+ * function onMyFunction (req: HandlerFunction<typeof myAction>['parameters']['req']): HandlerFunction<typeof myAction>['returns'] {
1392
+ * ...
1393
+ * }
1394
+ *
1395
+ * srv.on(myAction, onMyFunction)
1396
+ * ```
1397
+ */
1398
+ export type HandlerFunction<F extends CdsFunction> = {
1399
+ parameters: {
1400
+ /** @beta helper */
1401
+ req: Request_2<F['__parameters']>,
1402
+ },
1403
+ /** @beta helper */
1404
+ returns: F['__returns'],
1405
+ }
1406
+
1348
1407
  interface Having<T> {
1349
1408
  having: HavingWhere<this, T>
1350
1409
  }
@@ -1390,11 +1449,13 @@ interface INSERT_3<T> extends Columns<T>, InUpsert<T> {}
1390
1449
  class INSERT_3<T> extends ConstructedQuery<T> {
1391
1450
  private constructor();
1392
1451
 
1393
- static into: (<T extends ArrayConstructable> (entity: T, entries?: Entries) => INSERT_3<SingularInstanceType<T>>)
1452
+ static into: (<T extends ArrayConstructable> (entity: T, ...entries: SingularInstanceType<T>[]) => INSERT_3<SingularInstanceType<T>>)
1453
+ & (<T extends ArrayConstructable> (entity: T, entries?: SingularInstanceType<T>[]) => INSERT_3<SingularInstanceType<T>>)
1394
1454
  & (TaggedTemplateQueryPart<INSERT_3<unknown>>)
1455
+ & ((entity: EntityDescription, ...entries: Entries[]) => INSERT_3<StaticAny>)
1395
1456
  & ((entity: EntityDescription, entries?: Entries) => INSERT_3<StaticAny>)
1396
- & (<T> (entity: Constructable<T>, entries?: Entries) => INSERT_3<T>)
1397
- & (<T> (entity: T, entries?: T | Entries) => INSERT_3<T>)
1457
+ & (<T> (entity: Constructable<T>, ...entries: T[]) => INSERT_3<T>)
1458
+ & (<T> (entity: Constructable<T>, entries?: T[]) => INSERT_3<T>)
1398
1459
 
1399
1460
  /**
1400
1461
  * @deprected
@@ -1420,7 +1481,8 @@ type Intersect<T extends readonly unknown[]> = T extends [infer Head, ...infer T
1420
1481
  interface InUpsert<T> {
1421
1482
  data (block: (e: T) => void): this
1422
1483
 
1423
- entries (...entries: object[]): this
1484
+ entries (...entries: T[]): this
1485
+ entries (entries: T[]): this
1424
1486
 
1425
1487
  values (...val: (null | Primitive)[]): this
1426
1488
  values (val: (null | Primitive)[]): this
@@ -1814,17 +1876,17 @@ type ManagedAssociation = Association & {
1814
1876
 
1815
1877
  export class MessagingService extends Service {}
1816
1878
 
1817
- export type Middleswares = 'context' | 'trace' | 'auth' | 'ctx_model' | string
1879
+ export type Middlewares = 'context' | 'trace' | 'auth' | 'ctx_model' | string
1818
1880
 
1819
1881
  export const middlewares: {
1820
- add: (middleware: import('express').RequestHandler, pos?: XOR<XOR<{ at: number }, { after: Middleswares }>, { before: Middleswares }>) => void,
1882
+ add: (middleware: import('express').RequestHandler, pos?: XOR<XOR<{ at: number }, { after: Middlewares }>, { before: Middlewares }>) => void,
1821
1883
  };
1822
1884
 
1823
1885
  /**
1824
1886
  * Minifies a given CSN model by removing all unused1 types and aspects, as well all entities tagged with `@cds.persistence.skip:'if-unused'`
1825
1887
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-compile#cds-minify)
1826
1888
  */
1827
- export function minify (model: CSN): CSN
1889
+ export function minify (model: csn.CSN): csn.CSN
1828
1890
 
1829
1891
  /**
1830
1892
  * Allows arbitrary property access. Can be used for explicitly casting
@@ -1870,6 +1932,7 @@ namespace models {
1870
1932
  get,
1871
1933
  load,
1872
1934
  resolve,
1935
+ minify,
1873
1936
  reflect,
1874
1937
  _flavor,
1875
1938
  _odata_options,
@@ -1950,7 +2013,7 @@ export function on (event: 'loaded', listener: (model: CSN) => void): _cds
1950
2013
  export function on (event: 'connect', listener: (srv: Service) => void): _cds
1951
2014
 
1952
2015
  /**
1953
- * Emitted at the very beginning of the bootsrapping process, when the
2016
+ * Emitted at the very beginning of the bootstrapping process, when the
1954
2017
  * express application has been constructed but no middlewares or routes
1955
2018
  * added yet.
1956
2019
  */
@@ -2018,7 +2081,7 @@ interface OrderBy<T> {
2018
2081
  }
2019
2082
 
2020
2083
  /** @private */
2021
- export type ordering_term = expr & { sort?: 'asc' | 'desc', nulls?: 'first' | 'last' }
2084
+ export type ordering_term = UnionToIntersection<expr> & { sort?: 'asc' | 'desc', nulls?: 'first' | 'last' }
2022
2085
 
2023
2086
  export const outboxed: (service: Service) => Service;
2024
2087
 
@@ -2070,6 +2133,8 @@ type Projection<T> = (e: QLExtensions<T extends ArrayConstructable ? SingularIns
2070
2133
  */
2071
2134
  type Protocol = 'odata' | 'rest'
2072
2135
 
2136
+ type QbeOp = '=' | '-=' | '+=' | '*=' | '/=' | '%='
2137
+
2073
2138
  class QL<T> {
2074
2139
 
2075
2140
  SELECT: StaticSELECT<T>
@@ -2081,7 +2146,7 @@ class QL<T> {
2081
2146
  & ((...entries: object[]) => UPSERT_3<T>) & ((entries: object[]) => UPSERT_3<T>)
2082
2147
 
2083
2148
  UPDATE: typeof UPDATE_3<T>
2084
- & typeof UPDATE_3.entity<_TODO_2>
2149
+ & typeof UPDATE_3.entity
2085
2150
 
2086
2151
  DELETE: typeof DELETE_3<T>
2087
2152
  & ((...entries: object[]) => DELETE_3<T>) & ((entries: object[]) => DELETE_3<T>)
@@ -2110,7 +2175,7 @@ namespace ql {
2110
2175
  }
2111
2176
  export { ql }
2112
2177
 
2113
- export type QLExtensions<T> = T extends QLExtensions_<any> ? T : QLExtensions_<DeepRequired<T>>
2178
+ export type QLExtensions<T> = T extends QLExtensions_<any> ? T : QLExtensions_<Required<T>>
2114
2179
 
2115
2180
  /**
2116
2181
  * QLExtensions are properties that are attached to entities in CQL contexts.
@@ -2137,6 +2202,7 @@ export class QueryAPI {
2137
2202
  read: {
2138
2203
  <T extends ArrayConstructable>(entity: T, key?: Key): Awaitable<SELECT_3<T>, InstanceType<T>>,
2139
2204
  <T>(entity: linked_2.Definition | string, key?: Key): SELECT_3<T>,
2205
+ (entity: ref, key?: Key): SELECT_3<unknown>,
2140
2206
  }
2141
2207
 
2142
2208
  /**
@@ -2249,7 +2315,7 @@ export class RemoteService extends Service {}
2249
2315
  /**
2250
2316
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/events)
2251
2317
  */
2252
- class Request_2 extends Event_2 {
2318
+ class Request_2<T = any> extends Event_2<T> {
2253
2319
 
2254
2320
  params: (string | object)[]
2255
2321
 
@@ -2360,19 +2426,23 @@ type SELECT_2 = { SELECT: {
2360
2426
  columns?: column_expr[],
2361
2427
  excluding?: string[],
2362
2428
  where?: predicate,
2363
- having?: predicate,
2364
2429
  groupBy?: expr[],
2430
+ having?: predicate,
2365
2431
  orderBy?: ordering_term[],
2366
2432
  limit?: { rows: val, offset: val },
2433
+ forUpdate?: { wait: number },
2434
+ forShareLock?: { wait: number },
2435
+ search?: predicate,
2436
+ count?: boolean,
2367
2437
  }, }
2368
2438
  export { SELECT_2 as SELECT }
2369
2439
 
2370
2440
  interface SELECT_3<T> extends Where<T>, And, Having<T>, GroupBy, OrderBy<T>, Limit {
2371
2441
  // overload specific to SELECT
2372
- columns: Columns<T, SELECT_3<T>>['columns'] & ((projection: Projection<T>) => this)
2442
+ columns: Columns<T, this>['columns'] & ((projection: Projection<T>) => this)
2373
2443
  }
2374
2444
 
2375
- class SELECT_3<T> extends ConstructedQuery<T> {
2445
+ class SELECT_3<T, Q = SELECT_from> extends ConstructedQuery<T> {
2376
2446
  private constructor();
2377
2447
 
2378
2448
  static one: SELECT_one & { from: SELECT_one } & { localized: SELECT_one }
@@ -2383,7 +2453,7 @@ class SELECT_3<T> extends ConstructedQuery<T> {
2383
2453
 
2384
2454
  static localized: SELECT_from & { from: SELECT_from }
2385
2455
 
2386
- from: SELECT_from
2456
+ from: Q // SELECT_from | SELECT_one
2387
2457
  & TaggedTemplateQueryPart<this>
2388
2458
  & ((entity: EntityDescription, primaryKey?: PK, projection?: Projection<unknown>) => this)
2389
2459
 
@@ -2425,7 +2495,7 @@ TaggedTemplateQueryPart<Awaitable<SELECT_3<_TODO_2>, InstanceType<_TODO_2>>>
2425
2495
  &
2426
2496
  (<E extends ArrayConstructable>
2427
2497
  (entityType: E, primaryKey: PK, projection?: Projection<SingularInstanceType<E>>)
2428
- => Awaitable<SELECT_3<SingularInstanceType<E>>, SingularInstanceType<E>>) // when specifying a key, we expect a single element as result
2498
+ => Awaitable<SELECT_3<SingularInstanceType<E>>, SingularInstanceType<E> | null>) // when specifying a key, we expect a single element as result
2429
2499
  // calling with definition
2430
2500
  & (<T>(entity: EntityDescription, primaryKey?: PK, projection?: Projection<T>) => SELECT_3<T>)
2431
2501
  // calling with concrete list
@@ -2454,22 +2524,22 @@ projection?: Projection<InstanceType<T>>
2454
2524
  ) => Awaitable<SELECT_3<InstanceType<T>>, InstanceType<T>>)
2455
2525
 
2456
2526
  type SELECT_one =
2457
- TaggedTemplateQueryPart<Awaitable<SELECT_3<_TODO_2>, InstanceType<_TODO_2>>>
2527
+ TaggedTemplateQueryPart<Awaitable<SELECT_3<_TODO_2, SELECT_one>, InstanceType<_TODO_2>>>
2458
2528
  &
2459
2529
  // calling with class
2460
2530
  (<T extends ArrayConstructable>
2461
2531
  (entityType: T, projection?: Projection<QLExtensions<SingularInstanceType<T>>>)
2462
- => Awaitable<SELECT_3<SingularInstanceType<T>>, SingularInstanceType<T>>)
2532
+ => Awaitable<SELECT_3<SingularInstanceType<T>, SELECT_one>, SingularInstanceType<T> | null>)
2463
2533
  &
2464
2534
  (<T extends ArrayConstructable>
2465
2535
  (entityType: T, primaryKey: PK, projection?: Projection<QLExtensions<SingularInstanceType<T>>>)
2466
- => Awaitable<SELECT_3<SingularInstanceType<T>>, SingularInstanceType<T>>)
2536
+ => Awaitable<SELECT_3<SingularInstanceType<T>, SELECT_one>, SingularInstanceType<T> | null>)
2467
2537
 
2468
- & ((entity: EntityDescription, primaryKey?: PK, projection?: Projection<unknown>) => SELECT_3<_TODO_2>)
2469
- & (<T> (entity: T[], projection?: Projection<T>) => Awaitable<SELECT_3<T>, T>)
2470
- & (<T> (entity: T[], primaryKey: PK, projection?: Projection<T>) => Awaitable<SELECT_3<T>, T>)
2471
- & (<T> (entity: { new(): T }, projection?: Projection<T>) => Awaitable<SELECT_3<T>, T>)
2472
- & (<T> (entity: { new(): T }, primaryKey: PK, projection?: Projection<T>) => Awaitable<SELECT_3<T>, T>)
2538
+ & ((entity: EntityDescription, primaryKey?: PK, projection?: Projection<unknown>) => SELECT_3<_TODO_2, SELECT_one>)
2539
+ & (<T> (entity: T[], projection?: Projection<T>) => Awaitable<SELECT_3<T, SELECT_one>, T | null>)
2540
+ & (<T> (entity: T[], primaryKey: PK, projection?: Projection<T>) => Awaitable<SELECT_3<T, SELECT_one>, T | null>)
2541
+ & (<T> (entity: { new(): T }, projection?: Projection<T>) => Awaitable<SELECT_3<T, SELECT_one>, T | null>)
2542
+ & (<T> (entity: { new(): T }, primaryKey: PK, projection?: Projection<T>) => Awaitable<SELECT_3<T, SELECT_one>, T | null>)
2473
2543
  & ((subject: ref) => SELECT_3<_TODO_2>)
2474
2544
 
2475
2545
  /**
@@ -2551,7 +2621,7 @@ export class Service extends QueryAPI {
2551
2621
 
2552
2622
  /**
2553
2623
  * Constructs and emits an asynchronous event.
2554
- * @see [capire docs](https://cap.cloud.sap/docs/core-services#srv-emit-event)
2624
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services#srv-emit-event)
2555
2625
  */
2556
2626
  emit: {
2557
2627
  <T = any>(details: { event: types.event, data?: object, headers?: object }): Promise<T>,
@@ -2888,6 +2958,8 @@ export const test: {
2888
2958
  (command: string, ...args: string[]): Test,
2889
2959
 
2890
2960
  in (dirname: string): Test,
2961
+
2962
+ log: Test['log'],
2891
2963
  };
2892
2964
 
2893
2965
  class Time extends date { }
@@ -2932,15 +3004,13 @@ export class type<K extends kinds = 'type'> extends any_<K> { }
2932
3004
  interface type_2 extends any__2 {
2933
3005
  type?: 'cds.Boolean' |
2934
3006
  'cds.UUID' | 'cds.String' | 'cds.LargeString' | 'cds.Binary' | 'cds.LargeBinary' | 'cds.Vector' |
2935
- 'cds.Integer' | 'cds.UInt8' | 'cds.Int16' | 'cds.Int32' | 'cds.Int64' | 'cds.Float' | 'cds.Double' | 'cds.Decimal' |
3007
+ 'cds.Integer' | 'cds.UInt8' | 'cds.Int16' | 'cds.Int32' | 'cds.Int64' | 'cds.Double' | 'cds.Decimal' |
2936
3008
  'cds.Date' | 'cds.Time' | 'cds.DateTime' | 'cds.Timestamp' |
2937
3009
  'cds.Association' | 'cds.Composition' |
2938
3010
  FQN & Record<never,never> // allow any other CDS type as well (e.g. 'User')
2939
3011
  items?: type_2
2940
3012
  }
2941
3013
 
2942
- export type TypedRequest<T> = Omit<Request_2, 'data'> & { data: T }
2943
-
2944
3014
  export namespace types {
2945
3015
  export type event = eventName | eventName[]
2946
3016
  export type eventName = { name: string } | string
@@ -2981,29 +3051,30 @@ interface UPDATE_3<T> extends Where<T>, And, ByKey {}
2981
3051
  class UPDATE_3<T> extends ConstructedQuery<T> {
2982
3052
  private constructor();
2983
3053
 
2984
- // cds-typer plural
2985
- // FIXME: this returned UPDATE<SingularInstanceType<T>> before. should UPDATE<Books>.entity(...) return Book or Books?
2986
- static entity<T extends ArrayConstructable> (entity: T, primaryKey?: PK): UPDATE_3<InstanceType<T>>
2987
-
2988
- static entity (entity: EntityDescription, primaryKey?: PK): UPDATE_3<StaticAny>
2989
-
2990
- static entity<T extends Constructable> (entity: T, primaryKey?: PK): UPDATE_3<T>
3054
+ static entity: (TaggedTemplateQueryPart<UPDATE_3<StaticAny>>)
3055
+ // UPDATE<SingularInstanceType<T>> is used here so type inference in set/with has the property keys of the singular type
3056
+ & (<T extends ArrayConstructable> (entity: T, primaryKey?: PK) => UPDATE_3<SingularInstanceType<T>>)
3057
+ & (<T extends Constructable> (entity: T, primaryKey?: PK) => UPDATE_3<InstanceType<T>>)
3058
+ & ((entity: EntityDescription | ref | Definition_2, primaryKey?: PK) => UPDATE_3<StaticAny>)
3059
+ & (<T> (entity: T, primaryKey?: PK) => UPDATE_3<T>)
2991
3060
 
2992
- // currently no easy way to restrict T from being a primitive type
2993
- static entity<T> (entity: T, primaryKey?: PK): UPDATE_3<T>
2994
-
2995
- // with (block: (e:T)=>void) : this
2996
- // set (block: (e:T)=>void) : this
2997
- set: TaggedTemplateQueryPart<this>
2998
- & ((data: object) => this);
2999
-
3000
- with: TaggedTemplateQueryPart<this>
3001
- & ((data: object) => this)
3061
+ set: UpdateSet<this, T>
3062
+ with: UpdateSet<this, T>
3002
3063
 
3003
3064
  UPDATE: CQN.UPDATE['UPDATE']
3004
3065
 
3005
3066
  }
3006
3067
 
3068
+ /**
3069
+ * Represents updatable block that can be passed to either `.set` or `.with`
3070
+ * of an `UPDATE` query
3071
+ */
3072
+ type UpdateSet<This, T> = TaggedTemplateQueryPart<This>
3073
+ // simple value > title: 'Some Title'
3074
+ // qbe expression > stock: { '-=': quantity }
3075
+ // cqn expression > descr: {xpr: [{ref:[descr]}, '||', 'Some addition to descr.']}
3076
+ & ((data: {[P in keyof T]?: T[P] | {[op in QbeOp]?: T[P]} | CQN.xpr}) => This)
3077
+
3007
3078
  type UPSERT_2 = { UPSERT: {
3008
3079
  into: ref | name,
3009
3080
  columns: string[],
@@ -3018,13 +3089,13 @@ interface UPSERT_3<T> extends Columns<T>, InUpsert<T> {}
3018
3089
  class UPSERT_3<T> extends ConstructedQuery<T> {
3019
3090
  private constructor();
3020
3091
 
3021
- static into: (<T extends ArrayConstructable> (entity: T, entries?: Entries) => UPSERT_3<SingularInstanceType<T>>)
3092
+ static into: (<T extends ArrayConstructable> (entity: T, ...entries: SingularInstanceType<T>[]) => UPSERT_3<SingularInstanceType<T>>)
3093
+ & (<T extends ArrayConstructable> (entity: T, entries?: SingularInstanceType<T>[]) => UPSERT_3<SingularInstanceType<T>>)
3022
3094
  & (TaggedTemplateQueryPart<UPSERT_3<StaticAny>>)
3095
+ & ((entity: EntityDescription, ...entries: Entries[]) => UPSERT_3<StaticAny>)
3023
3096
  & ((entity: EntityDescription, entries?: Entries) => UPSERT_3<StaticAny>)
3024
- & (<T> (entity: Constructable<T>, entries?: Entries) => UPSERT_3<T>)
3025
- // currently no easy way to restrict T to non-primitives
3026
- & (<T> (entity: T, entries?: T | Entries) => UPSERT_3<T>)
3027
-
3097
+ & (<T> (entity: Constructable<T>, ...entries: T[]) => UPSERT_3<T>)
3098
+ & (<T> (entity: Constructable<T>, entries?: T[]) => UPSERT_3<T>)
3028
3099
 
3029
3100
  UPSERT: CQN.UPSERT['UPSERT']
3030
3101
 
@@ -3053,8 +3124,16 @@ export class User {
3053
3124
 
3054
3125
  roles: Array<string> | Record<string, string>
3055
3126
 
3127
+ static Anonymous: typeof Anonymous
3128
+
3129
+ static anonymous: Anonymous
3130
+
3056
3131
  static Privileged: typeof Privileged
3057
3132
 
3133
+ static privileged: Privileged
3134
+
3135
+ static default: User
3136
+
3058
3137
  is (role: string): boolean
3059
3138
 
3060
3139
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/cds-types",
3
- "version": "0.7.0",
3
+ "version": "0.9.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/",
@@ -33,10 +33,8 @@
33
33
  "dependencies": "node ./scripts/postinstall.js"
34
34
  },
35
35
  "peerDependencies": {
36
- "@sap/cds": "^8.0.0"
37
- },
38
- "dependencies": {
39
- "@types/express": "^4.17.21"
36
+ "@sap/cds": "^8.0.0",
37
+ "@types/express": ">=4"
40
38
  },
41
39
  "devDependencies": {
42
40
  "@eslint/js": "^9.2.0",