@cap-js/cds-types 0.6.5 → 0.8.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 +482 -260
  2. package/package.json +3 -2
@@ -1,5 +1,5 @@
1
1
  declare module '@sap/cds' {
2
-
2
+
3
3
 
4
4
  export type __any_ = classes.any_
5
5
 
@@ -70,6 +70,12 @@ export interface ActionEventHandler<P, R> {
70
70
  (req: Omit<Request_2, 'data'> & { data: P }, next: Function): Promise<R> | R
71
71
  }
72
72
 
73
+ interface And {
74
+ and: TaggedTemplateQueryPart<this>
75
+ & ((predicate: object) => this)
76
+ & ((...expr: any[]) => this)
77
+ }
78
+
73
79
  const any: typeof any_;
74
80
 
75
81
  interface any_ extends csn.any_ {}
@@ -87,6 +93,13 @@ interface any__2 {
87
93
  kind?: kinds
88
94
  }
89
95
 
96
+ /**
97
+ * The {@link https://expressjs.com/en/4x/api.html#app| express.js application} constructed by the server implementation.
98
+ *
99
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-server#cds-app)
100
+ */
101
+ export const app: import('express').Application;
102
+
90
103
  export class ApplicationService extends Service {}
91
104
 
92
105
  export class array extends type<'type' | 'elements'> { }
@@ -95,20 +108,6 @@ interface ArrayConstructable<T = any> {
95
108
  new(...args: any[]): T[]
96
109
  }
97
110
 
98
- /**
99
- * A subset of array-like methods, but not `ArrayLike`, as it does not expose `.length`.
100
- * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#iterable)
101
- * @internal
102
- * @since cds 7.9
103
- */
104
- type _ArrayLike<T> = Iterable<T> & {
105
- forEach: (handler: (element: T) => any) => void,
106
- filter: (predicate: (element: T) => boolean) => Array<T>,
107
- map: <R>(converter: (element: T) => R) => Array<R>,
108
- some: (predicate: (element: T) => boolean) => boolean,
109
- find: (predicate: (element: T) => boolean) => T | undefined,
110
- }
111
-
112
111
  class aspect<K extends kinds = 'aspect'> extends type<K> implements WithElements {
113
112
  elements: Definitions<type<'type'>>
114
113
  }
@@ -130,7 +129,6 @@ export class Association extends type {
130
129
  }
131
130
 
132
131
  interface Association_2 extends type_2 {
133
- type: 'cds.Association' | 'cds.Composition'
134
132
  target: FQN
135
133
 
136
134
  /**
@@ -154,17 +152,17 @@ type Awaitable<T, I> = T & Promise<I>
154
152
  class Axios {
155
153
 
156
154
  get axios (): import('axios').AxiosInstance
157
- get: import('axios').AxiosInstance['get'];
155
+ get: import('axios').AxiosInstance['get'] & TaggedTemplateRequest
158
156
 
159
- put: import('axios').AxiosInstance['put']
157
+ put: import('axios').AxiosInstance['put'] & TaggedTemplateRequest
160
158
 
161
- post: import('axios').AxiosInstance['post']
159
+ post: import('axios').AxiosInstance['post'] & TaggedTemplateRequest
162
160
 
163
- patch: import('axios').AxiosInstance['patch']
161
+ patch: import('axios').AxiosInstance['patch'] & TaggedTemplateRequest
164
162
 
165
- delete: import('axios').AxiosInstance['delete']
163
+ delete: import('axios').AxiosInstance['delete'] & TaggedTemplateRequest
166
164
 
167
- options: import('axios').AxiosInstance['options']
165
+ options: import('axios').AxiosInstance['options'] & TaggedTemplateRequest
168
166
 
169
167
  get GET (): Axios['get']
170
168
 
@@ -197,6 +195,10 @@ export const builtin: {
197
195
  types: Record<string, object>, // FIXME: value should be any class part of linked.classes
198
196
  };
199
197
 
198
+ interface ByKey {
199
+ byKey (primaryKey?: PK): this
200
+ }
201
+
200
202
  export type CDL = string
201
203
 
202
204
  namespace cds {
@@ -212,6 +214,7 @@ namespace cds {
212
214
  version,
213
215
  home,
214
216
  root,
217
+ cli,
215
218
  requires,
216
219
  extend,
217
220
  lazify,
@@ -238,11 +241,13 @@ namespace cds {
238
241
  cds_connect_options,
239
242
  Middleswares,
240
243
  middlewares,
244
+ app,
241
245
  env,
242
246
  _TODO,
243
247
  get,
244
248
  load,
245
249
  resolve,
250
+ minify,
246
251
  reflect,
247
252
  _flavor,
248
253
  _odata_options,
@@ -352,6 +357,8 @@ namespace cds {
352
357
  ordering_term,
353
358
  expr,
354
359
  ref,
360
+ _segment,
361
+ _named,
355
362
  val,
356
363
  xpr,
357
364
  _xpr,
@@ -370,7 +377,7 @@ export interface cds_connect_options {
370
377
  impl?: string
371
378
  service?: string
372
379
  kind?: string
373
- model?: string
380
+ model?: string | CSN
374
381
  credentials?: object
375
382
  }
376
383
 
@@ -383,7 +390,9 @@ export interface cds_serve_fluent {
383
390
  // (req,res) : void
384
391
  }
385
392
 
386
- export type cds_services = { [name: string]: Service }
393
+ export interface cds_services {
394
+ [name: string]: Service
395
+ }
387
396
 
388
397
  export type CdsFunction = {
389
398
  (...args: any[]): any,
@@ -440,10 +449,34 @@ namespace classes {
440
449
  }
441
450
  }
442
451
 
452
+ /**
453
+ * The parsed effective `cds` CLI command and arguments.
454
+ * May be undefined if not started from the `cds` CLI.
455
+ * @see https://cap.cloud.sap/docs/node.js/cds-facade#cds-cli
456
+ */
457
+ export const cli: {
458
+ /** Basic command like `serve` */ command?: CliCommands,
459
+ /** Positional arguments */ argv?: string[],
460
+ /** Named arguments */ options?: Record<string, any>,
461
+ } | undefined;
462
+
463
+ type CliCommands = 'add' | 'build' | 'compile' | 'deploy' | 'import' | 'init' | 'serve' | (string & {})
464
+
443
465
  type Column = { ref: [string], as?: string }
444
466
 
445
467
  export type column_expr = UnionToIntersection<expr> & { as?: name, cast?: any, expand?: column_expr[], inline?: column_expr[] }
446
468
 
469
+ interface Columns<T, This = undefined> {
470
+ columns:
471
+ ((...col: KeyOfSingular<T>[]) => This extends undefined ? this : This)
472
+ & ((col: KeyOfSingular<T>[]) => This extends undefined ? this : This)
473
+ & ((...col: (string | column_expr)[]) => This extends undefined ? this : This)
474
+ & ((col: (string | column_expr)[]) => This extends undefined ? this : This)
475
+ & TaggedTemplateQueryPart<This extends undefined ? this : This>
476
+ }
477
+
478
+ type ColumnValue = Primitive | Readonly<Primitive[]> | SELECT<any>
479
+
447
480
  /**
448
481
  * Provides a set of methods to parse a given model, query or expression.
449
482
  * You can also use `cds.compile(csn).to('<output>')` as a fluent variant.
@@ -456,6 +489,7 @@ export const compile: {
456
489
  for: {
457
490
  odata (model: csn.CSN, o?: _options): csn.CSN,
458
491
  sql (model: csn.CSN, o?: _options): csn.CSN,
492
+ nodejs (model: csn.CSN, o?: _options): linked.LinkedCSN,
459
493
  },
460
494
  to: {
461
495
  parsed: {
@@ -575,8 +609,10 @@ interface Constructable<T = any> {
575
609
  new(...args: any[]): T
576
610
  }
577
611
 
578
- class ConstructedQuery {
579
-
612
+ class ConstructedQuery<T> {
613
+ // branded type to break covariance for the subclasses
614
+ // that don't make explicit use of the generic. So `UPDATE<Books> !<: UPDATE<number>`
615
+ private _: T
580
616
  then (_resolved: (x: any) => any, _rejected: (e: Error) => any): any
581
617
 
582
618
  }
@@ -611,6 +647,8 @@ namespace CQN {
611
647
  ordering_term,
612
648
  expr,
613
649
  ref,
650
+ _segment,
651
+ _named,
614
652
  val,
615
653
  xpr,
616
654
  _xpr,
@@ -629,9 +667,10 @@ type CREATE_2 = { CREATE: {
629
667
  }, }
630
668
  export { CREATE_2 as CREATE }
631
669
 
632
- class CREATE_3<T> extends ConstructedQuery {
670
+ class CREATE_3<T> extends ConstructedQuery<T> {
671
+ private constructor();
633
672
 
634
- static entity (entity: Target): CREATE_3<any>
673
+ static entity (entity: EntityDescription): CREATE_3<EntityDescription>
635
674
 
636
675
  CREATE: CQN.CREATE['CREATE']
637
676
 
@@ -743,7 +782,17 @@ export const db: DatabaseService;
743
782
  */
744
783
  export function debug (name: string): undefined | Log
745
784
 
746
- class Decimal extends Float { }
785
+ class Decimal extends Float {
786
+ precision?: number
787
+ scale?: number
788
+ }
789
+
790
+ /**
791
+ * Recursively excludes nullability from all properties of T.
792
+ */
793
+ type DeepRequired<T> = {
794
+ [K in keyof T]: DeepRequired<T[K]>
795
+ } & Exclude<Required<T>, null>
747
796
 
748
797
  export namespace default_2 {
749
798
  export {
@@ -757,6 +806,7 @@ export namespace default_2 {
757
806
  version,
758
807
  home,
759
808
  root,
809
+ cli,
760
810
  requires,
761
811
  extend,
762
812
  lazify,
@@ -783,11 +833,13 @@ export namespace default_2 {
783
833
  cds_connect_options,
784
834
  Middleswares,
785
835
  middlewares,
836
+ app,
786
837
  env,
787
838
  _TODO,
788
839
  get,
789
840
  load,
790
841
  resolve,
842
+ minify,
791
843
  reflect,
792
844
  _flavor,
793
845
  _odata_options,
@@ -897,6 +949,8 @@ export namespace default_2 {
897
949
  ordering_term,
898
950
  expr,
899
951
  ref,
952
+ _segment,
953
+ _named,
900
954
  val,
901
955
  xpr,
902
956
  _xpr,
@@ -928,22 +982,16 @@ type DELETE_2 = { DELETE: {
928
982
  }, }
929
983
  export { DELETE_2 as DELETE }
930
984
 
931
- class DELETE_3<T> extends ConstructedQuery {
985
+ interface DELETE_3<T> extends Where<T>, And, ByKey {}
932
986
 
933
- static from:
934
- TaggedTemplateQueryPart<Awaitable<SELECT_3<unknown>, InstanceType<any>>>
935
- & ((entity: Target | ArrayConstructable, primaryKey?: PK) => DELETE_3<any>)
936
- & ((subject: ref) => DELETE_3<any>)
987
+ class DELETE_3<T> extends ConstructedQuery<T> {
988
+ private constructor();
937
989
 
938
- byKey (primaryKey?: PK): this
939
-
940
- where (predicate: object): this
941
-
942
- where (...expr: any[]): this
943
-
944
- and (predicate: object): this
990
+ static from:
991
+ TaggedTemplateQueryPart<Awaitable<SELECT_3<unknown>, InstanceType<StaticAny>>>
992
+ & (<T>(entity: EntityDescription | ArrayConstructable, primaryKey?: PK) => DELETE_3<T>)
993
+ & ((subject: ref) => DELETE_3<_TODO_2>)
945
994
 
946
- and (...expr: any[]): this
947
995
  DELETE: CQN.DELETE['DELETE']
948
996
 
949
997
  }
@@ -957,9 +1005,10 @@ type DROP_2 = { DROP: {
957
1005
  }, }
958
1006
  export { DROP_2 as DROP }
959
1007
 
960
- class DROP_3<T> extends ConstructedQuery {
1008
+ class DROP_3<T> extends ConstructedQuery<T> {
1009
+ private constructor();
961
1010
 
962
- static entity (entity: Target): DROP_3<any>
1011
+ static entity (entity: EntityDescription): DROP_3<EntityDescription>
963
1012
 
964
1013
  DROP: CQN.DROP['DROP']
965
1014
 
@@ -1010,15 +1059,22 @@ interface entity_2 extends Omit<struct_2, 'elements'> {
1010
1059
  drafts?: entity_2
1011
1060
  }
1012
1061
 
1062
+ type EntityDescription = entity | Definition | string
1063
+
1013
1064
  type EntityElements = {
1014
1065
  [name: string]: Element & {
1015
1066
  key?: boolean,
1016
1067
  virtual?: boolean,
1017
1068
  unique?: boolean,
1018
1069
  notNull?: boolean,
1070
+ precision?: number,
1071
+ scale?: number,
1072
+ length?: number,
1019
1073
  },
1020
1074
  }
1021
1075
 
1076
+ type Entries<T = any> = {[key:string]: T} | {[key:string]: T}
1077
+
1022
1078
  export type enum_literal = { '#': string }
1023
1079
 
1024
1080
  /**
@@ -1036,6 +1092,7 @@ export const env: {
1036
1092
  folders: string[],
1037
1093
  [key: string]: any,
1038
1094
  },
1095
+ profiles: string[],
1039
1096
  requires: env.Requires,
1040
1097
  folders: {
1041
1098
  app: string,
@@ -1087,23 +1144,50 @@ export namespace env {
1087
1144
  binding?: Binding,
1088
1145
  [key: string]: any,
1089
1146
  },
1090
- multitenancy: boolean | { kind: string, jobs: {
1147
+ multitenancy?: boolean | { kind: string, jobs: {
1091
1148
  clusterSize: number,
1092
1149
  workerSize: number,
1093
1150
  t0: string,
1094
1151
  [key: string]: any,
1095
1152
  },},
1096
- toggles: boolean,
1097
- extensibility: boolean | {
1153
+ toggles?: boolean,
1154
+ extensibility?: boolean | {
1098
1155
  model: string[],
1099
1156
  tenantCheckInterval: number,
1100
1157
  [key: string]: any,
1101
1158
  },
1102
- messaging: {
1159
+ messaging?: {
1103
1160
  kind: 'file-based-messaging' | 'redis-messaging' | 'local-messaging' | 'enterprise-messaging' | 'enterprise-messaging-shared' | string,
1104
1161
  format: 'cloudevents' | string,
1105
1162
  [key: string]: any,
1106
1163
  },
1164
+ 'cds.xt.SaasProvisioningService'?: {
1165
+ model: string,
1166
+ kind: string,
1167
+ alwaysUpgradeModel?: boolean,
1168
+ [key: string]: any,
1169
+ },
1170
+ 'cds.xt.SmsProvisioningService'?: {
1171
+ model: string,
1172
+ kind: string,
1173
+ [key: string]: any,
1174
+ },
1175
+ 'cds.xt.ExtensibilityService'?: {
1176
+ model: string,
1177
+ kind?: string,
1178
+ [key: string]: any,
1179
+ },
1180
+ 'cds.xt.ModelProviderService'?: {
1181
+ model: string,
1182
+ root: string,
1183
+ kind?: string,
1184
+ [key: string]: any,
1185
+ },
1186
+ 'cds.xt.DeploymentService'?: {
1187
+ model: string,
1188
+ kind?: string,
1189
+ [key: string]: any,
1190
+ },
1107
1191
  [key: string]: any,
1108
1192
  }
1109
1193
 
@@ -1140,6 +1224,10 @@ class Event_2 extends EventContext {
1140
1224
 
1141
1225
  headers: any
1142
1226
 
1227
+ before(phase: 'commit', handler: () => void)
1228
+
1229
+ on(phase: 'succeeded' | 'failed' | 'done', handler: () => void)
1230
+
1143
1231
  }
1144
1232
  export { Event_2 as Event }
1145
1233
 
@@ -1164,6 +1252,8 @@ export class EventContext {
1164
1252
 
1165
1253
  features?: { [key: string]: boolean }
1166
1254
 
1255
+ model: LinkedCSN
1256
+
1167
1257
  }
1168
1258
 
1169
1259
  export interface EventHandler {
@@ -1181,6 +1271,15 @@ export type expr = ref | val | xpr | function_call | SELECT_2
1181
1271
 
1182
1272
  export type expr_literal = { '=': string }
1183
1273
 
1274
+ type Expression<E extends string | number | bigint | boolean> = `${E}${WS}${Op}${WS}`
1275
+
1276
+ type Expressions<L,E> = KVPairs<L, Expression<Exclude<keyof E, symbol>>, ColumnValue> extends true
1277
+ ? L
1278
+ // fallback: allow for any string. Important for when user renamed properties
1279
+ : KVPairs<L, Expression<string>, ColumnValue> extends true
1280
+ ? L
1281
+ : never
1282
+
1184
1283
  /**
1185
1284
  * Add aspects to a given object, for example:
1186
1285
  *
@@ -1244,6 +1343,40 @@ export type function_call = { func: string, args: { [key: string]: any }[] }
1244
1343
  */
1245
1344
  export function get (files: '*' | filename | filename[], o?: _options): Promise<csn.CSN>
1246
1345
 
1346
+ interface GroupBy {
1347
+ groupBy: TaggedTemplateQueryPart<this>
1348
+ & ((columns: Partial<{[column in KeyOfTarget<this extends ConstructedQuery<infer E> ? E : never, never>]: any}>) => this)
1349
+ & ((...expr: string[]) => this)
1350
+ & ((ref: ref) => this)
1351
+ // columns currently not being auto-completed due to complexity
1352
+ }
1353
+
1354
+ interface Having<T> {
1355
+ having: HavingWhere<this, T>
1356
+ }
1357
+
1358
+ type HavingWhere<This, E> =
1359
+ /**
1360
+ * @param predicate - An object with keys that are valid fields of the target entity and values that are compared to the respective fields.
1361
+ * @example
1362
+ * ```js
1363
+ * SELECT.from(Books).where({ ID: 42 }) // where ID is a valid field of Book
1364
+ * SELECT.from(Books).having({ ID: 42 }) // where ID is a valid field of Book
1365
+ * ```
1366
+ */
1367
+ ((predicate: Partial<{[column in KeyOfTarget<This extends ConstructedQuery<infer E> ? E : never, never>]: any}>) => This)
1368
+ /**
1369
+ * @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.
1370
+ * @example
1371
+ * ```js
1372
+ * SELECT.from(Books).where(['ID =', 42 ]) // where ID is a valid, numerical field of Book
1373
+ * SELECT.from(Books).having(['ID =', 42 ]) // where ID is a valid, numerical field of Book
1374
+ *```
1375
+ */
1376
+ & (<const L extends unknown[]>(...expr: Expressions<L, UnwrappedInstanceType<E>>) => This)
1377
+ & ((...expr: string[]) => This)
1378
+ & TaggedTemplateQueryPart<This>
1379
+
1247
1380
  export const home: string;
1248
1381
 
1249
1382
  export const insert: Service['insert'];
@@ -1258,31 +1391,22 @@ type INSERT_2 = { INSERT: {
1258
1391
  }, }
1259
1392
  export { INSERT_2 as INSERT }
1260
1393
 
1261
- class INSERT_3<T> extends ConstructedQuery {
1262
-
1263
- static into: (<T extends ArrayConstructable<any>> (entity: T, entries?: object | object[]) => INSERT_3<SingularType<T>>)
1264
- & (TaggedTemplateQueryPart<INSERT_3<unknown>>)
1265
- & ((entity: Target, entries?: object | object[]) => INSERT_3<any>)
1266
- & (<T> (entity: Constructable<T>, entries?: object | object[]) => INSERT_3<T>)
1267
- & (<T> (entity: T, entries?: T | object | object[]) => INSERT_3<T>)
1268
-
1269
- into: (<T extends ArrayConstructable> (entity: T) => this)
1270
- & TaggedTemplateQueryPart<this>
1271
- & ((entity: Target) => this)
1272
-
1273
- data (block: (e: T) => void): this
1274
-
1275
- entries (...entries: object[]): this
1394
+ interface INSERT_3<T> extends Columns<T>, InUpsert<T> {}
1276
1395
 
1277
- columns (...col: (T extends ArrayConstructable<any> ? keyof SingularType<T> : keyof T)[]): this
1396
+ class INSERT_3<T> extends ConstructedQuery<T> {
1397
+ private constructor();
1278
1398
 
1279
- columns (...col: string[]): this
1280
-
1281
- values (...val: any[]): this
1282
-
1283
- rows (...row: any[]): this
1399
+ static into: (<T extends ArrayConstructable> (entity: T, entries?: Entries) => INSERT_3<SingularInstanceType<T>>)
1400
+ & (TaggedTemplateQueryPart<INSERT_3<unknown>>)
1401
+ & ((entity: EntityDescription, entries?: Entries) => INSERT_3<StaticAny>)
1402
+ & (<T> (entity: Constructable<T>, entries?: Entries) => INSERT_3<T>)
1403
+ & (<T> (entity: T, entries?: T | Entries) => INSERT_3<T>)
1284
1404
 
1405
+ /**
1406
+ * @deprected
1407
+ */
1285
1408
  as (select: SELECT_3<T>): this
1409
+ from (select: SELECT_3<T>): this
1286
1410
  INSERT: CQN.INSERT['INSERT']
1287
1411
 
1288
1412
  }
@@ -1299,53 +1423,70 @@ type Intersect<T extends readonly unknown[]> = T extends [infer Head, ...infer T
1299
1423
  ? Head & Intersect<Tail>
1300
1424
  : unknown
1301
1425
 
1426
+ interface InUpsert<T> {
1427
+ data (block: (e: T) => void): this
1428
+
1429
+ entries (...entries: object[]): this
1430
+
1431
+ values (...val: (null | Primitive)[]): this
1432
+ values (val: (null | Primitive)[]): this
1433
+
1434
+ rows (...row: (null | Primitive)[][]): this
1435
+ rows (row: (null | Primitive)[][]): this
1436
+
1437
+ into: (<T extends ArrayConstructable> (entity: T) => this)
1438
+ & TaggedTemplateQueryPart<this>
1439
+ & ((entity: EntityDescription) => this)
1440
+ }
1441
+
1302
1442
  /**
1303
1443
  * Object structure that exposes both array-like and object-like behaviour.
1304
1444
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#iterable)
1305
1445
  */
1306
- type IterableMap<T> = { [name: string]: T } & _ArrayLike<T>
1446
+
1447
+ type IterableMap<T> = { [name: string]: T } & Iterable<T>
1307
1448
 
1308
1449
  type JSON_2 = string
1309
1450
  export { JSON_2 as JSON }
1310
1451
 
1311
1452
  export type Key = number | string | any
1312
1453
 
1313
- type kinds = 'aspect' | 'entity' | 'type' | 'event' | 'action' | 'function' | 'service' | 'context' | 'elements'
1454
+ type KeyOfSingular<T> = Unwrap<T> extends T
1455
+ ? keyof T
1456
+ : keyof Unwrap<T>
1457
+
1458
+ type KeyOfTarget<T, F = string | column_expr> = T extends ConstructedQuery<infer U>
1459
+ ? (U extends ArrayConstructable // Books
1460
+ ? keyof SingularInstanceType<U>
1461
+ : U extends Constructable // Book
1462
+ ? keyof InstanceType<U>
1463
+ : F)
1464
+ : F
1465
+
1466
+ type kinds = 'aspect' | 'entity' | 'type' | 'event' | 'action' | 'function' | 'service' | 'context' | 'elements' | 'element'
1467
+
1468
+ /**
1469
+ * T is a tuple of alternating K, V pairs -> true, else false
1470
+ * Allows for variadic parameter lists with alternating expecing types,
1471
+ * like we have in cql.SELECT.where
1472
+ */
1473
+ type KVPairs<T,K,V> = T extends []
1474
+ ? true
1475
+ : T extends [K, V, ...infer R]
1476
+ ? KVPairs<R,K,V>
1477
+ : false
1314
1478
 
1315
1479
  class LargeBinary extends Binary { }
1316
1480
 
1317
1481
  class LargeString extends String_2 { }
1318
1482
 
1319
1483
  /**
1320
- * Prepare a node module for lazy-loading submodules instead
1321
- * of static requires. Example:
1322
- *
1323
- * @example
1324
- * ```js
1325
- * require = lazify (module) //> turns require into a lazy one
1326
- * const facade = module.exports = {
1327
- * sub: require ('./sub-module')
1328
- * })
1329
- * ```
1330
- *
1331
- * The first usage of `facade.sub` will load the sub module
1332
- * using standard Node.js's `module.require` functions.
1484
+ * @deprecated since version 8.1
1333
1485
  */
1334
1486
  export function lazified<T> (target: T): T
1335
1487
 
1336
1488
  /**
1337
- * Equip a given facade object with getters for lazy-loading modules instead
1338
- * of static requires. Example:
1339
- *
1340
- * @example
1341
- * ```js
1342
- * const facade = lazify ({
1343
- * sub: lazy => require ('./sub-module')
1344
- * })
1345
- * ```
1346
- *
1347
- * The first usage of `facade.sub` will load the sub module
1348
- * using standard Node.js's `module.require` functions.
1489
+ * @deprecated since version 8.1
1349
1490
  */
1350
1491
  export function lazify<T> (target: T): T
1351
1492
 
@@ -1355,6 +1496,11 @@ enum levels {
1355
1496
  SILENT = 0, ERROR = 1, WARN = 2, INFO = 3, DEBUG = 4, TRACE = 5, SILLY = 5, VERBOSE = 5
1356
1497
  }
1357
1498
 
1499
+ interface Limit {
1500
+ limit: TaggedTemplateQueryPart<this>
1501
+ & ((rows: number, offset?: number) => this)
1502
+ }
1503
+
1358
1504
  export const linked: {
1359
1505
 
1360
1506
  /**
@@ -1680,6 +1826,12 @@ export const middlewares: {
1680
1826
  add: (middleware: import('express').RequestHandler, pos?: XOR<XOR<{ at: number }, { after: Middleswares }>, { before: Middleswares }>) => void,
1681
1827
  };
1682
1828
 
1829
+ /**
1830
+ * Minifies a given CSN model by removing all unused1 types and aspects, as well all entities tagged with `@cds.persistence.skip:'if-unused'`
1831
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-compile#cds-minify)
1832
+ */
1833
+ export function minify (model: csn.CSN): csn.CSN
1834
+
1683
1835
  /**
1684
1836
  * Allows arbitrary property access. Can be used for explicitly casting
1685
1837
  * classes you have added {@link mixin}s to.
@@ -1724,6 +1876,7 @@ namespace models {
1724
1876
  get,
1725
1877
  load,
1726
1878
  resolve,
1879
+ minify,
1727
1880
  reflect,
1728
1881
  _flavor,
1729
1882
  _odata_options,
@@ -1777,6 +1930,9 @@ namespace models {
1777
1930
  /** @private */
1778
1931
  export type name = string
1779
1932
 
1933
+ /** @private */
1934
+ export type _named = { [key: name]: expr }
1935
+
1780
1936
  const number: typeof number_;
1781
1937
 
1782
1938
  class number_ extends scalar { }
@@ -1849,6 +2005,8 @@ export interface OnEventHandler {
1849
2005
  (req: Request_2, next: Function): Promise<any> | any | void
1850
2006
  }
1851
2007
 
2008
+ type Op = '=' | '<' | '>' | '<=' | '>=' | '!=' | 'in' | 'like'
2009
+
1852
2010
  /** @private */
1853
2011
  export type operator = string
1854
2012
 
@@ -1860,8 +2018,14 @@ export type _options = {
1860
2018
  odata?: _odata_options,
1861
2019
  } | _flavor
1862
2020
 
2021
+ interface OrderBy<T> {
2022
+ orderBy: TaggedTemplateQueryPart<this>
2023
+ & ((...col: KeyOfSingular<T>[]) => this)
2024
+ & ((...expr: string[]) => this)
2025
+ }
2026
+
1863
2027
  /** @private */
1864
- export type ordering_term = expr & { sort?: 'asc' | 'desc', nulls?: 'first' | 'last' }
2028
+ export type ordering_term = UnionToIntersection<expr> & { sort?: 'asc' | 'desc', nulls?: 'first' | 'last' }
1865
2029
 
1866
2030
  export const outboxed: (service: Service) => Service;
1867
2031
 
@@ -1885,7 +2049,7 @@ export { Partial_2 as Partial }
1885
2049
 
1886
2050
  type PK = number | string | object
1887
2051
 
1888
- type PluralType<T extends Constructable> = Array<InstanceType<T>>
2052
+ type PluralInstanceType<T extends Constructable> = Array<InstanceType<T>>
1889
2053
 
1890
2054
  export type predicate = UnionsToIntersections<_xpr>
1891
2055
 
@@ -1905,7 +2069,7 @@ export class Privileged extends User {
1905
2069
 
1906
2070
  }
1907
2071
 
1908
- type Projection<T> = (e: QLExtensions<T extends ArrayConstructable ? SingularType<T> : T>) => void
2072
+ type Projection<T> = (e: QLExtensions<T extends ArrayConstructable ? SingularInstanceType<T> : T>) => void
1909
2073
 
1910
2074
  /**
1911
2075
  * @alpha
@@ -1917,42 +2081,32 @@ class QL<T> {
1917
2081
 
1918
2082
  SELECT: StaticSELECT<T>
1919
2083
 
1920
- INSERT: typeof INSERT_3
1921
- & ((...entries: object[]) => INSERT_3<any>) & ((entries: object[]) => INSERT_3<any>)
2084
+ INSERT: typeof INSERT_3<T>
2085
+ & ((...entries: object[]) => INSERT_3<T>) & ((entries: object[]) => INSERT_3<T>)
1922
2086
 
1923
2087
  UPSERT: typeof UPSERT_3
1924
- & ((...entries: object[]) => UPSERT_3<any>) & ((entries: object[]) => UPSERT_3<any>)
2088
+ & ((...entries: object[]) => UPSERT_3<T>) & ((entries: object[]) => UPSERT_3<T>)
1925
2089
 
1926
- UPDATE: typeof UPDATE_3
1927
- & typeof UPDATE_3.entity
2090
+ UPDATE: typeof UPDATE_3<T>
2091
+ & typeof UPDATE_3.entity<_TODO_2>
1928
2092
 
1929
- DELETE: typeof DELETE_3
1930
- & ((...entries: object[]) => DELETE_3<any>) & ((entries: object[]) => DELETE_3<any>)
2093
+ DELETE: typeof DELETE_3<T>
2094
+ & ((...entries: object[]) => DELETE_3<T>) & ((entries: object[]) => DELETE_3<T>)
1931
2095
 
1932
- CREATE: typeof CREATE_3
2096
+ CREATE: typeof CREATE_3<T>
1933
2097
 
1934
- DROP: typeof DROP_3
2098
+ DROP: typeof DROP_3<T>
1935
2099
 
1936
2100
  }
1937
2101
 
1938
2102
  namespace ql {
1939
2103
  export {
1940
2104
  Query_2 as Query,
1941
- ConstructedQuery,
1942
- PK,
1943
- Primitive,
1944
2105
  QLExtensions,
1945
- Target,
1946
- QLExtensions_,
1947
- Subqueryable,
1948
- Projection,
1949
- Awaitable,
2106
+ ConstructedQuery,
1950
2107
  StaticSELECT,
1951
2108
  QL,
1952
- TaggedTemplateQueryPart,
1953
2109
  SELECT_3 as SELECT,
1954
- SELECT_one,
1955
- SELECT_from,
1956
2110
  INSERT_3 as INSERT,
1957
2111
  UPSERT_3 as UPSERT,
1958
2112
  DELETE_3 as DELETE,
@@ -1963,35 +2117,20 @@ namespace ql {
1963
2117
  }
1964
2118
  export { ql }
1965
2119
 
1966
- export type QLExtensions<T> = T extends QLExtensions_<any> ? T : QLExtensions_<T>
2120
+ export type QLExtensions<T> = T extends QLExtensions_<any> ? T : QLExtensions_<DeepRequired<T>>
1967
2121
 
1968
2122
  /**
1969
2123
  * QLExtensions are properties that are attached to entities in CQL contexts.
1970
2124
  * They are passed down to all properties recursively.
1971
2125
  */
1972
- type QLExtensions_<T> = {
1973
- [Key in keyof T]: QLExtensions<T[Key]>
1974
- } & {
1975
-
1976
- /**
1977
- * Alias for this attribute.
1978
- */
1979
- as: (alias: string) => void,
1980
-
1981
- /**
1982
- * Accesses any nested attribute based on a [path](https://cap.cloud.sap/cap/docs/java/query-api#path-expressions):
1983
- * `X.get('a.b.c.d')`. Note that you will not receive
1984
- * proper typing after this call.
1985
- * To still have access to typed results, use
1986
- * `X.a().b().c().d()` instead.
1987
- */
1988
- get: (path: string) => any,
1989
-
1990
- // have to exclude undefined from the type, or we'd end up with a distribution of Subqueryable
1991
- // over T and undefined, which gives us zero code completion within the callable.
1992
- } & Subqueryable<Exclude<T, undefined>>
2126
+ // have to exclude undefined from the type, or we'd end up with a distribution of Subqueryable
2127
+ // over T and undefined, which gives us zero code completion within the callable.
2128
+ type QLExtensions_<T> = { [Key in keyof T]: QLExtensions<T[Key]> } & QueryArtefact & Subqueryable<Exclude<T, undefined>>
1993
2129
 
1994
- export type Query = Partial<SELECT_2 & INSERT_2 & UPDATE_2 & DELETE_2 & CREATE_2 & DROP_2 & UPSERT_2>
2130
+ export type Query = {
2131
+ /** @since 7.4.0 */
2132
+ elements: { [key: string]: Definition },
2133
+ } & Partial<SELECT_2 & INSERT_2 & UPDATE_2 & DELETE_2 & CREATE_2 & DROP_2 & UPSERT_2>
1995
2134
 
1996
2135
  type Query_2 = CQN.Query
1997
2136
 
@@ -2043,7 +2182,7 @@ export class QueryAPI {
2043
2182
  * @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
2044
2183
  */
2045
2184
  run: {
2046
- (query: ConstructedQuery | ConstructedQuery[]): Promise<ResultSet | any>,
2185
+ (query: ConstructedQuery<_TODO_2> | ConstructedQuery<_TODO_2>[]): Promise<ResultSet | any>,
2047
2186
  (query: Query_2): Promise<ResultSet | any>,
2048
2187
  (query: string, args?: any[] | object): Promise<ResultSet | any>,
2049
2188
  }
@@ -2083,10 +2222,28 @@ export class QueryAPI {
2083
2222
 
2084
2223
  }
2085
2224
 
2225
+ type QueryArtefact = {
2226
+
2227
+ /**
2228
+ * Alias for this attribute.
2229
+ */
2230
+ as (alias: string): void,
2231
+
2232
+ /**
2233
+ * Accesses any nested attribute based on a [path](https://cap.cloud.sap/cap/docs/java/query-api#path-expressions):
2234
+ * `X.get('a.b.c.d')`. Note that you will not receive
2235
+ * proper typing after this call.
2236
+ * To still have access to typed results, use
2237
+ * `X.a().b().c().d()` instead.
2238
+ */
2239
+ get (path: string): any,
2240
+
2241
+ }
2242
+
2086
2243
  export const read: Service['read'];
2087
2244
 
2088
2245
  /** @private */
2089
- export type ref = { ref: (name & { id?: string, where?: expr, args?: expr[] })[] }
2246
+ export type ref = { ref: _segment[] }
2090
2247
 
2091
2248
  /**
2092
2249
  * Turns the given plain CSN model into a reflected model
@@ -2191,6 +2348,17 @@ class scalar extends type { }
2191
2348
 
2192
2349
  type Scalarise<A> = A extends Array<infer N> ? N : A
2193
2350
 
2351
+ /** @private */
2352
+ export type _segment = name | {
2353
+ id?: string,
2354
+ where?: _xpr,
2355
+ args?: _named,
2356
+ groupBy: expr[],
2357
+ having: _xpr,
2358
+ orderBy: ordering_term[],
2359
+ limit: { rows: expr, offset: expr },
2360
+ }
2361
+
2194
2362
  type SELECT_2 = { SELECT: {
2195
2363
  distinct?: true,
2196
2364
  one?: boolean,
@@ -2199,51 +2367,36 @@ type SELECT_2 = { SELECT: {
2199
2367
  columns?: column_expr[],
2200
2368
  excluding?: string[],
2201
2369
  where?: predicate,
2202
- having?: predicate,
2203
2370
  groupBy?: expr[],
2371
+ having?: predicate,
2204
2372
  orderBy?: ordering_term[],
2205
2373
  limit?: { rows: val, offset: val },
2374
+ forUpdate?: { wait: number },
2375
+ forShareLock?: { wait: number },
2376
+ search?: predicate,
2377
+ count?: boolean,
2206
2378
  }, }
2207
2379
  export { SELECT_2 as SELECT }
2208
2380
 
2209
- class SELECT_3<T> extends ConstructedQuery {
2210
-
2211
- static one: SELECT_one & { from: SELECT_one }
2212
-
2213
- static distinct: typeof SELECT_3
2214
-
2215
- static from: SELECT_from
2381
+ interface SELECT_3<T> extends Where<T>, And, Having<T>, GroupBy, OrderBy<T>, Limit {
2382
+ // overload specific to SELECT
2383
+ columns: Columns<T, this>['columns'] & ((projection: Projection<T>) => this)
2384
+ }
2216
2385
 
2217
- from: SELECT_from & TaggedTemplateQueryPart<this>
2218
- & ((entity: Target, primaryKey?: PK, projection?: Projection<unknown>) => this)
2386
+ class SELECT_3<T, Q = SELECT_from> extends ConstructedQuery<T> {
2387
+ private constructor();
2219
2388
 
2220
- byKey (primaryKey?: PK): this
2221
- columns: TaggedTemplateQueryPart<this>
2222
- & ((projection: Projection<T>) => this)
2223
- & ((...col: (T extends ArrayConstructable<any> ? keyof SingularType<T> : keyof T)[]) => this)
2224
- & ((...col: (string | column_expr)[]) => this)
2225
- & ((col: (string | column_expr)[]) => this)
2226
-
2227
- where: TaggedTemplateQueryPart<this>
2228
- & ((predicate: object) => this)
2229
- & ((...expr: any[]) => this)
2389
+ static one: SELECT_one & { from: SELECT_one } & { localized: SELECT_one }
2230
2390
 
2231
- and: TaggedTemplateQueryPart<this>
2232
- & ((predicate: object) => this)
2233
- & ((...expr: any[]) => this)
2234
-
2235
- having: TaggedTemplateQueryPart<this>
2236
- & ((...expr: string[]) => this)
2237
- & ((predicate: object) => this)
2391
+ static distinct: typeof SELECT_3<StaticAny>
2238
2392
 
2239
- groupBy: TaggedTemplateQueryPart<this>
2240
- & ((...expr: string[]) => this)
2393
+ static from: SELECT_from & { localized: SELECT_from }
2241
2394
 
2242
- orderBy: TaggedTemplateQueryPart<this>
2243
- & ((...expr: string[]) => this)
2395
+ static localized: SELECT_from & { from: SELECT_from }
2244
2396
 
2245
- limit: TaggedTemplateQueryPart<this>
2246
- & ((rows: number, offset?: number) => this)
2397
+ from: Q // SELECT_from | SELECT_one
2398
+ & TaggedTemplateQueryPart<this>
2399
+ & ((entity: EntityDescription, primaryKey?: PK, projection?: Projection<unknown>) => this)
2247
2400
 
2248
2401
  forShareLock (): this
2249
2402
 
@@ -2274,52 +2427,61 @@ class SELECT_3<T> extends ConstructedQuery {
2274
2427
 
2275
2428
  type SELECT_from =
2276
2429
  // tagged template
2277
- TaggedTemplateQueryPart<Awaitable<SELECT_3<unknown>, InstanceType<any>>>
2430
+ TaggedTemplateQueryPart<Awaitable<SELECT_3<_TODO_2>, InstanceType<_TODO_2>>>
2278
2431
  &
2279
2432
  // calling with class
2280
- (<T extends ArrayConstructable<any>>
2281
- (entityType: T, projection?: Projection<QLExtensions<SingularType<T>>>)
2282
- => Awaitable<SELECT_3<T>, InstanceType<T>>)
2433
+ (<E extends ArrayConstructable>
2434
+ (entityType: E, projection?: Projection<QLExtensions<SingularInstanceType<E>>>)
2435
+ => Awaitable<SELECT_3<E>, InstanceType<E>>)
2283
2436
  &
2284
- (<T extends ArrayConstructable<any>>
2285
- (entityType: T, primaryKey: PK, projection?: Projection<SingularType<T>>)
2286
- => Awaitable<SELECT_3<SingularType<T>>, InstanceType<SingularType<T>>>) // when specifying a key, we expect a single element as result
2437
+ (<E extends ArrayConstructable>
2438
+ (entityType: E, primaryKey: PK, projection?: Projection<SingularInstanceType<E>>)
2439
+ => Awaitable<SELECT_3<SingularInstanceType<E>>, SingularInstanceType<E>>) // when specifying a key, we expect a single element as result
2287
2440
  // calling with definition
2288
- & ((entity: Target, primaryKey?: PK, projection?: Projection<unknown>) => SELECT_3<any>)
2441
+ & (<T>(entity: EntityDescription, primaryKey?: PK, projection?: Projection<T>) => SELECT_3<T>)
2289
2442
  // calling with concrete list
2290
2443
  & (<T> (entity: T[], projection?: Projection<T>) => SELECT_3<T> & Promise<T[]>)
2291
2444
  & (<T> (entity: T[], primaryKey: PK, projection?: Projection<T>) => Awaitable<SELECT_3<T>, T>)
2292
- & ((subject: ref) => SELECT_3<any>)
2445
+ & ((subject: ref) => SELECT_3<_TODO_2>)
2293
2446
  // put these overloads at the very end, as they would also match the above
2294
2447
  // We expect these to be the overloads for scalars since we covered arrays above -> wrap them back in Array
2295
- & (<T extends Constructable<any>>(
2448
+ & (<T extends Constructable>(
2449
+ entityType: T,
2450
+ columns: string[] // could be keyof in the future
2451
+ ) => Awaitable<SELECT_3<PluralInstanceType<T>>, PluralInstanceType<T>>)
2452
+ & (<T extends Constructable>(
2453
+ entityType: T,
2454
+ primaryKey: PK,
2455
+ columns: string[] // could be keyof in the future
2456
+ ) => Awaitable<SELECT_3<InstanceType<T>>, InstanceType<T>>)
2457
+ & (<T extends Constructable>(
2296
2458
  entityType: T,
2297
2459
  projection?: Projection<InstanceType<T>>
2298
- ) => Awaitable<SELECT_3<PluralType<T>>, PluralType<T>>)
2299
- & (<T extends Constructable<any>>(
2460
+ ) => Awaitable<SELECT_3<PluralInstanceType<T>>, PluralInstanceType<T>>)
2461
+ & (<T extends Constructable>(
2300
2462
  entityType: T,
2301
2463
  primaryKey: PK,
2302
2464
  projection?: Projection<InstanceType<T>>
2303
- ) => Awaitable<SELECT_3<PluralType<T>>, PluralType<T>>)
2465
+ ) => Awaitable<SELECT_3<InstanceType<T>>, InstanceType<T>>)
2304
2466
 
2305
2467
  type SELECT_one =
2306
- TaggedTemplateQueryPart<Awaitable<SELECT_3<unknown>, InstanceType<any>>>
2468
+ TaggedTemplateQueryPart<Awaitable<SELECT_3<_TODO_2, SELECT_one>, InstanceType<_TODO_2>>>
2307
2469
  &
2308
2470
  // calling with class
2309
- (<T extends ArrayConstructable<any>>
2310
- (entityType: T, projection?: Projection<QLExtensions<SingularType<T>>>)
2311
- => Awaitable<SELECT_3<SingularType<T>>, SingularType<T>>)
2471
+ (<T extends ArrayConstructable>
2472
+ (entityType: T, projection?: Projection<QLExtensions<SingularInstanceType<T>>>)
2473
+ => Awaitable<SELECT_3<SingularInstanceType<T>, SELECT_one>, SingularInstanceType<T>>)
2312
2474
  &
2313
- (<T extends ArrayConstructable<any>>
2314
- (entityType: T, primaryKey: PK, projection?: Projection<QLExtensions<SingularType<T>>>)
2315
- => Awaitable<SELECT_3<SingularType<T>>, SingularType<T>>)
2475
+ (<T extends ArrayConstructable>
2476
+ (entityType: T, primaryKey: PK, projection?: Projection<QLExtensions<SingularInstanceType<T>>>)
2477
+ => Awaitable<SELECT_3<SingularInstanceType<T>, SELECT_one>, SingularInstanceType<T>>)
2316
2478
 
2317
- & ((entity: Target, primaryKey?: PK, projection?: Projection<unknown>) => SELECT_3<any>)
2318
- & (<T> (entity: T[], projection?: Projection<T>) => Awaitable<SELECT_3<T>, T>)
2319
- & (<T> (entity: T[], primaryKey: PK, projection?: Projection<T>) => Awaitable<SELECT_3<T>, T>)
2320
- & (<T> (entity: { new(): T }, projection?: Projection<T>) => Awaitable<SELECT_3<T>, T>)
2321
- & (<T> (entity: { new(): T }, primaryKey: PK, projection?: Projection<T>) => Awaitable<SELECT_3<T>, T>)
2322
- & ((subject: ref) => SELECT_3<any>)
2479
+ & ((entity: EntityDescription, primaryKey?: PK, projection?: Projection<unknown>) => SELECT_3<_TODO_2, SELECT_one>)
2480
+ & (<T> (entity: T[], projection?: Projection<T>) => Awaitable<SELECT_3<T, SELECT_one>, T>)
2481
+ & (<T> (entity: T[], primaryKey: PK, projection?: Projection<T>) => Awaitable<SELECT_3<T, SELECT_one>, T>)
2482
+ & (<T> (entity: { new(): T }, projection?: Projection<T>) => Awaitable<SELECT_3<T, SELECT_one>, T>)
2483
+ & (<T> (entity: { new(): T }, primaryKey: PK, projection?: Projection<T>) => Awaitable<SELECT_3<T, SELECT_one>, T>)
2484
+ & ((subject: ref) => SELECT_3<_TODO_2>)
2323
2485
 
2324
2486
  /**
2325
2487
  * Constructs service providers from respective service definitions
@@ -2415,7 +2577,7 @@ export class Service extends QueryAPI {
2415
2577
  <T = any>(event: types.event, path: string, data?: object, headers?: object): Promise<T>,
2416
2578
  <T = any>(event: types.event, data?: object, headers?: object): Promise<T>,
2417
2579
  <T = any>(details: { event: types.event, data?: object, headers?: object }): Promise<T>,
2418
- <T = any>(details: { query: ConstructedQuery, data?: object, headers?: object }): Promise<T>,
2580
+ <T = any>(details: { query: ConstructedQuery<T>, data?: object, headers?: object }): Promise<T>,
2419
2581
  <T = any>(details: { method: types.eventName, path: string, data?: object, headers?: object }): Promise<T>,
2420
2582
  <T = any>(details: { event: types.eventName, entity: linked_2.Definition | string, data?: object, params?: object, headers?: object }): Promise<T>,
2421
2583
  }
@@ -2462,8 +2624,8 @@ export class Service extends QueryAPI {
2462
2624
  // Provider API
2463
2625
  prepend (fn: ServiceImpl): this
2464
2626
 
2465
- on<T extends ArrayConstructable>(eve: types.event, entity: T, handler: CRUDEventHandler.On<Unwrap<T>>): this
2466
- on<T extends Constructable>(eve: types.event, entity: T, handler: CRUDEventHandler.On<InstanceType<T>>): this
2627
+ on<T extends ArrayConstructable>(eve: types.event, entity: T | T[], handler: CRUDEventHandler.On<Unwrap<T>>): this
2628
+ on<T extends Constructable>(eve: types.event, entity: T | T[], handler: CRUDEventHandler.On<InstanceType<T>>): this
2467
2629
  on<F extends CdsFunction>(boundAction: F, service: string, handler: ActionEventHandler<F['__parameters'], void | Error | F['__returns']>): this
2468
2630
  on<F extends CdsFunction>(unboundAction: F, handler: ActionEventHandler<F['__parameters'], void | Error | F['__returns']>): this
2469
2631
  on (eve: types.event, entity: types.target, handler: OnEventHandler): this
@@ -2476,8 +2638,8 @@ export class Service extends QueryAPI {
2476
2638
  // onFailed (eve: types.Events, handler: types.EventHandler): this
2477
2639
  before<F extends CdsFunction>(boundAction: F, service: string, handler: CRUDEventHandler.Before<F['__parameters'], void | Error | F['__returns']>): this
2478
2640
  before<F extends CdsFunction>(unboundAction: F, handler: CRUDEventHandler.Before<F['__parameters'], void | Error | F['__returns']>): this
2479
- before<T extends ArrayConstructable>(eve: types.event, entity: T, handler: CRUDEventHandler.Before<Unwrap<T>>): this
2480
- before<T extends Constructable>(eve: types.event, entity: T, handler: CRUDEventHandler.Before<InstanceType<T>>): this
2641
+ before<T extends ArrayConstructable>(eve: types.event, entity: T | T[], handler: CRUDEventHandler.Before<Unwrap<T>>): this
2642
+ before<T extends Constructable>(eve: types.event, entity: T | T[], handler: CRUDEventHandler.Before<InstanceType<T>>): this
2481
2643
  before (eve: types.event, entity: types.target, handler: EventHandler): this
2482
2644
  before (eve: types.event, handler: EventHandler): this
2483
2645
 
@@ -2486,11 +2648,11 @@ export class Service extends QueryAPI {
2486
2648
  // (3) check if T is scalar -> use T directly
2487
2649
  // this streamlines that in _most_ cases, handlers will receive a single object.
2488
2650
  // _Except_ for after.read handlers (1), which will change its inflection based on T.
2489
- after<T extends ArrayConstructable>(event: 'READ', entity: T, handler: CRUDEventHandler.After<InstanceType<T>>): this
2490
- after<T extends ArrayConstructable>(event: 'each', entity: T, handler: CRUDEventHandler.After<Unwrap<T>>): this
2491
- after<T extends Constructable>(event: 'READ' | 'each', entity: T, handler: CRUDEventHandler.After<InstanceType<T>>): this
2492
- after<T extends ArrayConstructable>(eve: types.event, entity: T, handler: CRUDEventHandler.After<Unwrap<T>>): this
2493
- after<T extends Constructable>(eve: types.event, entity: T, handler: CRUDEventHandler.After<InstanceType<T>>): this
2651
+ after<T extends ArrayConstructable>(event: 'READ', entity: T | T[], handler: CRUDEventHandler.After<InstanceType<T>>): this
2652
+ after<T extends ArrayConstructable>(event: 'each', entity: T | T[], handler: CRUDEventHandler.After<Unwrap<T>>): this
2653
+ after<T extends Constructable>(event: 'READ' | 'each', entity: T | T[], handler: CRUDEventHandler.After<InstanceType<T>>): this
2654
+ after<T extends ArrayConstructable>(eve: types.event, entity: T | T[], handler: CRUDEventHandler.After<Unwrap<T>>): this
2655
+ after<T extends Constructable>(eve: types.event, entity: T | T[], handler: CRUDEventHandler.After<InstanceType<T>>): this
2494
2656
  after<F extends CdsFunction>(boundAction: F, service: string, handler: CRUDEventHandler.After<F['__parameters'], void | Error | F['__returns']>): this
2495
2657
  after<F extends CdsFunction>(unboundAction: F, handler: CRUDEventHandler.After<F['__parameters'], void | Error | F['__returns']>): this
2496
2658
  after (eve: types.event, entity: types.target, handler: ResultsHandler): this
@@ -2556,7 +2718,7 @@ export interface ServiceImpl {
2556
2718
  */
2557
2719
  export const services: cds_services;
2558
2720
 
2559
- type SingularType<T extends ArrayConstructable<T>> = InstanceType<T>[number]
2721
+ type SingularInstanceType<T extends ArrayConstructable> = InstanceType<T>[number]
2560
2722
 
2561
2723
  /** @private */
2562
2724
  export type source = UnionToIntersection<ref | SELECT_2> & { as?: name, join?: name, on?: xpr }
@@ -2593,11 +2755,11 @@ export type SpawnOptions = {
2593
2755
 
2594
2756
  export type SQL = string
2595
2757
 
2596
- type StaticSELECT<T> = typeof SELECT_3
2597
- & ((...columns: (T extends ArrayConstructable<any> ? keyof SingularType<T> : keyof T)[]) => SELECT_3<T>)
2598
- & ((...columns: string[]) => SELECT_3<T>)
2599
- & ((columns: string[]) => SELECT_3<T>)
2600
- & (TaggedTemplateQueryPart<SELECT_3<T>>)
2758
+ type StaticAny = any
2759
+
2760
+ type StaticSELECT<T> = { columns: SELECT_3<T>['columns'] }
2761
+ & typeof SELECT_3<T>
2762
+ & SELECT_3<T>['columns']
2601
2763
  & SELECT_from // as it is not directly quantified, ...
2602
2764
  & SELECT_one
2603
2765
 
@@ -2605,7 +2767,9 @@ export const stream: Service['stream'];
2605
2767
 
2606
2768
  const string: typeof string_;
2607
2769
 
2608
- class string_ extends scalar { }
2770
+ class string_ extends scalar {
2771
+ length?: number
2772
+ }
2609
2773
 
2610
2774
  class String_2 extends string { }
2611
2775
 
@@ -2635,7 +2799,7 @@ interface struct_2 extends type_2 {
2635
2799
  * The final result of each subquery will be the property itself:
2636
2800
  * `Book.title` == `Subqueryable<Book>.title()`
2637
2801
  */
2638
- type Subqueryable<T> = T extends Primitive ? unknown
2802
+ type Subqueryable<T> = T extends Primitive ? unknown
2639
2803
  // composition of many/ association to many
2640
2804
  : T extends readonly unknown[] ? {
2641
2805
 
@@ -2679,10 +2843,7 @@ type Subqueryable<T> = T extends Primitive ? unknown
2679
2843
 
2680
2844
  type TaggedTemplateQueryPart<T> = (strings: TemplateStringsArray, ...params: unknown[]) => T
2681
2845
 
2682
- /**
2683
- * Target for any QL operation
2684
- */
2685
- type Target = linked_2.classes.entity | Definition | string
2846
+ type TaggedTemplateRequest = (strings: TemplateStringsArray, ...params: unknown[]) => Promise<import('axios').AxiosResponse>
2686
2847
 
2687
2848
  class Test extends Axios {
2688
2849
 
@@ -2738,6 +2899,8 @@ export const test: {
2738
2899
  (command: string, ...args: string[]): Test,
2739
2900
 
2740
2901
  in (dirname: string): Test,
2902
+
2903
+ log: Test['log'],
2741
2904
  };
2742
2905
 
2743
2906
  class Time extends date { }
@@ -2750,6 +2913,9 @@ class TimeStamp extends DateTime { }
2750
2913
  */
2751
2914
  export type _TODO = any
2752
2915
 
2916
+ /** @internal */
2917
+ type _TODO_2 = any
2918
+
2753
2919
  export interface Transaction extends Service {
2754
2920
  commit(): Promise<void>
2755
2921
  rollback(): Promise<void>
@@ -2768,13 +2934,21 @@ export const tx: {
2768
2934
  };
2769
2935
 
2770
2936
  export interface type extends Omit<csn.type, 'items'> {
2771
- items: type
2937
+ items?: type
2938
+ key?: boolean
2939
+ notNull?: boolean
2940
+ virtual?: boolean
2772
2941
  }
2773
2942
 
2774
2943
  export class type<K extends kinds = 'type'> extends any_<K> { }
2775
2944
 
2776
2945
  interface type_2 extends any__2 {
2777
- type?: FQN
2946
+ type?: 'cds.Boolean' |
2947
+ 'cds.UUID' | 'cds.String' | 'cds.LargeString' | 'cds.Binary' | 'cds.LargeBinary' | 'cds.Vector' |
2948
+ 'cds.Integer' | 'cds.UInt8' | 'cds.Int16' | 'cds.Int32' | 'cds.Int64' | 'cds.Float' | 'cds.Double' | 'cds.Decimal' |
2949
+ 'cds.Date' | 'cds.Time' | 'cds.DateTime' | 'cds.Timestamp' |
2950
+ 'cds.Association' | 'cds.Composition' |
2951
+ FQN & Record<never,never> // allow any other CDS type as well (e.g. 'User')
2778
2952
  items?: type_2
2779
2953
  }
2780
2954
 
@@ -2799,11 +2973,13 @@ type UnionsToIntersections<U> = Array<UnionToIntersection<Scalarise<U>>>
2799
2973
  type UnionToIntersection<U> = Partial<(U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never>
2800
2974
 
2801
2975
  type Unwrap<T> = T extends ArrayConstructable
2802
- ? SingularType<T>
2976
+ ? SingularInstanceType<T>
2803
2977
  : T extends Array<infer U>
2804
2978
  ? U
2805
2979
  : T
2806
2980
 
2981
+ type UnwrappedInstanceType<T> = Unwrap<T> extends Constructable ? InstanceType<Unwrap<T>> : Unwrap<T>
2982
+
2807
2983
  export const update: Service['update'];
2808
2984
 
2809
2985
  type UPDATE_2 = { UPDATE: {
@@ -2813,18 +2989,22 @@ type UPDATE_2 = { UPDATE: {
2813
2989
  }, }
2814
2990
  export { UPDATE_2 as UPDATE }
2815
2991
 
2816
- class UPDATE_3<T> extends ConstructedQuery {
2992
+ interface UPDATE_3<T> extends Where<T>, And, ByKey {}
2993
+
2994
+ class UPDATE_3<T> extends ConstructedQuery<T> {
2995
+ private constructor();
2817
2996
 
2818
2997
  // cds-typer plural
2819
- static entity<T extends ArrayConstructable<any>> (entity: T, primaryKey?: PK): UPDATE_3<SingularType<T>>
2998
+ // FIXME: this returned UPDATE<SingularInstanceType<T>> before. should UPDATE<Books>.entity(...) return Book or Books?
2999
+ static entity<T extends ArrayConstructable> (entity: T, primaryKey?: PK): UPDATE_3<InstanceType<T>>
2820
3000
 
2821
- static entity (entity: Target, primaryKey?: PK): UPDATE_3<any>
3001
+ static entity (entity: EntityDescription, primaryKey?: PK): UPDATE_3<StaticAny>
2822
3002
 
2823
- static entity<T> (entity: Constructable<T>, primaryKey?: PK): UPDATE_3<T>
3003
+ static entity<T extends Constructable> (entity: T, primaryKey?: PK): UPDATE_3<T>
2824
3004
 
3005
+ // currently no easy way to restrict T from being a primitive type
2825
3006
  static entity<T> (entity: T, primaryKey?: PK): UPDATE_3<T>
2826
3007
 
2827
- byKey (primaryKey?: PK): this
2828
3008
  // with (block: (e:T)=>void) : this
2829
3009
  // set (block: (e:T)=>void) : this
2830
3010
  set: TaggedTemplateQueryPart<this>
@@ -2833,13 +3013,6 @@ class UPDATE_3<T> extends ConstructedQuery {
2833
3013
  with: TaggedTemplateQueryPart<this>
2834
3014
  & ((data: object) => this)
2835
3015
 
2836
- where (predicate: object): this
2837
-
2838
- where (...expr: any[]): this
2839
-
2840
- and (predicate: object): this
2841
-
2842
- and (...expr: any[]): this
2843
3016
  UPDATE: CQN.UPDATE['UPDATE']
2844
3017
 
2845
3018
  }
@@ -2853,29 +3026,19 @@ type UPSERT_2 = { UPSERT: {
2853
3026
  }, }
2854
3027
  export { UPSERT_2 as UPSERT }
2855
3028
 
2856
- class UPSERT_3<T> extends ConstructedQuery {
2857
-
2858
- static into: (<T extends ArrayConstructable<any>> (entity: T, entries?: object | object[]) => UPSERT_3<SingularType<T>>)
2859
- & (TaggedTemplateQueryPart<UPSERT_3<unknown>>)
2860
- & ((entity: Target, entries?: object | object[]) => UPSERT_3<any>)
2861
- & (<T> (entity: Constructable<T>, entries?: object | object[]) => UPSERT_3<T>)
2862
- & (<T> (entity: T, entries?: T | object | object[]) => UPSERT_3<T>)
2863
-
2864
- into: (<T extends ArrayConstructable> (entity: T) => this)
2865
- & TaggedTemplateQueryPart<this>
2866
- & ((entity: Target) => this)
3029
+ interface UPSERT_3<T> extends Columns<T>, InUpsert<T> {}
2867
3030
 
2868
- data (block: (e: T) => void): this
3031
+ class UPSERT_3<T> extends ConstructedQuery<T> {
3032
+ private constructor();
2869
3033
 
2870
- entries (...entries: object[]): this
3034
+ static into: (<T extends ArrayConstructable> (entity: T, entries?: Entries) => UPSERT_3<SingularInstanceType<T>>)
3035
+ & (TaggedTemplateQueryPart<UPSERT_3<StaticAny>>)
3036
+ & ((entity: EntityDescription, entries?: Entries) => UPSERT_3<StaticAny>)
3037
+ & (<T> (entity: Constructable<T>, entries?: Entries) => UPSERT_3<T>)
3038
+ // currently no easy way to restrict T to non-primitives
3039
+ & (<T> (entity: T, entries?: T | Entries) => UPSERT_3<T>)
2871
3040
 
2872
- columns (...col: (T extends ArrayConstructable<any> ? keyof SingularType<T> : keyof T)[]): this
2873
3041
 
2874
- columns (...col: string[]): this
2875
-
2876
- values (...val: any[]): this
2877
-
2878
- rows (...row: any[]): this
2879
3042
  UPSERT: CQN.UPSERT['UPSERT']
2880
3043
 
2881
3044
  }
@@ -2910,7 +3073,7 @@ export class User {
2910
3073
  }
2911
3074
 
2912
3075
  /**
2913
- * Provides a set of utility functionss
3076
+ * Provides a set of utility functions
2914
3077
  */
2915
3078
  export const utils: {
2916
3079
 
@@ -2996,6 +3159,59 @@ export const utils: {
2996
3159
  * @see https://cap.cloud.sap/docs/node.js/cds-utils#async-rm-path
2997
3160
  */
2998
3161
  rm: (...path: string[]) => Promise<ReturnType<typeof import('node:fs').promises.rm>>,
3162
+
3163
+ /**
3164
+ * @since 8.3.0
3165
+ * @see https://cap.cloud.sap/docs/node.js/cds-utils#colors
3166
+ */
3167
+ colors: {
3168
+ enabled: boolean,
3169
+ RESET: '\x1b[0m',
3170
+ BOLD: '\x1b[1m' | '',
3171
+ BRIGHT: '\x1b[1m' | '',
3172
+ DIMMED: '\x1b[2m' | '',
3173
+ ITALIC: '\x1b[3m' | '',
3174
+ UNDER: '\x1b[4m' | '',
3175
+ BLINK: '\x1b[5m' | '',
3176
+ FLASH: '\x1b[6m' | '',
3177
+ INVERT: '\x1b[7m' | '',
3178
+ BLACK: '\x1b[30m' | '',
3179
+ RED: '\x1b[31m' | '',
3180
+ GREEN: '\x1b[32m' | '',
3181
+ YELLOW: '\x1b[33m' | '',
3182
+ BLUE: '\x1b[34m' | '',
3183
+ PINK: '\x1b[35m' | '',
3184
+ CYAN: '\x1b[36m' | '',
3185
+ LIGHT_GRAY: '\x1b[37m' | '',
3186
+ DEFAULT: '\x1b[39m' | '',
3187
+ GRAY: '\x1b[90m' | '',
3188
+ LIGHT_RED: '\x1b[91m' | '',
3189
+ LIGHT_GREEN: '\x1b[92m' | '',
3190
+ LIGHT_YELLOW: '\x1b[93m' | '',
3191
+ LIGHT_BLUE: '\x1b[94m' | '',
3192
+ LIGHT_PINK: '\x1b[95m' | '',
3193
+ LIGHT_CYAN: '\x1b[96m' | '',
3194
+ WHITE: '\x1b[97m' | '',
3195
+ bg: {
3196
+ BLACK: '\x1b[40m' | '',
3197
+ RED: '\x1b[41m' | '',
3198
+ GREEN: '\x1b[42m' | '',
3199
+ YELLOW: '\x1b[43m' | '',
3200
+ BLUE: '\x1b[44m' | '',
3201
+ PINK: '\x1b[45m' | '',
3202
+ CYAN: '\x1b[46m' | '',
3203
+ WHITE: '\x1b[47m' | '',
3204
+ DEFAULT: '\x1b[49m' | '',
3205
+ LIGHT_GRAY: '\x1b[100m' | '',
3206
+ LIGHT_RED: '\x1b[101m' | '',
3207
+ LIGHT_GREEN: '\x1b[102m' | '',
3208
+ LIGHT_YELLOW: '\x1b[103m' | '',
3209
+ LIGHT_BLUE: '\x1b[104m' | '',
3210
+ LIGHT_PINK: '\x1b[105m' | '',
3211
+ LIGHT_CYAN: '\x1b[106m' | '',
3212
+ LIGHT_WHITE: '\x1b[107m' | '',
3213
+ },
3214
+ },
2999
3215
  };
3000
3216
 
3001
3217
  class UUID extends string { }
@@ -3009,6 +3225,10 @@ export const version: string;
3009
3225
 
3010
3226
  type Visitor = (def: any_, name: string, parent: any_, defs: Definitions) => void
3011
3227
 
3228
+ interface Where<T> {
3229
+ where: HavingWhere<this, T>
3230
+ }
3231
+
3012
3232
  interface WithElements {
3013
3233
  elements: Definitions<type>
3014
3234
  }
@@ -3019,6 +3239,8 @@ interface WithElements {
3019
3239
  */
3020
3240
  type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never }
3021
3241
 
3242
+ type WS = '' | ' '
3243
+
3022
3244
  export type XML = string
3023
3245
 
3024
3246
  /** @internal */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js/cds-types",
3
- "version": "0.6.5",
3
+ "version": "0.8.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/",
@@ -29,7 +29,8 @@
29
29
  "lint:fix": "npx eslint . --fix",
30
30
  "setup": "npm i && npm i file:. --no-save --force",
31
31
  "prerelease:ci-fix": "node .github/prerelease-fix.js",
32
- "postinstall": "node ./scripts/postinstall.js"
32
+ "postinstall": "node ./scripts/postinstall.js",
33
+ "dependencies": "node ./scripts/postinstall.js"
33
34
  },
34
35
  "peerDependencies": {
35
36
  "@sap/cds": "^8.0.0"